Author: bodewig
Date: Thu Aug 11 14:22:37 2011
New Revision: 1156627
URL: http://svn.apache.org/viewvc?rev=1156627&view=rev
Log:
whitespace - and rename of local variables in ZAIS.bufferContainsSignature
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1156627&r1=1156626&r2=1156627&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Thu Aug 11 14:22:37 2011
@@ -329,38 +329,40 @@ public class ZipArchiveInputStream exten
*/
private int readStored(byte[] buffer, int start, int length)
throws IOException {
- if (current.hasDataDescriptor) {
- if (lastStoredEntry == null) {
- readStoredEntry();
- }
- return lastStoredEntry.read(buffer, start, length);
- }
- long csize = current.entry.getSize();
- if (current.bytesRead >= csize) {
- return -1;
- }
- if (buf.offsetInBuffer >= buf.lengthOfLastRead) {
- buf.offsetInBuffer = 0;
- if ((buf.lengthOfLastRead = in.read(buf.buf)) == -1) {
- return -1;
- }
- count(buf.lengthOfLastRead);
- current.bytesReadFromStream += buf.lengthOfLastRead;
- }
- int toRead = length > buf.lengthOfLastRead
- ? buf.lengthOfLastRead - buf.offsetInBuffer
- : length;
- if ((csize - current.bytesRead) < toRead) {
- // if it is smaller than toRead then it fits into an int
- toRead = (int) (csize - current.bytesRead);
- }
- System.arraycopy(buf.buf, buf.offsetInBuffer, buffer, start,
- toRead);
- buf.offsetInBuffer += toRead;
- current.bytesRead += toRead;
- crc.update(buffer, start, toRead);
- return toRead;
+ if (current.hasDataDescriptor) {
+ if (lastStoredEntry == null) {
+ readStoredEntry();
+ }
+ return lastStoredEntry.read(buffer, start, length);
+ }
+
+ long csize = current.entry.getSize();
+ if (current.bytesRead >= csize) {
+ return -1;
+ }
+
+ if (buf.offsetInBuffer >= buf.lengthOfLastRead) {
+ buf.offsetInBuffer = 0;
+ if ((buf.lengthOfLastRead = in.read(buf.buf)) == -1) {
+ return -1;
+ }
+ count(buf.lengthOfLastRead);
+ current.bytesReadFromStream += buf.lengthOfLastRead;
+ }
+
+ int toRead = length > buf.lengthOfLastRead
+ ? buf.lengthOfLastRead - buf.offsetInBuffer
+ : length;
+ if ((csize - current.bytesRead) < toRead) {
+ // if it is smaller than toRead then it fits into an int
+ toRead = (int) (csize - current.bytesRead);
+ }
+ System.arraycopy(buf.buf, buf.offsetInBuffer, buffer, start, toRead);
+ buf.offsetInBuffer += toRead;
+ current.bytesRead += toRead;
+ crc.update(buffer, start, toRead);
+ return toRead;
}
/**
@@ -368,27 +370,27 @@ public class ZipArchiveInputStream exten
*/
private int readDeflated(byte[] buffer, int start, int length)
throws IOException {
- if (inf.needsInput()) {
- fill();
- if (buf.lengthOfLastRead > 0) {
- current.bytesReadFromStream += buf.lengthOfLastRead;
- }
- }
- int read = 0;
- try {
- read = inf.inflate(buffer, start, length);
- } catch (DataFormatException e) {
- throw new ZipException(e.getMessage());
- }
- if (read == 0) {
- if (inf.finished()) {
- return -1;
- } else if (buf.lengthOfLastRead == -1) {
- throw new IOException("Truncated ZIP file");
- }
+ if (inf.needsInput()) {
+ fill();
+ if (buf.lengthOfLastRead > 0) {
+ current.bytesReadFromStream += buf.lengthOfLastRead;
+ }
+ }
+ int read = 0;
+ try {
+ read = inf.inflate(buffer, start, length);
+ } catch (DataFormatException e) {
+ throw new ZipException(e.getMessage());
+ }
+ if (read == 0) {
+ if (inf.finished()) {
+ return -1;
+ } else if (buf.lengthOfLastRead == -1) {
+ throw new IOException("Truncated ZIP file");
}
- crc.update(buffer, start, read);
- return read;
+ }
+ crc.update(buffer, start, read);
+ return read;
}
@Override
@@ -490,7 +492,7 @@ public class ZipArchiveInputStream exten
// Ensure all entry bytes are read
if (current.bytesReadFromStream <= current.entry.getCompressedSize()
- && !current.hasDataDescriptor) {
+ && !current.hasDataDescriptor) {
drainCurrentEntryData();
} else {
skip(Long.MAX_VALUE);
@@ -525,19 +527,19 @@ public class ZipArchiveInputStream exten
* that hasn't been read, yet.
*/
private void drainCurrentEntryData() throws IOException {
- long remaining = current.entry.getCompressedSize()
- - current.bytesReadFromStream;
- while (remaining > 0) {
- long n = in.read(buf.buf, 0, (int) Math.min(buf.buf.length,
- remaining));
- if (n < 0) {
- throw new EOFException(
- "Truncated ZIP entry: " + current.entry.getName());
- } else {
- count(n);
- remaining -= n;
- }
+ long remaining = current.entry.getCompressedSize()
+ - current.bytesReadFromStream;
+ while (remaining > 0) {
+ long n = in.read(buf.buf, 0, (int) Math.min(buf.buf.length,
+ remaining));
+ if (n < 0) {
+ throw new EOFException(
+ "Truncated ZIP entry: " +
current.entry.getName());
+ } else {
+ count(n);
+ remaining -= n;
}
+ }
}
/**
@@ -698,34 +700,36 @@ public class ZipArchiveInputStream exten
* and positions the stream right after the data descriptor.</p>
*/
private boolean bufferContainsSignature(ByteArrayOutputStream bos,
- int off, int r, int ddLen)
+ int offset, int lastRead,
+ int expectedDDLen)
throws IOException {
boolean done = false;
- int readTooMuch = 0;
- for (int i = 0; !done && i < r - 4; i++) {
- if (buf.buf[i] == LFH[0] && buf.buf[i + 1] == LFH[1]) {
- if ((buf.buf[i + 2] == LFH[2] && buf.buf[i + 3] == LFH[3])
- || (buf.buf[i] == CFH[2] && buf.buf[i + 3] == CFH[3]))
{
- // found a LFH or CFH:
- readTooMuch = off + r - i - ddLen;
- done = true;
- }
- else if (buf.buf[i + 2] == DD[2] && buf.buf[i + 3] ==
DD[3]) {
- // found DD:
- readTooMuch = off + r - i;
- done = true;
- }
- if (done) {
- // * push back bytes read in excess as well as the data
- // descriptor
- // * copy the remaining bytes to cache
- // * read data descriptor
- pushback(buf.buf, off + r - readTooMuch, readTooMuch);
- bos.write(buf.buf, 0, i);
- readDataDescriptor();
- }
+ int readTooMuch = 0;
+ for (int i = 0; !done && i < lastRead - 4; i++) {
+ if (buf.buf[i] == LFH[0] && buf.buf[i + 1] == LFH[1]) {
+ if ((buf.buf[i + 2] == LFH[2] && buf.buf[i + 3] == LFH[3])
+ || (buf.buf[i] == CFH[2] && buf.buf[i + 3] == CFH[3])) {
+ // found a LFH or CFH:
+ readTooMuch = offset + lastRead - i - expectedDDLen;
+ done = true;
+ }
+ else if (buf.buf[i + 2] == DD[2] && buf.buf[i + 3] == DD[3]) {
+ // found DD:
+ readTooMuch = offset + lastRead - i;
+ done = true;
+ }
+ if (done) {
+ // * push back bytes read in excess as well as the data
+ // descriptor
+ // * copy the remaining bytes to cache
+ // * read data descriptor
+ pushback(buf.buf, offset + lastRead - readTooMuch,
+ readTooMuch);
+ bos.write(buf.buf, 0, i);
+ readDataDescriptor();
}
}
+ }
return done;
}
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1156627&r1=1156626&r2=1156627&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Thu Aug 11 14:22:37 2011
@@ -536,47 +536,47 @@ public class ZipArchiveOutputStream exte
*/
private void rewriteSizesAndCrc(boolean actuallyNeedsZip64)
throws IOException {
- long save = raf.getFilePointer();
+ long save = raf.getFilePointer();
- raf.seek(entry.localDataStart);
- writeOut(ZipLong.getBytes(entry.entry.getCrc()));
- if (!hasZip64Extra(entry.entry) || !actuallyNeedsZip64) {
- writeOut(ZipLong.getBytes(entry.entry.getCompressedSize()));
- writeOut(ZipLong.getBytes(entry.entry.getSize()));
- } else {
- writeOut(ZipLong.ZIP64_MAGIC.getBytes());
- writeOut(ZipLong.ZIP64_MAGIC.getBytes());
- }
+ raf.seek(entry.localDataStart);
+ writeOut(ZipLong.getBytes(entry.entry.getCrc()));
+ if (!hasZip64Extra(entry.entry) || !actuallyNeedsZip64) {
+ writeOut(ZipLong.getBytes(entry.entry.getCompressedSize()));
+ writeOut(ZipLong.getBytes(entry.entry.getSize()));
+ } else {
+ writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+ writeOut(ZipLong.ZIP64_MAGIC.getBytes());
+ }
- if (hasZip64Extra(entry.entry)) {
- // seek to ZIP64 extra, skip header and size information
- raf.seek(entry.localDataStart + 3 * WORD + 2 * SHORT
- + getName(entry.entry).limit() + 2 * SHORT);
- // inside the ZIP64 extra uncompressed size comes
- // first, unlike the LFH, CD or data descriptor
- writeOut(ZipEightByteInteger.getBytes(entry.entry.getSize()));
-
writeOut(ZipEightByteInteger.getBytes(entry.entry.getCompressedSize()));
-
- if (!actuallyNeedsZip64) {
- // do some cleanup:
- // * rewrite version needed to extract
- raf.seek(entry.localDataStart - 5 * SHORT);
- writeOut(ZipShort.getBytes(INITIAL_VERSION));
-
- // * remove ZIP64 extra so it doesn't get written
- // to the central directory
-
entry.entry.removeExtraField(Zip64ExtendedInformationExtraField
- .HEADER_ID);
- entry.entry.setExtra();
-
- // * reset hasUsedZip64 if it has been set because
- // of this entry
- if (entry.causedUseOfZip64) {
- hasUsedZip64 = false;
- }
+ if (hasZip64Extra(entry.entry)) {
+ // seek to ZIP64 extra, skip header and size information
+ raf.seek(entry.localDataStart + 3 * WORD + 2 * SHORT
+ + getName(entry.entry).limit() + 2 * SHORT);
+ // inside the ZIP64 extra uncompressed size comes
+ // first, unlike the LFH, CD or data descriptor
+ writeOut(ZipEightByteInteger.getBytes(entry.entry.getSize()));
+
writeOut(ZipEightByteInteger.getBytes(entry.entry.getCompressedSize()));
+
+ if (!actuallyNeedsZip64) {
+ // do some cleanup:
+ // * rewrite version needed to extract
+ raf.seek(entry.localDataStart - 5 * SHORT);
+ writeOut(ZipShort.getBytes(INITIAL_VERSION));
+
+ // * remove ZIP64 extra so it doesn't get written
+ // to the central directory
+ entry.entry.removeExtraField(Zip64ExtendedInformationExtraField
+ .HEADER_ID);
+ entry.entry.setExtra();
+
+ // * reset hasUsedZip64 if it has been set because
+ // of this entry
+ if (entry.causedUseOfZip64) {
+ hasUsedZip64 = false;
}
}
- raf.seek(save);
+ }
+ raf.seek(save);
}
/**
@@ -616,8 +616,8 @@ public class ZipArchiveOutputStream exte
// actually, we already know the sizes
size = new ZipEightByteInteger(entry.entry.getSize());
}
- z64.setSize(size);
- z64.setCompressedSize(size);
+ z64.setSize(size);
+ z64.setCompressedSize(size);
entry.entry.setExtra();
}
@@ -771,25 +771,25 @@ public class ZipArchiveOutputStream exte
*/
private void writeDeflated(byte[]b, int offset, int length)
throws IOException {
- if (length > 0 && !def.finished()) {
- entry.bytesRead += length;
- if (length <= DEFLATER_BLOCK_SIZE) {
- def.setInput(b, offset, length);
+ if (length > 0 && !def.finished()) {
+ entry.bytesRead += length;
+ if (length <= DEFLATER_BLOCK_SIZE) {
+ def.setInput(b, offset, length);
+ deflateUntilInputIsNeeded();
+ } else {
+ final int fullblocks = length / DEFLATER_BLOCK_SIZE;
+ for (int i = 0; i < fullblocks; i++) {
+ def.setInput(b, offset + i * DEFLATER_BLOCK_SIZE,
+ DEFLATER_BLOCK_SIZE);
+ deflateUntilInputIsNeeded();
+ }
+ final int done = fullblocks * DEFLATER_BLOCK_SIZE;
+ if (done < length) {
+ def.setInput(b, offset + done, length - done);
deflateUntilInputIsNeeded();
- } else {
- final int fullblocks = length / DEFLATER_BLOCK_SIZE;
- for (int i = 0; i < fullblocks; i++) {
- def.setInput(b, offset + i * DEFLATER_BLOCK_SIZE,
- DEFLATER_BLOCK_SIZE);
- deflateUntilInputIsNeeded();
- }
- final int done = fullblocks * DEFLATER_BLOCK_SIZE;
- if (done < length) {
- def.setInput(b, offset + done, length - done);
- deflateUntilInputIsNeeded();
- }
}
}
+ }
}
/**
@@ -955,29 +955,29 @@ public class ZipArchiveOutputStream exte
private void addUnicodeExtraFields(ZipArchiveEntry ze, boolean encodable,
ByteBuffer name)
throws IOException {
+ if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
+ || !encodable) {
+ ze.addExtraField(new UnicodePathExtraField(ze.getName(),
+ name.array(),
+ name.arrayOffset(),
+ name.limit()));
+ }
+
+ String comm = ze.getComment();
+ if (comm != null && !"".equals(comm)) {
+
+ boolean commentEncodable = zipEncoding.canEncode(comm);
+
if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
- || !encodable) {
- ze.addExtraField(new UnicodePathExtraField(ze.getName(),
- name.array(),
- name.arrayOffset(),
- name.limit()));
- }
-
- String comm = ze.getComment();
- if (comm != null && !"".equals(comm)) {
-
- boolean commentEncodable = zipEncoding.canEncode(comm);
-
- if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
- || !commentEncodable) {
- ByteBuffer commentB = getEntryEncoding(ze).encode(comm);
- ze.addExtraField(new UnicodeCommentExtraField(comm,
-
commentB.array(),
-
commentB.arrayOffset(),
-
commentB.limit())
- );
- }
+ || !commentEncodable) {
+ ByteBuffer commentB = getEntryEncoding(ze).encode(comm);
+ ze.addExtraField(new UnicodeCommentExtraField(comm,
+ commentB.array(),
+
commentB.arrayOffset(),
+ commentB.limit())
+ );
}
+ }
}
/**
@@ -1334,7 +1334,7 @@ public class ZipArchiveOutputStream exte
*/
@Override
public ArchiveEntry createArchiveEntry(File inputFile, String entryName)
- throws IOException {
+ throws IOException {
if (finished) {
throw new IOException("Stream has already been finished");
}
@@ -1359,10 +1359,10 @@ public class ZipArchiveOutputStream exte
.HEADER_ID);
if (z64 == null) {
/*
- System.err.println("Adding z64 for " + ze.getName()
- + ", method: " + ze.getMethod()
- + " (" + (ze.getMethod() == STORED) + ")"
- + ", raf: " + (raf != null));
+ System.err.println("Adding z64 for " + ze.getName()
+ + ", method: " + ze.getMethod()
+ + " (" + (ze.getMethod() == STORED) + ")"
+ + ", raf: " + (raf != null));
*/
z64 = new Zip64ExtendedInformationExtraField();
}
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1156627&r1=1156626&r2=1156627&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Thu Aug 11 14:22:37 2011
@@ -51,9 +51,10 @@ import static org.apache.commons.compres
* <p>It doesn't extend <code>java.util.zip.ZipFile</code> as it would
* have to reimplement all methods anyway. Like
* <code>java.util.ZipFile</code>, it uses RandomAccessFile under the
- * covers and supports compressed and uncompressed entries. It also
- * transparently supports Zip64 extensions and thus individual entries
- * and archives larger than 4 GB or with more than 65536 entries.</p>
+ * covers and supports compressed and uncompressed entries. As of
+ * Apache Commons Compress it also transparently supports Zip64
+ * extensions and thus individual entries and archives larger than 4
+ * GB or with more than 65536 entries.</p>
*
* <p>The method signatures mimic the ones of
* <code>java.util.zip.ZipFile</code>, with a couple of exceptions:
@@ -427,86 +428,87 @@ public class ZipFile {
* added to this map.
*/
private void
- readCentralDirectoryEntry(Map<ZipArchiveEntry, NameAndComment>
noUTF8Flag) throws IOException {
+ readCentralDirectoryEntry(Map<ZipArchiveEntry, NameAndComment>
noUTF8Flag)
+ throws IOException {
byte[] cfh = new byte[CFH_LEN];
- archive.readFully(cfh);
- int off = 0;
- ZipArchiveEntry ze = new ZipArchiveEntry();
+ archive.readFully(cfh);
+ int off = 0;
+ ZipArchiveEntry ze = new ZipArchiveEntry();
- int versionMadeBy = ZipShort.getValue(cfh, off);
- off += SHORT;
- ze.setPlatform((versionMadeBy >> BYTE_SHIFT) & NIBLET_MASK);
+ int versionMadeBy = ZipShort.getValue(cfh, off);
+ off += SHORT;
+ ze.setPlatform((versionMadeBy >> BYTE_SHIFT) & NIBLET_MASK);
- off += SHORT; // skip version info
+ off += SHORT; // skip version info
- final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(cfh, off);
- final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames();
- final ZipEncoding entryEncoding =
- hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING :
zipEncoding;
- ze.setGeneralPurposeBit(gpFlag);
+ final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(cfh, off);
+ final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames();
+ final ZipEncoding entryEncoding =
+ hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
+ ze.setGeneralPurposeBit(gpFlag);
- off += SHORT;
+ off += SHORT;
- ze.setMethod(ZipShort.getValue(cfh, off));
- off += SHORT;
+ ze.setMethod(ZipShort.getValue(cfh, off));
+ off += SHORT;
- long time = ZipUtil.dosToJavaTime(ZipLong.getValue(cfh, off));
- ze.setTime(time);
- off += WORD;
+ long time = ZipUtil.dosToJavaTime(ZipLong.getValue(cfh, off));
+ ze.setTime(time);
+ off += WORD;
- ze.setCrc(ZipLong.getValue(cfh, off));
- off += WORD;
+ ze.setCrc(ZipLong.getValue(cfh, off));
+ off += WORD;
- ze.setCompressedSize(ZipLong.getValue(cfh, off));
- off += WORD;
+ ze.setCompressedSize(ZipLong.getValue(cfh, off));
+ off += WORD;
- ze.setSize(ZipLong.getValue(cfh, off));
- off += WORD;
+ ze.setSize(ZipLong.getValue(cfh, off));
+ off += WORD;
- int fileNameLen = ZipShort.getValue(cfh, off);
- off += SHORT;
+ int fileNameLen = ZipShort.getValue(cfh, off);
+ off += SHORT;
- int extraLen = ZipShort.getValue(cfh, off);
- off += SHORT;
+ int extraLen = ZipShort.getValue(cfh, off);
+ off += SHORT;
- int commentLen = ZipShort.getValue(cfh, off);
- off += SHORT;
+ int commentLen = ZipShort.getValue(cfh, off);
+ off += SHORT;
- int diskStart = ZipShort.getValue(cfh, off);
- off += SHORT;
+ int diskStart = ZipShort.getValue(cfh, off);
+ off += SHORT;
- ze.setInternalAttributes(ZipShort.getValue(cfh, off));
- off += SHORT;
+ ze.setInternalAttributes(ZipShort.getValue(cfh, off));
+ off += SHORT;
- ze.setExternalAttributes(ZipLong.getValue(cfh, off));
- off += WORD;
+ ze.setExternalAttributes(ZipLong.getValue(cfh, off));
+ off += WORD;
- byte[] fileName = new byte[fileNameLen];
- archive.readFully(fileName);
- ze.setName(entryEncoding.decode(fileName), fileName);
+ byte[] fileName = new byte[fileNameLen];
+ archive.readFully(fileName);
+ ze.setName(entryEncoding.decode(fileName), fileName);
- // LFH offset,
- OffsetEntry offset = new OffsetEntry();
- offset.headerOffset = ZipLong.getValue(cfh, off);
- // data offset will be filled later
- entries.put(ze, offset);
+ // LFH offset,
+ OffsetEntry offset = new OffsetEntry();
+ offset.headerOffset = ZipLong.getValue(cfh, off);
+ // data offset will be filled later
+ entries.put(ze, offset);
- nameMap.put(ze.getName(), ze);
+ nameMap.put(ze.getName(), ze);
- byte[] cdExtraData = new byte[extraLen];
- archive.readFully(cdExtraData);
- ze.setCentralDirectoryExtra(cdExtraData);
+ byte[] cdExtraData = new byte[extraLen];
+ archive.readFully(cdExtraData);
+ ze.setCentralDirectoryExtra(cdExtraData);
- setSizesAndOffsetFromZip64Extra(ze, offset, diskStart);
+ setSizesAndOffsetFromZip64Extra(ze, offset, diskStart);
- byte[] comment = new byte[commentLen];
- archive.readFully(comment);
- ze.setComment(entryEncoding.decode(comment));
+ byte[] comment = new byte[commentLen];
+ archive.readFully(comment);
+ ze.setComment(entryEncoding.decode(comment));
- if (!hasUTF8Flag && useUnicodeExtraFields) {
- noUTF8Flag.put(ze, new NameAndComment(fileName, comment));
- }
+ if (!hasUTF8Flag && useUnicodeExtraFields) {
+ noUTF8Flag.put(ze, new NameAndComment(fileName, comment));
+ }
}
/**
@@ -525,39 +527,36 @@ public class ZipFile {
OffsetEntry offset,
int diskStart)
throws IOException {
- Zip64ExtendedInformationExtraField z64 =
- (Zip64ExtendedInformationExtraField)
- ze.getExtraField(Zip64ExtendedInformationExtraField
- .HEADER_ID);
- if (z64 != null) {
- boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;
- boolean hasCompressedSize =
- ze.getCompressedSize() == ZIP64_MAGIC;
- boolean hasRelativeHeaderOffset =
- offset.headerOffset == ZIP64_MAGIC;
- z64.reparseCentralDirectoryData(hasUncompressedSize,
- hasCompressedSize,
- hasRelativeHeaderOffset,
- diskStart ==
ZIP64_MAGIC_SHORT);
-
- if (hasUncompressedSize) {
- ze.setSize(z64.getSize().getLongValue());
- } else if (hasCompressedSize) {
- z64.setSize(new ZipEightByteInteger(ze.getSize()));
- }
-
- if (hasCompressedSize) {
- ze.setCompressedSize(z64.getCompressedSize()
- .getLongValue());
- } else if (hasUncompressedSize) {
- z64.setCompressedSize(new
ZipEightByteInteger(ze.getCompressedSize()));
- }
-
- if (hasRelativeHeaderOffset) {
- offset.headerOffset =
- z64.getRelativeHeaderOffset().getLongValue();
- }
+ Zip64ExtendedInformationExtraField z64 =
+ (Zip64ExtendedInformationExtraField)
+ ze.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
+ if (z64 != null) {
+ boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;
+ boolean hasCompressedSize = ze.getCompressedSize() == ZIP64_MAGIC;
+ boolean hasRelativeHeaderOffset =
+ offset.headerOffset == ZIP64_MAGIC;
+ z64.reparseCentralDirectoryData(hasUncompressedSize,
+ hasCompressedSize,
+ hasRelativeHeaderOffset,
+ diskStart == ZIP64_MAGIC_SHORT);
+
+ if (hasUncompressedSize) {
+ ze.setSize(z64.getSize().getLongValue());
+ } else if (hasCompressedSize) {
+ z64.setSize(new ZipEightByteInteger(ze.getSize()));
+ }
+
+ if (hasCompressedSize) {
+ ze.setCompressedSize(z64.getCompressedSize().getLongValue());
+ } else if (hasUncompressedSize) {
+ z64.setCompressedSize(new
ZipEightByteInteger(ze.getCompressedSize()));
+ }
+
+ if (hasRelativeHeaderOffset) {
+ offset.headerOffset =
+ z64.getRelativeHeaderOffset().getLongValue();
}
+ }
}
/**
@@ -680,25 +679,25 @@ public class ZipFile {
*/
private void positionAtCentralDirectory64()
throws IOException {
- archive.skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET);
- byte[] zip64EocdOffset = new byte[DWORD];
- archive.readFully(zip64EocdOffset);
- archive.seek(ZipEightByteInteger.getLongValue(zip64EocdOffset));
- byte[] sig = new byte[WORD];
- archive.readFully(sig);
- if (sig[POS_0] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_0]
- || sig[POS_1] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_1]
- || sig[POS_2] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_2]
- || sig[POS_3] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_3]
- ) {
- throw new ZipException("archive's ZIP64 end of central "
- + "directory locator is corrupt.");
- }
- archive.skipBytes(ZIP64_EOCD_CFD_LOCATOR_OFFSET
- - WORD /* signature has already been read */);
- byte[] cfdOffset = new byte[DWORD];
- archive.readFully(cfdOffset);
- archive.seek(ZipEightByteInteger.getLongValue(cfdOffset));
+ archive.skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET);
+ byte[] zip64EocdOffset = new byte[DWORD];
+ archive.readFully(zip64EocdOffset);
+ archive.seek(ZipEightByteInteger.getLongValue(zip64EocdOffset));
+ byte[] sig = new byte[WORD];
+ archive.readFully(sig);
+ if (sig[POS_0] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_0]
+ || sig[POS_1] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_1]
+ || sig[POS_2] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_2]
+ || sig[POS_3] != ZipArchiveOutputStream.ZIP64_EOCD_SIG[POS_3]
+ ) {
+ throw new ZipException("archive's ZIP64 end of central "
+ + "directory locator is corrupt.");
+ }
+ archive.skipBytes(ZIP64_EOCD_CFD_LOCATOR_OFFSET
+ - WORD /* signature has already been read */);
+ byte[] cfdOffset = new byte[DWORD];
+ archive.readFully(cfdOffset);
+ archive.seek(ZipEightByteInteger.getLongValue(cfdOffset));
}
/**
@@ -923,20 +922,20 @@ public class ZipFile {
*/
private final Comparator<ZipArchiveEntry> OFFSET_COMPARATOR =
new Comparator<ZipArchiveEntry>() {
- public int compare(ZipArchiveEntry e1, ZipArchiveEntry e2) {
- if (e1 == e2)
- return 0;
+ public int compare(ZipArchiveEntry e1, ZipArchiveEntry e2) {
+ if (e1 == e2)
+ return 0;
- OffsetEntry off1 = entries.get(e1);
- OffsetEntry off2 = entries.get(e2);
- if (off1 == null) {
- return 1;
- }
- if (off2 == null) {
- return -1;
- }
- long val = (off1.headerOffset - off2.headerOffset);
- return val == 0 ? 0 : val < 0 ? -1 : +1;
+ OffsetEntry off1 = entries.get(e1);
+ OffsetEntry off2 = entries.get(e2);
+ if (off1 == null) {
+ return 1;
+ }
+ if (off2 == null) {
+ return -1;
}
- };
+ long val = (off1.headerOffset - off2.headerOffset);
+ return val == 0 ? 0 : val < 0 ? -1 : +1;
+ }
+ };
}