commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject commons-compress git commit: use term back-reference consistently
Date Wed, 18 Jan 2017 06:17:36 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master 74b38da45 -> b743bb24b


use term back-reference consistently


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/b743bb24
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/b743bb24
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/b743bb24

Branch: refs/heads/master
Commit: b743bb24b8870ebf7adb47f27750bc140a8ef671
Parents: 74b38da
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Wed Jan 18 07:17:13 2017 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Wed Jan 18 07:17:13 2017 +0100

----------------------------------------------------------------------
 .../lz4/BlockLZ4CompressorInputStream.java      | 46 ++++++++++----------
 .../lz4/BlockLZ4CompressorOutputStream.java     |  6 +--
 .../AbstractLZ77CompressorInputStream.java      | 30 ++++++-------
 .../snappy/SnappyCompressorInputStream.java     | 22 +++++-----
 4 files changed, 52 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b743bb24/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
index a93f10d..bb2038e 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorInputStream.java
@@ -34,11 +34,11 @@ public class BlockLZ4CompressorInputStream extends AbstractLZ77CompressorInputSt
 
     static final int WINDOW_SIZE = 1 << 16;
     static final int SIZE_BITS = 4;
-    static final int COPY_SIZE_MASK = (1 << SIZE_BITS) - 1;
-    static final int LITERAL_SIZE_MASK = COPY_SIZE_MASK << SIZE_BITS;
+    static final int BACK_REFERENCE_SIZE_MASK = (1 << SIZE_BITS) - 1;
+    static final int LITERAL_SIZE_MASK = BACK_REFERENCE_SIZE_MASK << SIZE_BITS;
 
-    /** Copy-size part of the block starting byte. */
-    private int nextCopySize;
+    /** Back-Reference-size part of the block starting byte. */
+    private int nextBackReferenceSize;
 
     /** Current state of the stream */
     private State state = State.NO_BLOCK;
@@ -69,21 +69,21 @@ public class BlockLZ4CompressorInputStream extends AbstractLZ77CompressorInputSt
         case IN_LITERAL:
             int litLen = readLiteral(b, off, len);
             if (!hasMoreDataInBlock()) {
-                state = State.LOOKING_FOR_COPY;
+                state = State.LOOKING_FOR_BACK_REFERENCE;
             }
             return litLen;
-        case LOOKING_FOR_COPY:
-            if (!initializeCopy()) {
+        case LOOKING_FOR_BACK_REFERENCE:
+            if (!initializeBackReference()) {
                 state = State.EOF;
                 return -1;
             }
             /*FALLTHROUGH*/
-        case IN_COPY:
-            int copyLen = readCopy(b, off, len);
+        case IN_BACK_REFERENCE:
+            int backReferenceLen = readBackReference(b, off, len);
             if (!hasMoreDataInBlock()) {
                 state = State.NO_BLOCK;
             }
-            return copyLen;
+            return backReferenceLen;
         default:
             throw new IOException("Unknown stream state " + state);
         }
@@ -94,9 +94,9 @@ public class BlockLZ4CompressorInputStream extends AbstractLZ77CompressorInputSt
         if (nextBlock == -1) {
             throw new IOException("Premature end of stream while looking for next block");
         }
-        nextCopySize = nextBlock & COPY_SIZE_MASK;
+        nextBackReferenceSize = nextBlock & BACK_REFERENCE_SIZE_MASK;
         long literalSizePart = (nextBlock & LITERAL_SIZE_MASK) >> SIZE_BITS;
-        if (literalSizePart == COPY_SIZE_MASK) {
+        if (literalSizePart == BACK_REFERENCE_SIZE_MASK) {
             literalSizePart += readSizeBytes();
         }
         startLiteral(literalSizePart);
@@ -117,30 +117,30 @@ public class BlockLZ4CompressorInputStream extends AbstractLZ77CompressorInputSt
     }
 
     /**
-     * @return false if there is no more copy - this means this is the
+     * @return false if there is no more back-reference - this means this is the
      * last block of the stream.
      */
-    private boolean initializeCopy() throws IOException {
-        int copyOffset = 0;
+    private boolean initializeBackReference() throws IOException {
+        int backReferenceOffset = 0;
         try {
-            copyOffset = (int) ByteUtils.fromLittleEndian(supplier, 2);
+            backReferenceOffset = (int) ByteUtils.fromLittleEndian(supplier, 2);
         } catch (IOException ex) {
-            if (nextCopySize == 0) { // the last block has no copy
+            if (nextBackReferenceSize == 0) { // the last block has no back-reference
                 return false;
             }
             throw ex;
         }
-        long copySize = nextCopySize;
-        if (nextCopySize == COPY_SIZE_MASK) {
-            copySize += readSizeBytes();
+        long backReferenceSize = nextBackReferenceSize;
+        if (nextBackReferenceSize == BACK_REFERENCE_SIZE_MASK) {
+            backReferenceSize += readSizeBytes();
         }
         // minimal match length 4 is encoded as 0
-        startCopy(copyOffset, copySize + 4);
-        state = State.IN_COPY;
+        startBackReference(backReferenceOffset, backReferenceSize + 4);
+        state = State.IN_BACK_REFERENCE;
         return true;
     }
 
     private enum State {
-        NO_BLOCK, IN_LITERAL, LOOKING_FOR_COPY, IN_COPY, EOF
+        NO_BLOCK, IN_LITERAL, LOOKING_FOR_BACK_REFERENCE, IN_BACK_REFERENCE, EOF
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b743bb24/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
index 79e1310..415e1f5 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz4/BlockLZ4CompressorOutputStream.java
@@ -45,9 +45,9 @@ public class BlockLZ4CompressorOutputStream extends CompressorOutputStream
{
         block.
 
       * the start of a literal/back-reference pair contains the length
-        of the copy (at least some part of it) so we can't start
-        writing the literal before we know how long the next copy is
-        going to be.
+        of the back-reference (at least some part of it) so we can't
+        start writing the literal before we know how long the next
+        back-reference is going to be.
 
       * there is a special rule for the final blocks
 

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b743bb24/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
b/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
index 0877a1d..24e74c8 100644
--- a/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/lz77support/AbstractLZ77CompressorInputStream.java
@@ -51,11 +51,11 @@ public abstract class AbstractLZ77CompressorInputStream extends CompressorInputS
     /** The underlying stream to read compressed data from */
     private final InputStream in;
 
-    /** Number of bytes still to be read from the current literal or copy. */
+    /** Number of bytes still to be read from the current literal or back-reference. */
     private long bytesRemaining;
 
-    /** Offset of the current copy. */
-    private int copyOffset;
+    /** Offset of the current back-reference. */
+    private int backReferenceOffset;
 
     /** uncompressed size */
     private int size = 0;
@@ -192,8 +192,8 @@ public abstract class AbstractLZ77CompressorInputStream extends CompressorInputS
      * @param the offset of the back-reference
      * @param length the length of the back-reference
      */
-    protected final void startCopy(int offset, long length) {
-        copyOffset = offset;
+    protected final void startBackReference(int offset, long length) {
+        backReferenceOffset = offset;
         bytesRemaining = length;
     }
 
@@ -205,7 +205,7 @@ public abstract class AbstractLZ77CompressorInputStream extends CompressorInputS
      * @return number of bytes read, may be 0. Will never return -1 as
      * EOF-detection is the responsibility of the subclass
      */
-    protected final int readCopy(final byte[] b, final int off, final int len) {
+    protected final int readBackReference(final byte[] b, final int off, final int len) {
         final int avail = available();
         if (len > avail) {
             tryToCopy(len - avail);
@@ -215,29 +215,29 @@ public abstract class AbstractLZ77CompressorInputStream extends CompressorInputS
 
     private void tryToCopy(int bytesToCopy) {
         // this will fit into the buffer without sliding and not
-        // require more than is available inside the copy
+        // require more than is available inside the back-reference
         int copy = (int) Math.min(Math.min(bytesToCopy, bytesRemaining),
                                   buf.length - writeIndex);
         if (copy == 0) {
             // NOP
-        } else if (copyOffset == 1) { // pretty common special case
+        } else if (backReferenceOffset == 1) { // pretty common special case
             final byte last = buf[writeIndex - 1];
             for (int i = 0; i < copy; i++) {
                 buf[writeIndex++] = last;
             }
-        } else if (copy < copyOffset) {
-            System.arraycopy(buf, writeIndex - copyOffset, buf, writeIndex, copy);
+        } else if (copy < backReferenceOffset) {
+            System.arraycopy(buf, writeIndex - backReferenceOffset, buf, writeIndex, copy);
             writeIndex += copy;
         } else {
-            final int fullRots = copy / copyOffset;
+            final int fullRots = copy / backReferenceOffset;
             for (int i = 0; i < fullRots; i++) {
-                System.arraycopy(buf, writeIndex - copyOffset, buf, writeIndex, copyOffset);
-                writeIndex += copyOffset;
+                System.arraycopy(buf, writeIndex - backReferenceOffset, buf, writeIndex,
backReferenceOffset);
+                writeIndex += backReferenceOffset;
             }
 
-            final int pad = copy - (copyOffset * fullRots);
+            final int pad = copy - (backReferenceOffset * fullRots);
             if (pad > 0) {
-                System.arraycopy(buf, writeIndex - copyOffset, buf, writeIndex, pad);
+                System.arraycopy(buf, writeIndex - backReferenceOffset, buf, writeIndex,
pad);
                 writeIndex += pad;
             }
         }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/b743bb24/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
b/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
index 28bd514..ddf68f1 100644
--- a/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
@@ -104,12 +104,12 @@ public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStre
                 state = State.NO_BLOCK;
             }
             return litLen;
-        case IN_COPY:
-            int copyLen = readCopy(b, off, len);
+        case IN_BACK_REFERENCE:
+            int backReferenceLen = readBackReference(b, off, len);
             if (!hasMoreDataInBlock()) {
                 state = State.NO_BLOCK;
             }
-            return copyLen;
+            return backReferenceLen;
         default:
             throw new IOException("Unknown stream state " + state);
         }
@@ -160,12 +160,12 @@ public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStre
             offset = (b & 0xE0) << 3;
             b = readOneByte();
             if (b == -1) {
-                throw new IOException("Premature end of stream reading copy length");
+                throw new IOException("Premature end of stream reading back-reference length");
             }
             offset |= b;
 
-            startCopy(offset, length);
-            state = State.IN_COPY;
+            startBackReference(offset, length);
+            state = State.IN_BACK_REFERENCE;
             break;
 
         case 0x02:
@@ -183,8 +183,8 @@ public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStre
 
             offset = (int) ByteUtils.fromLittleEndian(supplier, 2);
 
-            startCopy(offset, length);
-            state = State.IN_COPY;
+            startBackReference(offset, length);
+            state = State.IN_BACK_REFERENCE;
             break;
 
         case 0x03:
@@ -201,8 +201,8 @@ public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStre
 
             offset = (int) ByteUtils.fromLittleEndian(supplier, 4) & 0x7fffffff;
 
-            startCopy(offset, length);
-            state = State.IN_COPY;
+            startBackReference(offset, length);
+            state = State.IN_BACK_REFERENCE;
             break;
         }
     }
@@ -282,6 +282,6 @@ public class SnappyCompressorInputStream extends AbstractLZ77CompressorInputStre
     }
 
     private enum State {
-        NO_BLOCK, IN_LITERAL, IN_COPY
+        NO_BLOCK, IN_LITERAL, IN_BACK_REFERENCE
     }
 }


Mime
View raw message