Repository: commons-compress
Updated Branches:
  refs/heads/COMPRESS-376 [created] 71caa69e2


COMPRESS-376 passing testcase, seems to be too naive


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

Branch: refs/heads/COMPRESS-376
Commit: 71caa69e24c4351bbd3715263325054ea6d72479
Parents: 726ba6f
Author: Stefan Bodewig <bode...@apache.org>
Authored: Sun Dec 18 13:50:16 2016 +0100
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Sun Dec 18 13:50:16 2016 +0100

----------------------------------------------------------------------
 .../compressors/gzip/Compress376Test.java       |  93 +++++++++++++++++++
 src/test/resources/COMPRESS-376.tar.gz          | Bin 0 -> 2048 bytes
 2 files changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/71caa69e/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
new file mode 100644
index 0000000..0494211
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/compress/compressors/gzip/Compress376Test.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.compress.compressors.gzip;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.utils.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @see "https://issues.apache.org/jira/browse/COMPRESS-376";
+ */
+public class Compress376Test extends AbstractTestCase {
+
+    private interface StreamDecorator {
+        InputStream decorate(InputStream is) throws IOException;
+    }
+
+    @Test
+    public void testUnbuffered() throws Exception {
+        test(new StreamDecorator() {
+                @Override
+                public InputStream decorate(InputStream is) {
+                    return is;
+                }
+            });
+    }
+
+    @Test
+    public void testBuffered() throws Exception {
+        test(new StreamDecorator() {
+                @Override
+                public InputStream decorate(InputStream is) throws IOException 
{
+                    return new BufferedInputStream(is);
+                }
+            });
+    }
+
+    /*
+     * Really only asserts there is no error thrown. The archive
+     * contains two entries and garbage after the second one. We
+     * should be able to read both entries without an exception.
+     */
+    public void test(StreamDecorator decorator) throws Exception {
+        final File input = getFile("COMPRESS-376.tar.gz");
+        try (InputStream fis = new FileInputStream(input);
+             InputStream gis = new GzipCompressorInputStream(fis, true);
+             InputStream is = decorator.decorate(gis);
+             TarArchiveInputStream in = new TarArchiveInputStream(is)) {
+            TarArchiveEntry entry = (TarArchiveEntry) in.getNextEntry();
+            try (OutputStream out = new FileOutputStream(new File(dir, 
entry.getName()))) {
+                IOUtils.copy(in, out);
+            }
+            entry = (TarArchiveEntry) in.getNextEntry();
+            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());
+            }
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/71caa69e/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
new file mode 100644
index 0000000..ff95293
Binary files /dev/null and b/src/test/resources/COMPRESS-376.tar.gz differ

Reply via email to