Author: bodewig Date: Mon Jul 8 15:09:16 2013 New Revision: 1500788 URL: http://svn.apache.org/r1500788 Log: COMPRESS-233 performance and readability tweak for TarBuffer
Modified: commons/proper/compress/trunk/src/changes/changes.xml commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java Modified: commons/proper/compress/trunk/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1500788&r1=1500787&r2=1500788&view=diff ============================================================================== --- commons/proper/compress/trunk/src/changes/changes.xml (original) +++ commons/proper/compress/trunk/src/changes/changes.xml Mon Jul 8 15:09:16 2013 @@ -80,6 +80,10 @@ The <action> type attribute can be add,u 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"> Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java?rev=1500788&r1=1500787&r2=1500788&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java Mon Jul 8 15:09:16 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); } /**