Author: bodewig Date: Wed Jul 17 14:39:09 2013 New Revision: 1504155 URL: http://svn.apache.org/r1504155 Log: merge from trunk
Modified: commons/proper/compress/branches/LZMA/ (props changed) commons/proper/compress/branches/LZMA/NOTICE.txt commons/proper/compress/branches/LZMA/src/changes/changes.xml commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/ (props changed) commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java (contents, props changed) commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ (props changed) commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java Propchange: commons/proper/compress/branches/LZMA/ ------------------------------------------------------------------------------ Merged /commons/proper/compress/trunk:r1500025-1504154 Modified: commons/proper/compress/branches/LZMA/NOTICE.txt URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/NOTICE.txt?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/NOTICE.txt (original) +++ commons/proper/compress/branches/LZMA/NOTICE.txt Wed Jul 17 14:39:09 2013 @@ -4,8 +4,6 @@ Copyright 2002-2013 The Apache Software This product includes software developed at The Apache Software Foundation (http://www.apache.org/). -==================== - The files in the package org.apache.commons.compress.archivers.sevenz were derived from the LZMA SDK, version 9.20 (C/ and CPP/7zip/), which has been placed in the public domain: Modified: commons/proper/compress/branches/LZMA/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/changes/changes.xml?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/changes/changes.xml (original) +++ commons/proper/compress/branches/LZMA/src/changes/changes.xml Wed Jul 17 14:39:09 2013 @@ -76,6 +76,14 @@ The <action> type attribute can be add,u The class now also provides two new methods to obtain all entries of a given name rather than just the first one. </action> + <action type="update" date="2013-07-08" issue="COMPRESS-232" + due-to="BELUGA BEHR"> + Readabilty patch to TarArchiveInputStream. + </action> + <action type="update" date="2013-07-08" issue="COMPRESS-233" + due-to="BELUGA BEHR"> + Performance and readability patch to TarBuffer. + </action> </release> <release version="1.5" date="2013-03-14" description="Release 1.5"> Propchange: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/ ------------------------------------------------------------------------------ Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar:r1500025-1504154 Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java Wed Jul 17 14:39:09 2013 @@ -233,7 +233,8 @@ public class TarArchiveInputStream exten byte[] headerBuf = getRecord(); - if (hasHitEOF) { + if (headerBuf == null) { + /* hit EOF */ currEntry = null; return null; } @@ -324,28 +325,27 @@ public class TarArchiveInputStream exten * over any remaining data in the current entry, if there * is one, and place the input stream at the header of the * next entry. - * If there are no more entries in the archive, null will - * be returned to indicate that the end of the archive has - * been reached. + * + * <p>If there are no more entries in the archive, null will be + * returned to indicate that the end of the archive has been + * reached. At the same time the {@code hasHitEOF} marker will be + * set to true.</p> * * @return The next header in the archive, or null. * @throws IOException on error */ private byte[] getRecord() throws IOException { - if (hasHitEOF) { - return null; - } - - byte[] headerBuf = buffer.readRecord(); - - if (buffer.isEOFRecord(headerBuf)) { - hasHitEOF = true; - if (headerBuf != null) { + byte[] headerBuf = null; + if (!hasHitEOF) { + headerBuf = buffer.readRecord(); + hasHitEOF = buffer.isEOFRecord(headerBuf); + if (hasHitEOF && headerBuf != null) { buffer.tryToConsumeSecondEOFRecord(); + headerBuf = null; } } - return hasHitEOF ? null : headerBuf; + return headerBuf; } private void paxHeaders() throws IOException{ @@ -456,7 +456,7 @@ public class TarArchiveInputStream exten TarArchiveSparseEntry entry; do { byte[] headerBuf = getRecord(); - if (hasHitEOF) { + if (headerBuf == null) { currEntry = null; break; } Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java Wed Jul 17 14:39:09 2013 @@ -44,6 +44,8 @@ class TarBuffer { // Not public, because /** Default block size */ public static final int DEFAULT_BLKSIZE = (DEFAULT_RCDSIZE * 20); + private static final byte[] DEFAULT_EOF_RECORD = new byte[DEFAULT_RCDSIZE]; + // TODO make these final? (would need to change close() method) private InputStream inStream; private OutputStream outStream; @@ -51,6 +53,7 @@ class TarBuffer { // Not public, because private final int recordSize; private final int recsPerBlock; private final byte[] blockBuffer; + private final byte[] eofRecord; private int currBlkIdx; private int currRecIdx; @@ -119,6 +122,8 @@ class TarBuffer { // Not public, because this.recordSize = recordSize; this.recsPerBlock = (this.blockSize / this.recordSize); this.blockBuffer = new byte[this.blockSize]; + this.eofRecord = recordSize == DEFAULT_RCDSIZE + ? DEFAULT_EOF_RECORD : new byte[recordSize]; if (this.inStream != null) { this.currBlkIdx = -1; @@ -153,14 +158,7 @@ class TarBuffer { // Not public, because * @return true if the record data is an End of Archive */ public boolean isEOFRecord(byte[] record) { - if (record != null) { - for (int i = 0, sz = getRecordSize(); i < sz; ++i) { - if (record[i] != 0) { - return false; - } - } - } - return true; + return record == null || Arrays.equals(record, eofRecord); } /** Propchange: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java ------------------------------------------------------------------------------ Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java:r1500025-1504154 Propchange: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ ------------------------------------------------------------------------------ Merged /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip:r1500025-1504154 Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodeCommentExtraField.java Wed Jul 17 14:39:09 2013 @@ -24,15 +24,10 @@ package org.apache.commons.compress.arch * <p>Stores the UTF-8 version of the file comment as stored in the * central directory header.</p> * - * <pre> - * Value Size Description - * ----- ---- ----------- - * (UCom) 0x6375 Short tag for this extra block type ("uc") - * TSize Short total data size for this block - * Version 1 byte version of this extra field, currently 1 - * ComCRC32 4 bytes Comment Field CRC32 Checksum - * UnicodeCom Variable UTF-8 version of the entry comment - * </pre> + * <p>See {@link + * "http://www.pkware.com/documents/casestudies/APPNOTE.TXT PKWARE's + * APPNOTE.TXT, section 4.6.8"}.</p> + * * @NotThreadSafe super-class is not thread-safe */ public class UnicodeCommentExtraField extends AbstractUnicodeExtraField { Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/UnicodePathExtraField.java Wed Jul 17 14:39:09 2013 @@ -24,15 +24,9 @@ package org.apache.commons.compress.arch * <p>Stores the UTF-8 version of the file name field as stored in the * local header and central directory header.</p> * - * <pre> - * Value Size Description - * ----- ---- ----------- - * (UPath) 0x7075 Short tag for this extra block type ("up") - * TSize Short total data size for this block - * Version 1 byte version of this extra field, currently 1 - * NameCRC32 4 bytes File Name Field CRC32 Checksum - * UnicodeName Variable UTF-8 version of the entry File Name - * </pre> + * <p>See {@link + * "http://www.pkware.com/documents/casestudies/APPNOTE.TXT PKWARE's + * APPNOTE.TXT, section 4.6.9"}.</p> * @NotThreadSafe super-class is not thread-safe */ public class UnicodePathExtraField extends AbstractUnicodeExtraField { Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java Wed Jul 17 14:39:09 2013 @@ -27,42 +27,9 @@ import static org.apache.commons.compres * Holds size and other extended information for entries that use Zip64 * features. * - * <p>From {@link "http://www.pkware.com/documents/casestudies/APPNOTE.TXT PKWARE's APPNOTE.TXT"} - * <pre> - * Zip64 Extended Information Extra Field (0x0001): - * - * The following is the layout of the zip64 extended - * information "extra" block. If one of the size or - * offset fields in the Local or Central directory - * record is too small to hold the required data, - * a Zip64 extended information record is created. - * The order of the fields in the zip64 extended - * information record is fixed, but the fields will - * only appear if the corresponding Local or Central - * directory record field is set to 0xFFFF or 0xFFFFFFFF. - * - * Note: all fields stored in Intel low-byte/high-byte order. - * - * Value Size Description - * ----- ---- ----------- - * (ZIP64) 0x0001 2 bytes Tag for this "extra" block type - * Size 2 bytes Size of this "extra" block - * Original - * Size 8 bytes Original uncompressed file size - * Compressed - * Size 8 bytes Size of compressed data - * Relative Header - * Offset 8 bytes Offset of local header record - * Disk Start - * Number 4 bytes Number of the disk on which - * this file starts - * - * This entry in the Local header must include BOTH original - * and compressed file size fields. If encrypting the - * central directory and bit 13 of the general purpose bit - * flag is set indicating masking, the value stored in the - * Local Header for the original file size will be zero. - * </pre></p> + * <p>See {@link + * "http://www.pkware.com/documents/casestudies/APPNOTE.TXT PKWARE's + * APPNOTE.TXT, section 4.5.3"}.</p> * * <p>Currently Commons Compress doesn't support encrypting the * central directory so the note about masking doesn't apply.</p> Modified: commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1504155&r1=1504154&r2=1504155&view=diff ============================================================================== --- commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java (original) +++ commons/proper/compress/branches/LZMA/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java Wed Jul 17 14:39:09 2013 @@ -113,38 +113,38 @@ public class ZipArchiveInputStream exten private static final int LFH_LEN = 30; /* - local file header signature 4 bytes (0x04034b50) - version needed to extract 2 bytes - general purpose bit flag 2 bytes - compression method 2 bytes - last mod file time 2 bytes - last mod file date 2 bytes - crc-32 4 bytes - compressed size 4 bytes - uncompressed size 4 bytes - file name length 2 bytes - extra field length 2 bytes + local file header signature WORD + version needed to extract SHORT + general purpose bit flag SHORT + compression method SHORT + last mod file time SHORT + last mod file date SHORT + crc-32 WORD + compressed size WORD + uncompressed size WORD + file name length SHORT + extra field length SHORT */ private static final int CFH_LEN = 46; /* - central file header signature 4 bytes (0x02014b50) - version made by 2 bytes - version needed to extract 2 bytes - general purpose bit flag 2 bytes - compression method 2 bytes - last mod file time 2 bytes - last mod file date 2 bytes - crc-32 4 bytes - compressed size 4 bytes - uncompressed size 4 bytes - file name length 2 bytes - extra field length 2 bytes - file comment length 2 bytes - disk number start 2 bytes - internal file attributes 2 bytes - external file attributes 4 bytes - relative offset of local header 4 bytes + central file header signature WORD + version made by SHORT + version needed to extract SHORT + general purpose bit flag SHORT + compression method SHORT + last mod file time SHORT + last mod file date SHORT + crc-32 WORD + compressed size WORD + uncompressed size WORD + file name length SHORT + extra field length SHORT + file comment length SHORT + disk number start SHORT + internal file attributes SHORT + external file attributes WORD + relative offset of local header WORD */ private static final long TWO_EXP_32 = ZIP64_MAGIC + 1; @@ -860,20 +860,20 @@ public class ZipArchiveInputStream exten } // End of Central Directory Record - // end of central dir signature 4 bytes (0x06054b50) - // number of this disk 2 bytes + // end of central dir signature WORD + // number of this disk SHORT // number of the disk with the - // start of the central directory 2 bytes + // start of the central directory SHORT // total number of entries in the - // central directory on this disk 2 bytes + // central directory on this disk SHORT // total number of entries in - // the central directory 2 bytes - // size of the central directory 4 bytes + // the central directory SHORT + // size of the central directory WORD // offset of start of central // directory with respect to - // the starting disk number 4 bytes - // .ZIP file comment length 2 bytes - // .ZIP file comment (variable size) + // the starting disk number WORD + // .ZIP file comment length SHORT + // .ZIP file comment up to 64KB // /**