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: COMPRESS-376 delay initialization of concatenated streams
Date Tue, 20 Dec 2016 13:25:21 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/COMPRESS-376 71caa69e2 -> 6a8f6c95f


COMPRESS-376 delay initialization of concatenated streams


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

Branch: refs/heads/COMPRESS-376
Commit: 6a8f6c95f3a1b71c6b5950c558fbc0d22786d763
Parents: 71caa69
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Tue Dec 20 14:24:17 2016 +0100
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Tue Dec 20 14:24:17 2016 +0100

----------------------------------------------------------------------
 .../gzip/GzipCompressorInputStream.java         |  26 +++++++++++++++----
 .../compressors/gzip/Compress376Test.java       |   7 +----
 src/test/resources/COMPRESS-376.tar.gz          | Bin 2048 -> 8192 bytes
 3 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6a8f6c95/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
index 9f28c8a..e95b967 100644
--- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java
@@ -77,6 +77,8 @@ public class GzipCompressorInputStream extends CompressorInputStream {
     // True once everything has been decompressed
     private boolean endReached = false;
 
+    private boolean currentStreamInitialized = false;
+
     // used in no-arg read method
     private final byte[] oneByte = new byte[1];
 
@@ -230,6 +232,7 @@ public class GzipCompressorInputStream extends CompressorInputStream {
         inf.reset();
         crc.reset();
 
+        currentStreamInitialized = true;
         return true;
     }
 
@@ -265,6 +268,11 @@ public class GzipCompressorInputStream extends CompressorInputStream
{
             return -1;
         }
 
+        if (!currentStreamInitialized && !init(false)) {
+            eofReached();
+            return -1;
+        }
+
         int size = 0;
 
         while (len > 0) {
@@ -327,12 +335,12 @@ public class GzipCompressorInputStream extends CompressorInputStream
{
                                           + "(uncompressed size mismatch)");
                 }
 
-                // See if this is the end of the file.
-                if (!decompressConcatenated || !init(false)) {
-                    inf.end();
-                    inf = null;
-                    endReached = true;
+                if (!decompressConcatenated) {
+                    eofReached();
                     return size == 0 ? -1 : size;
+                } else {
+                    currentStreamInitialized = false;
+                    return size == 0 ? read(b, off, len) : size;
                 }
             }
         }
@@ -366,6 +374,14 @@ public class GzipCompressorInputStream extends CompressorInputStream
{
         return true;
     }
 
+    private void eofReached() {
+        if (inf != null) {
+            inf.end();
+            inf = null;
+        }
+        endReached = true;
+    }
+
     /**
      * Closes the input stream (unless it is System.in).
      *

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6a8f6c95/src/test/java/org/apache/commons/compress/compressors/gzip/Compress376Test.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/gzip/Compress376Test.java
b/src/test/java/org/apache/commons/compress/compressors/gzip/Compress376Test.java
index 0494211..4398161 100644
--- a/src/test/java/org/apache/commons/compress/compressors/gzip/Compress376Test.java
+++ b/src/test/java/org/apache/commons/compress/compressors/gzip/Compress376Test.java
@@ -81,12 +81,7 @@ public class Compress376Test extends AbstractTestCase {
             try (OutputStream out = new FileOutputStream(new File(dir, entry.getName())))
{
                 IOUtils.copy(in, out);
             }
-            try {
-                in.getNextEntry();
-                Assert.fail("should report garbage");
-            } catch (IOException ex) {
-                Assert.assertEquals("Garbage after a valid .gz stream", ex.getMessage());
-            }
+            Assert.assertNull(in.getNextEntry());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/6a8f6c95/src/test/resources/COMPRESS-376.tar.gz
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-376.tar.gz b/src/test/resources/COMPRESS-376.tar.gz
index ff95293..f21af14 100644
Binary files a/src/test/resources/COMPRESS-376.tar.gz and b/src/test/resources/COMPRESS-376.tar.gz
differ


Mime
View raw message