COMPRESS-233 performance and readability tweak for TarBuffer
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1500788 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 27e33a6..2f54944 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -80,6 +80,10 @@
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">
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
index 4e13f54..baeb197 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
@@ -44,6 +44,8 @@
/** 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 @@
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 @@
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 @@
* @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);
}
/**