Browse Source

improve performance when reading non zip64 zip files, merge from commons compress, based on patch by Robin Power

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1439044 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 12 years ago
parent
commit
1a4946cfd6
3 changed files with 24 additions and 8 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      contributors.xml
  3. +19
    -8
      src/main/org/apache/tools/zip/ZipFile.java

+ 1
- 0
CONTRIBUTORS View File

@@ -298,6 +298,7 @@ Robert Streich
Robert Watkins Robert Watkins
Roberto Scaramuzzi Roberto Scaramuzzi
Robin Green Robin Green
Robin Power
Robin Verduijn Robin Verduijn
Rob Oxspring Rob Oxspring
Rob van Oostrum Rob van Oostrum


+ 4
- 0
contributors.xml View File

@@ -1201,6 +1201,10 @@
<first>Robin</first> <first>Robin</first>
<last>Green</last> <last>Green</last>
</name> </name>
<name>
<first>Robin</first>
<last>Power</last>
</name>
<name> <name>
<first>Robin</first> <first>Robin</first>
<last>Verduijn</last> <last>Verduijn</last>


+ 19
- 8
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -666,12 +666,14 @@ public class ZipFile {
*/ */
private void positionAtCentralDirectory() private void positionAtCentralDirectory()
throws IOException { throws IOException {
boolean found = tryToLocateSignature(MIN_EOCD_SIZE + ZIP64_EOCDL_LENGTH,
MAX_EOCD_SIZE + ZIP64_EOCDL_LENGTH,
ZipOutputStream
.ZIP64_EOCD_LOC_SIG);
positionAtEndOfCentralDirectoryRecord();
archive.seek(archive.getFilePointer() - ZIP64_EOCDL_LENGTH);
archive.readFully(WORD_BUF);
boolean found = Arrays.equals(ZipOutputStream.ZIP64_EOCD_LOC_SIG,
WORD_BUF);
if (!found) { if (!found) {
// not a ZIP64 archive // not a ZIP64 archive
skipBytes(ZIP64_EOCDL_LENGTH - WORD);
positionAtCentralDirectory32(); positionAtCentralDirectory32();
} else { } else {
positionAtCentralDirectory64(); positionAtCentralDirectory64();
@@ -686,7 +688,8 @@ public class ZipFile {
*/ */
private void positionAtCentralDirectory64() private void positionAtCentralDirectory64()
throws IOException { throws IOException {
skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET);
skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET
- WORD /* signature has already been read */);
archive.readFully(DWORD_BUF); archive.readFully(DWORD_BUF);
archive.seek(ZipEightByteInteger.getLongValue(DWORD_BUF)); archive.seek(ZipEightByteInteger.getLongValue(DWORD_BUF));
archive.readFully(WORD_BUF); archive.readFully(WORD_BUF);
@@ -706,15 +709,23 @@ public class ZipFile {
* record. * record.
*/ */
private void positionAtCentralDirectory32() private void positionAtCentralDirectory32()
throws IOException {
skipBytes(CFD_LOCATOR_OFFSET);
archive.readFully(WORD_BUF);
archive.seek(ZipLong.getValue(WORD_BUF));
}

/**
* Searches for the and positions the stream at the start of the
* &quot;End of central dir record&quot;.
*/
private void positionAtEndOfCentralDirectoryRecord()
throws IOException { throws IOException {
boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE, boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE,
ZipOutputStream.EOCD_SIG); ZipOutputStream.EOCD_SIG);
if (!found) { if (!found) {
throw new ZipException("archive is not a ZIP archive"); throw new ZipException("archive is not a ZIP archive");
} }
skipBytes(CFD_LOCATOR_OFFSET);
archive.readFully(WORD_BUF);
archive.seek(ZipLong.getValue(WORD_BUF));
} }


/** /**


Loading…
Cancel
Save