commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1540460 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors: CompressorInputStream.java snappy/FramedSnappyCompressorInputStream.java snappy/SnappyCompressorInputStream.java
Date Sun, 10 Nov 2013 10:26:31 GMT
Author: bodewig
Date: Sun Nov 10 10:26:30 2013
New Revision: 1540460

URL: http://svn.apache.org/r1540460
Log:
COMPRESS-147 CompressorInputStream didn't know the concept of pushback, also take adavantage
of count ignoring -1s

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java?rev=1540460&r1=1540459&r2=1540460&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorInputStream.java
Sun Nov 10 10:26:30 2013
@@ -42,12 +42,22 @@ public abstract class CompressorInputStr
      * @param read the number of bytes read
      */
     protected void count(long read) {
-        if(read != -1) {
+        if (read != -1) {
             bytesRead = bytesRead + read;
         }
     }
 
     /**
+     * Decrements the counter of already read bytes.
+     * 
+     * @param pushedBack the number of bytes pushed back.
+     * @since 1.7
+     */
+    protected void pushedBackBytes(long pushedBack) {
+        bytesRead -= pushedBack;
+    }
+
+    /**
      * Returns the current number of bytes read from this stream.
      * @return the number of read bytes
      * @deprecated this method may yield wrong results for large

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java?rev=1540460&r1=1540459&r2=1540460&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/FramedSnappyCompressorInputStream.java
Sun Nov 10 10:26:30 2013
@@ -136,7 +136,7 @@ public class FramedSnappyCompressorInput
             endReached = true;
         } else if (type == STREAM_IDENTIFIER_TYPE) {
             in.unread(type);
-            count(-1);
+            pushedBackBytes(1);
             readStreamIdentifier();
             readNextBlock();
         } else if (type == PADDING_CHUNK_TYPE
@@ -166,9 +166,7 @@ public class FramedSnappyCompressorInput
     private void readCrc() throws IOException {
         byte[] b = new byte[4];
         int read = IOUtils.readFully(in, b);
-        if (read > 0) {
-            count(read);
-        }
+        count(read);
         if (read != 4) {
             throw new IOException("premature end of stream");
         }
@@ -190,9 +188,7 @@ public class FramedSnappyCompressorInput
     private void skipBlock() throws IOException {
         int size = readSize();
         long read = IOUtils.skip(in, size);
-        if (read > 0) {
-            count(read);
-        }
+        count(read);
         if (read != size) {
             throw new IOException("premature end of stream");
         }
@@ -201,9 +197,7 @@ public class FramedSnappyCompressorInput
     private void readStreamIdentifier() throws IOException {
         byte[] b = new byte[10];
         int read = IOUtils.readFully(in, b);
-        if (read > 0) {
-            count(read);
-        }
+        count(read);
         if (10 != read || !matches(b, 10)) {
             throw new IOException("Not a framed Snappy stream");
         }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java?rev=1540460&r1=1540459&r2=1540460&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/snappy/SnappyCompressorInputStream.java
Sun Nov 10 10:26:30 2013
@@ -311,9 +311,7 @@ public class SnappyCompressorInputStream
      */
     private boolean expandLiteral(final int length) throws IOException {
         int bytesRead = in.read(decompressBuf, writeIndex, length);
-        if (bytesRead != -1) {
-            count(bytesRead);
-        }
+        count(bytesRead);
         if (length != bytesRead) {
             throw new IOException("Premature end of stream");
         }



Mime
View raw message