Repository: commons-compress Updated Branches: refs/heads/master 5e0980f01 -> 2b5ba89b7
rename instance fields that look like class fields Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/c61c68d8 Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/c61c68d8 Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/c61c68d8 Branch: refs/heads/master Commit: c61c68d802266e0265a60e81f2eb5ae56e14b315 Parents: 5e0980f Author: Stefan Bodewig <[email protected]> Authored: Tue Dec 20 15:00:58 2016 +0100 Committer: Stefan Bodewig <[email protected]> Committed: Tue Dec 20 15:00:58 2016 +0100 ---------------------------------------------------------------------- .../compress/archivers/ArchiveInputStream.java | 6 +- .../archivers/ar/ArArchiveInputStream.java | 36 ++--- .../archivers/cpio/CpioArchiveInputStream.java | 24 ++-- .../archivers/tar/TarArchiveInputStream.java | 6 +- .../archivers/zip/ZipArchiveInputStream.java | 64 ++++----- .../commons/compress/archivers/zip/ZipFile.java | 133 +++++++++---------- .../compressors/pack200/StreamBridge.java | 6 +- 7 files changed, 137 insertions(+), 138 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java index afd3c4a..f36b5a2 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveInputStream.java @@ -39,7 +39,7 @@ import java.io.InputStream; */ public abstract class ArchiveInputStream extends InputStream { - private final byte[] SINGLE = new byte[1]; + private final byte[] single = new byte[1]; private static final int BYTE_MASK = 0xFF; /** holds the number of bytes read in this stream */ @@ -78,8 +78,8 @@ public abstract class ArchiveInputStream extends InputStream { */ @Override public int read() throws IOException { - final int num = read(SINGLE, 0, 1); - return num == -1 ? -1 : SINGLE[0] & BYTE_MASK; + final int num = read(single, 0, 1); + return num == -1 ? -1 : single[0] & BYTE_MASK; } /** http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java index 0489ad4..69bc640 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java @@ -55,11 +55,11 @@ public class ArArchiveInputStream extends ArchiveInputStream { private long entryOffset = -1; // cached buffers - must only be used locally in the class (COMPRESS-172 - reduce garbage collection) - private final byte[] NAME_BUF = new byte[16]; - private final byte[] LAST_MODIFIED_BUF = new byte[12]; - private final byte[] ID_BUF = new byte[6]; - private final byte[] FILE_MODE_BUF = new byte[8]; - private final byte[] LENGTH_BUF = new byte[10]; + private final byte[] nameBuf = new byte[16]; + private final byte[] lastModifiedBuf = new byte[12]; + private final byte[] idBuf = new byte[6]; + private final byte[] fileModeBuf = new byte[8]; + private final byte[] lengthBuf = new byte[10]; /** * Constructs an Ar input stream with the referenced stream @@ -109,13 +109,13 @@ public class ArArchiveInputStream extends ArchiveInputStream { return null; } - IOUtils.readFully(this, NAME_BUF); - IOUtils.readFully(this, LAST_MODIFIED_BUF); - IOUtils.readFully(this, ID_BUF); - final int userId = asInt(ID_BUF, true); - IOUtils.readFully(this, ID_BUF); - IOUtils.readFully(this, FILE_MODE_BUF); - IOUtils.readFully(this, LENGTH_BUF); + IOUtils.readFully(this, nameBuf); + IOUtils.readFully(this, lastModifiedBuf); + IOUtils.readFully(this, idBuf); + final int userId = asInt(idBuf, true); + IOUtils.readFully(this, idBuf); + IOUtils.readFully(this, fileModeBuf); + IOUtils.readFully(this, lengthBuf); { final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.TRAILER); @@ -136,13 +136,13 @@ public class ArArchiveInputStream extends ArchiveInputStream { // GNU ar uses a '/' to mark the end of the filename; this allows for the use of spaces without the use of an extended filename. // entry name is stored as ASCII string - String temp = ArchiveUtils.toAsciiString(NAME_BUF).trim(); + String temp = ArchiveUtils.toAsciiString(nameBuf).trim(); if (isGNUStringTable(temp)) { // GNU extended filenames entry - currentEntry = readGNUStringTable(LENGTH_BUF); + currentEntry = readGNUStringTable(lengthBuf); return getNextArEntry(); } - long len = asLong(LENGTH_BUF); + long len = asLong(lengthBuf); if (temp.endsWith("/")) { // GNU terminator temp = temp.substring(0, temp.length() - 1); } else if (isGNULongName(temp)) { @@ -159,9 +159,9 @@ public class ArArchiveInputStream extends ArchiveInputStream { } currentEntry = new ArArchiveEntry(temp, len, userId, - asInt(ID_BUF, true), - asInt(FILE_MODE_BUF, 8), - asLong(LAST_MODIFIED_BUF)); + asInt(idBuf, true), + asInt(fileModeBuf, 8), + asLong(lastModifiedBuf)); return currentEntry; } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java index 5f2e586..a7059bc 100644 --- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java @@ -82,9 +82,9 @@ public class CpioArchiveInputStream extends ArchiveInputStream implements private final InputStream in; // cached buffers - must only be used locally in the class (COMPRESS-172 - reduce garbage collection) - private final byte[] TWO_BYTES_BUF = new byte[2]; - private final byte[] FOUR_BYTES_BUF = new byte[4]; - private final byte[] SIX_BYTES_BUF = new byte[6]; + private final byte[] twoBytesBuf = new byte[2]; + private final byte[] fourBytesBuf = new byte[4]; + private final byte[] sixBytesBuf = new byte[6]; private final int blockSize; @@ -234,18 +234,18 @@ public class CpioArchiveInputStream extends ArchiveInputStream implements if (this.entry != null) { closeEntry(); } - readFully(TWO_BYTES_BUF, 0, TWO_BYTES_BUF.length); - if (CpioUtil.byteArray2long(TWO_BYTES_BUF, false) == MAGIC_OLD_BINARY) { + readFully(twoBytesBuf, 0, twoBytesBuf.length); + if (CpioUtil.byteArray2long(twoBytesBuf, false) == MAGIC_OLD_BINARY) { this.entry = readOldBinaryEntry(false); - } else if (CpioUtil.byteArray2long(TWO_BYTES_BUF, true) + } else if (CpioUtil.byteArray2long(twoBytesBuf, true) == MAGIC_OLD_BINARY) { this.entry = readOldBinaryEntry(true); } else { - System.arraycopy(TWO_BYTES_BUF, 0, SIX_BYTES_BUF, 0, - TWO_BYTES_BUF.length); - readFully(SIX_BYTES_BUF, TWO_BYTES_BUF.length, - FOUR_BYTES_BUF.length); - final String magicString = ArchiveUtils.toAsciiString(SIX_BYTES_BUF); + System.arraycopy(twoBytesBuf, 0, sixBytesBuf, 0, + twoBytesBuf.length); + readFully(sixBytesBuf, twoBytesBuf.length, + fourBytesBuf.length); + final String magicString = ArchiveUtils.toAsciiString(sixBytesBuf); switch (magicString) { case MAGIC_NEW: this.entry = readNewEntry(false); @@ -276,7 +276,7 @@ public class CpioArchiveInputStream extends ArchiveInputStream implements private void skip(final int bytes) throws IOException{ // bytes cannot be more than 3 bytes if (bytes > 0) { - readFully(FOUR_BYTES_BUF, 0, bytes); + readFully(fourBytesBuf, 0, bytes); } } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java index f03e968..281ad5b 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java @@ -49,7 +49,7 @@ public class TarArchiveInputStream extends ArchiveInputStream { private static final int SMALL_BUFFER_SIZE = 256; - private final byte[] SMALL_BUF = new byte[SMALL_BUFFER_SIZE]; + private final byte[] smallBuf = new byte[SMALL_BUFFER_SIZE]; /** The size the TAR header */ private final int recordSize; @@ -357,8 +357,8 @@ public class TarArchiveInputStream extends ArchiveInputStream { // read in the name final ByteArrayOutputStream longName = new ByteArrayOutputStream(); int length = 0; - while ((length = read(SMALL_BUF)) >= 0) { - longName.write(SMALL_BUF, 0, length); + while ((length = read(smallBuf)) >= 0) { + longName.write(smallBuf, 0, length); } getNextEntry(); if (currEntry == null) { http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java index 035f804..3783576 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java @@ -152,11 +152,11 @@ public class ZipArchiveInputStream extends ArchiveInputStream { private static final long TWO_EXP_32 = ZIP64_MAGIC + 1; // cached buffers - must only be used locally in the class (COMPRESS-172 - reduce garbage collection) - private final byte[] LFH_BUF = new byte[LFH_LEN]; - private final byte[] SKIP_BUF = new byte[1024]; - private final byte[] SHORT_BUF = new byte[SHORT]; - private final byte[] WORD_BUF = new byte[WORD]; - private final byte[] TWO_DWORD_BUF = new byte[2 * DWORD]; + private final byte[] lfhBuf = new byte[LFH_LEN]; + private final byte[] skipBuf = new byte[1024]; + private final byte[] shortBuf = new byte[SHORT]; + private final byte[] wordBuf = new byte[WORD]; + private final byte[] twoDwordBuf = new byte[2 * DWORD]; private int entriesRead = 0; @@ -232,15 +232,15 @@ public class ZipArchiveInputStream extends ArchiveInputStream { // first local file header - look for it and fail with // the appropriate error message if this is a split // archive. - readFirstLocalFileHeader(LFH_BUF); + readFirstLocalFileHeader(lfhBuf); } else { - readFully(LFH_BUF); + readFully(lfhBuf); } } catch (final EOFException e) { return null; } - final ZipLong sig = new ZipLong(LFH_BUF); + final ZipLong sig = new ZipLong(lfhBuf); if (sig.equals(ZipLong.CFH_SIG) || sig.equals(ZipLong.AED_SIG)) { hitCentralDirectory = true; skipRemainderOfArchive(); @@ -253,11 +253,11 @@ public class ZipArchiveInputStream extends ArchiveInputStream { int off = WORD; current = new CurrentEntry(); - final int versionMadeBy = ZipShort.getValue(LFH_BUF, off); + final int versionMadeBy = ZipShort.getValue(lfhBuf, off); off += SHORT; current.entry.setPlatform((versionMadeBy >> ZipFile.BYTE_SHIFT) & ZipFile.NIBLET_MASK); - final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(LFH_BUF, off); + final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(lfhBuf, off); final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames(); final ZipEncoding entryEncoding = hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding; current.hasDataDescriptor = gpFlag.usesDataDescriptor(); @@ -265,32 +265,32 @@ public class ZipArchiveInputStream extends ArchiveInputStream { off += SHORT; - current.entry.setMethod(ZipShort.getValue(LFH_BUF, off)); + current.entry.setMethod(ZipShort.getValue(lfhBuf, off)); off += SHORT; - final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(LFH_BUF, off)); + final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(lfhBuf, off)); current.entry.setTime(time); off += WORD; ZipLong size = null, cSize = null; if (!current.hasDataDescriptor) { - current.entry.setCrc(ZipLong.getValue(LFH_BUF, off)); + current.entry.setCrc(ZipLong.getValue(lfhBuf, off)); off += WORD; - cSize = new ZipLong(LFH_BUF, off); + cSize = new ZipLong(lfhBuf, off); off += WORD; - size = new ZipLong(LFH_BUF, off); + size = new ZipLong(lfhBuf, off); off += WORD; } else { off += 3 * WORD; } - final int fileNameLen = ZipShort.getValue(LFH_BUF, off); + final int fileNameLen = ZipShort.getValue(lfhBuf, off); off += SHORT; - final int extraLen = ZipShort.getValue(LFH_BUF, off); + final int extraLen = ZipShort.getValue(lfhBuf, off); off += SHORT; final byte[] fileName = new byte[fileNameLen]; @@ -550,7 +550,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream { long skipped = 0; while (skipped < value) { final long rem = value - skipped; - final int x = read(SKIP_BUF, 0, (int) (SKIP_BUF.length > rem ? rem : SKIP_BUF.length)); + final int x = read(skipBuf, 0, (int) (skipBuf.length > rem ? rem : skipBuf.length)); if (x == -1) { return skipped; } @@ -728,12 +728,12 @@ public class ZipArchiveInputStream extends ArchiveInputStream { } private void readDataDescriptor() throws IOException { - readFully(WORD_BUF); - ZipLong val = new ZipLong(WORD_BUF); + readFully(wordBuf); + ZipLong val = new ZipLong(wordBuf); if (ZipLong.DD_SIG.equals(val)) { // data descriptor with signature, skip sig - readFully(WORD_BUF); - val = new ZipLong(WORD_BUF); + readFully(wordBuf); + val = new ZipLong(wordBuf); } current.entry.setCrc(val.getValue()); @@ -748,15 +748,15 @@ public class ZipArchiveInputStream extends ArchiveInputStream { // descriptor (ignoring archive decryption headers for now). // If so, push back eight bytes and assume sizes are four // bytes, otherwise sizes are eight bytes each. - readFully(TWO_DWORD_BUF); - final ZipLong potentialSig = new ZipLong(TWO_DWORD_BUF, DWORD); + readFully(twoDwordBuf); + final ZipLong potentialSig = new ZipLong(twoDwordBuf, DWORD); if (potentialSig.equals(ZipLong.CFH_SIG) || potentialSig.equals(ZipLong.LFH_SIG)) { - pushback(TWO_DWORD_BUF, DWORD, DWORD); - current.entry.setCompressedSize(ZipLong.getValue(TWO_DWORD_BUF)); - current.entry.setSize(ZipLong.getValue(TWO_DWORD_BUF, WORD)); + pushback(twoDwordBuf, DWORD, DWORD); + current.entry.setCompressedSize(ZipLong.getValue(twoDwordBuf)); + current.entry.setSize(ZipLong.getValue(twoDwordBuf, WORD)); } else { - current.entry.setCompressedSize(ZipEightByteInteger.getLongValue(TWO_DWORD_BUF)); - current.entry.setSize(ZipEightByteInteger.getLongValue(TWO_DWORD_BUF, DWORD)); + current.entry.setCompressedSize(ZipEightByteInteger.getLongValue(twoDwordBuf)); + current.entry.setSize(ZipEightByteInteger.getLongValue(twoDwordBuf, DWORD)); } } @@ -920,9 +920,9 @@ public class ZipArchiveInputStream extends ArchiveInputStream { realSkip((long) entriesRead * CFH_LEN - LFH_LEN); findEocdRecord(); realSkip((long) ZipFile.MIN_EOCD_SIZE - WORD /* signature */ - SHORT /* comment len */); - readFully(SHORT_BUF); + readFully(shortBuf); // file comment - realSkip(ZipShort.getValue(SHORT_BUF)); + realSkip(ZipShort.getValue(shortBuf)); } /** @@ -974,7 +974,7 @@ public class ZipArchiveInputStream extends ArchiveInputStream { long skipped = 0; while (skipped < value) { final long rem = value - skipped; - final int x = in.read(SKIP_BUF, 0, (int) (SKIP_BUF.length > rem ? rem : SKIP_BUF.length)); + final int x = in.read(skipBuf, 0, (int) (skipBuf.length > rem ? rem : skipBuf.length)); if (x == -1) { return; } http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java index d2691fd..34c08b2 100644 --- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java @@ -142,14 +142,13 @@ public class ZipFile implements Closeable { private volatile boolean closed = true; // cached buffers - must only be used locally in the class (COMPRESS-172 - reduce garbage collection) - private final byte[] DWORD_BUF = new byte[DWORD]; - private final byte[] WORD_BUF = new byte[WORD]; - private final byte[] CFH_BUF = new byte[CFH_LEN]; - private final byte[] SHORT_BUF = new byte[SHORT]; - private final ByteBuffer DWORD_BBUF = ByteBuffer.wrap(DWORD_BUF); - private final ByteBuffer WORD_BBUF = ByteBuffer.wrap(WORD_BUF); - private final ByteBuffer CFH_BBUF = ByteBuffer.wrap(CFH_BUF); - private final ByteBuffer SHORT_BBUF = ByteBuffer.wrap(SHORT_BUF); + private final byte[] dwordBuf = new byte[DWORD]; + private final byte[] wordBuf = new byte[WORD]; + private final byte[] cfhBuf = new byte[CFH_LEN]; + private final byte[] shortBuf = new byte[SHORT]; + private final ByteBuffer dwordBbuf = ByteBuffer.wrap(dwordBuf); + private final ByteBuffer wordBbuf = ByteBuffer.wrap(wordBuf); + private final ByteBuffer cfhBbuf = ByteBuffer.wrap(cfhBuf); /** * Opens the given file for reading, assuming "UTF8" for file names. @@ -359,7 +358,7 @@ public class ZipFile implements Closeable { */ public Enumeration<ZipArchiveEntry> getEntriesInPhysicalOrder() { final ZipArchiveEntry[] allEntries = entries.toArray(new ZipArchiveEntry[entries.size()]); - Arrays.sort(allEntries, OFFSET_COMPARATOR); + Arrays.sort(allEntries, offsetComparator); return Collections.enumeration(Arrays.asList(allEntries)); } @@ -408,7 +407,7 @@ public class ZipFile implements Closeable { ZipArchiveEntry[] entriesOfThatName = new ZipArchiveEntry[0]; if (nameMap.containsKey(name)) { entriesOfThatName = nameMap.get(name).toArray(entriesOfThatName); - Arrays.sort(entriesOfThatName, OFFSET_COMPARATOR); + Arrays.sort(entriesOfThatName, offsetComparator); } return Arrays.asList(entriesOfThatName); } @@ -612,9 +611,9 @@ public class ZipFile implements Closeable { positionAtCentralDirectory(); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - long sig = ZipLong.getValue(WORD_BUF); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + long sig = ZipLong.getValue(wordBuf); if (sig != CFH_SIG && startsWithLocalFileHeader()) { throw new IOException("central directory is empty, can't expand" @@ -623,9 +622,9 @@ public class ZipFile implements Closeable { while (sig == CFH_SIG) { readCentralDirectoryEntry(noUTF8Flag); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - sig = ZipLong.getValue(WORD_BUF); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + sig = ZipLong.getValue(wordBuf); } return noUTF8Flag; } @@ -642,62 +641,62 @@ public class ZipFile implements Closeable { private void readCentralDirectoryEntry(final Map<ZipArchiveEntry, NameAndComment> noUTF8Flag) throws IOException { - CFH_BBUF.rewind(); - IOUtils.readFully(archive, CFH_BBUF); + cfhBbuf.rewind(); + IOUtils.readFully(archive, cfhBbuf); int off = 0; final OffsetEntry offset = new OffsetEntry(); final Entry ze = new Entry(offset); - final int versionMadeBy = ZipShort.getValue(CFH_BUF, off); + final int versionMadeBy = ZipShort.getValue(cfhBuf, off); off += SHORT; ze.setVersionMadeBy(versionMadeBy); ze.setPlatform((versionMadeBy >> BYTE_SHIFT) & NIBLET_MASK); - ze.setVersionRequired(ZipShort.getValue(CFH_BUF, off)); + ze.setVersionRequired(ZipShort.getValue(cfhBuf, off)); off += SHORT; // version required - final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(CFH_BUF, off); + final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(cfhBuf, off); final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames(); final ZipEncoding entryEncoding = hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding; ze.setGeneralPurposeBit(gpFlag); - ze.setRawFlag(ZipShort.getValue(CFH_BUF, off)); + ze.setRawFlag(ZipShort.getValue(cfhBuf, off)); off += SHORT; //noinspection MagicConstant - ze.setMethod(ZipShort.getValue(CFH_BUF, off)); + ze.setMethod(ZipShort.getValue(cfhBuf, off)); off += SHORT; - final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(CFH_BUF, off)); + final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(cfhBuf, off)); ze.setTime(time); off += WORD; - ze.setCrc(ZipLong.getValue(CFH_BUF, off)); + ze.setCrc(ZipLong.getValue(cfhBuf, off)); off += WORD; - ze.setCompressedSize(ZipLong.getValue(CFH_BUF, off)); + ze.setCompressedSize(ZipLong.getValue(cfhBuf, off)); off += WORD; - ze.setSize(ZipLong.getValue(CFH_BUF, off)); + ze.setSize(ZipLong.getValue(cfhBuf, off)); off += WORD; - final int fileNameLen = ZipShort.getValue(CFH_BUF, off); + final int fileNameLen = ZipShort.getValue(cfhBuf, off); off += SHORT; - final int extraLen = ZipShort.getValue(CFH_BUF, off); + final int extraLen = ZipShort.getValue(cfhBuf, off); off += SHORT; - final int commentLen = ZipShort.getValue(CFH_BUF, off); + final int commentLen = ZipShort.getValue(cfhBuf, off); off += SHORT; - final int diskStart = ZipShort.getValue(CFH_BUF, off); + final int diskStart = ZipShort.getValue(cfhBuf, off); off += SHORT; - ze.setInternalAttributes(ZipShort.getValue(CFH_BUF, off)); + ze.setInternalAttributes(ZipShort.getValue(cfhBuf, off)); off += SHORT; - ze.setExternalAttributes(ZipLong.getValue(CFH_BUF, off)); + ze.setExternalAttributes(ZipLong.getValue(cfhBuf, off)); off += WORD; final byte[] fileName = new byte[fileNameLen]; @@ -705,7 +704,7 @@ public class ZipFile implements Closeable { ze.setName(entryEncoding.decode(fileName), fileName); // LFH offset, - offset.headerOffset = ZipLong.getValue(CFH_BUF, off); + offset.headerOffset = ZipLong.getValue(cfhBuf, off); // data offset will be filled later entries.add(ze); @@ -878,10 +877,10 @@ public class ZipFile implements Closeable { archive.position() > ZIP64_EOCDL_LENGTH; if (searchedForZip64EOCD) { archive.position(archive.position() - ZIP64_EOCDL_LENGTH); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); found = Arrays.equals(ZipArchiveOutputStream.ZIP64_EOCD_LOC_SIG, - WORD_BUF); + wordBuf); } if (!found) { // not a ZIP64 archive @@ -907,20 +906,20 @@ public class ZipFile implements Closeable { throws IOException { skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET - WORD /* signature has already been read */); - DWORD_BBUF.rewind(); - IOUtils.readFully(archive, DWORD_BBUF); - archive.position(ZipEightByteInteger.getLongValue(DWORD_BUF)); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - if (!Arrays.equals(WORD_BUF, ZipArchiveOutputStream.ZIP64_EOCD_SIG)) { + dwordBbuf.rewind(); + IOUtils.readFully(archive, dwordBbuf); + archive.position(ZipEightByteInteger.getLongValue(dwordBuf)); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + if (!Arrays.equals(wordBuf, ZipArchiveOutputStream.ZIP64_EOCD_SIG)) { throw new ZipException("archive's ZIP64 end of central " + "directory locator is corrupt."); } skipBytes(ZIP64_EOCD_CFD_LOCATOR_OFFSET - WORD /* signature has already been read */); - DWORD_BBUF.rewind(); - IOUtils.readFully(archive, DWORD_BBUF); - archive.position(ZipEightByteInteger.getLongValue(DWORD_BUF)); + dwordBbuf.rewind(); + IOUtils.readFully(archive, dwordBbuf); + archive.position(ZipEightByteInteger.getLongValue(dwordBuf)); } /** @@ -933,9 +932,9 @@ public class ZipFile implements Closeable { private void positionAtCentralDirectory32() throws IOException { skipBytes(CFD_LOCATOR_OFFSET); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - archive.position(ZipLong.getValue(WORD_BUF)); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + archive.position(ZipLong.getValue(wordBuf)); } /** @@ -967,19 +966,19 @@ public class ZipFile implements Closeable { for (; off >= stopSearching; off--) { archive.position(off); try { - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - WORD_BBUF.flip(); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + wordBbuf.flip(); } catch (EOFException ex) { break; } - int curr = WORD_BBUF.get(); + int curr = wordBbuf.get(); if (curr == sig[POS_0]) { - curr = WORD_BBUF.get(); + curr = wordBbuf.get(); if (curr == sig[POS_1]) { - curr = WORD_BBUF.get(); + curr = wordBbuf.get(); if (curr == sig[POS_2]) { - curr = WORD_BBUF.get(); + curr = wordBbuf.get(); if (curr == sig[POS_3]) { found = true; break; @@ -1040,13 +1039,13 @@ public class ZipFile implements Closeable { final OffsetEntry offsetEntry = ze.getOffsetEntry(); final long offset = offsetEntry.headerOffset; archive.position(offset + LFH_OFFSET_FOR_FILENAME_LENGTH); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - WORD_BBUF.flip(); - WORD_BBUF.get(SHORT_BUF); - final int fileNameLen = ZipShort.getValue(SHORT_BUF); - WORD_BBUF.get(SHORT_BUF); - final int extraFieldLen = ZipShort.getValue(SHORT_BUF); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + wordBbuf.flip(); + wordBbuf.get(shortBuf); + final int fileNameLen = ZipShort.getValue(shortBuf); + wordBbuf.get(shortBuf); + final int extraFieldLen = ZipShort.getValue(shortBuf); skipBytes(fileNameLen); final byte[] localExtraData = new byte[extraFieldLen]; IOUtils.readFully(archive, ByteBuffer.wrap(localExtraData)); @@ -1076,9 +1075,9 @@ public class ZipFile implements Closeable { */ private boolean startsWithLocalFileHeader() throws IOException { archive.position(0); - WORD_BBUF.rewind(); - IOUtils.readFully(archive, WORD_BBUF); - return Arrays.equals(WORD_BUF, ZipArchiveOutputStream.LFH_SIG); + wordBbuf.rewind(); + IOUtils.readFully(archive, wordBbuf); + return Arrays.equals(wordBuf, ZipArchiveOutputStream.LFH_SIG); } /** @@ -1194,7 +1193,7 @@ public class ZipFile implements Closeable { * * @since 1.1 */ - private final Comparator<ZipArchiveEntry> OFFSET_COMPARATOR = + private final Comparator<ZipArchiveEntry> offsetComparator = new Comparator<ZipArchiveEntry>() { @Override public int compare(final ZipArchiveEntry e1, final ZipArchiveEntry e2) { http://git-wip-us.apache.org/repos/asf/commons-compress/blob/c61c68d8/src/main/java/org/apache/commons/compress/compressors/pack200/StreamBridge.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/compress/compressors/pack200/StreamBridge.java b/src/main/java/org/apache/commons/compress/compressors/pack200/StreamBridge.java index 980cb7e..9de3567 100644 --- a/src/main/java/org/apache/commons/compress/compressors/pack200/StreamBridge.java +++ b/src/main/java/org/apache/commons/compress/compressors/pack200/StreamBridge.java @@ -33,7 +33,7 @@ import java.io.OutputStream; */ abstract class StreamBridge extends FilterOutputStream { private InputStream input; - private final Object INPUT_LOCK = new Object(); + private final Object inputLock = new Object(); protected StreamBridge(final OutputStream out) { super(out); @@ -47,7 +47,7 @@ abstract class StreamBridge extends FilterOutputStream { * Provides the input view. */ InputStream getInput() throws IOException { - synchronized (INPUT_LOCK) { + synchronized (inputLock) { if (input == null) { input = getInputView(); } @@ -65,7 +65,7 @@ abstract class StreamBridge extends FilterOutputStream { */ void stop() throws IOException { close(); - synchronized (INPUT_LOCK) { + synchronized (inputLock) { if (input != null) { input.close(); input = null;
