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
Roberto Scaramuzzi
Robin Green
Robin Power
Robin Verduijn
Rob Oxspring
Rob van Oostrum


+ 4
- 0
contributors.xml View File

@@ -1201,6 +1201,10 @@
<first>Robin</first>
<last>Green</last>
</name>
<name>
<first>Robin</first>
<last>Power</last>
</name>
<name>
<first>Robin</first>
<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()
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) {
// not a ZIP64 archive
skipBytes(ZIP64_EOCDL_LENGTH - WORD);
positionAtCentralDirectory32();
} else {
positionAtCentralDirectory64();
@@ -686,7 +688,8 @@ public class ZipFile {
*/
private void positionAtCentralDirectory64()
throws IOException {
skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET);
skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET
- WORD /* signature has already been read */);
archive.readFully(DWORD_BUF);
archive.seek(ZipEightByteInteger.getLongValue(DWORD_BUF));
archive.readFully(WORD_BUF);
@@ -706,15 +709,23 @@ public class ZipFile {
* record.
*/
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 {
boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE,
ZipOutputStream.EOCD_SIG);
if (!found) {
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