commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r918032 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
Date Tue, 02 Mar 2010 13:40:31 GMT
Author: bodewig
Date: Tue Mar  2 13:40:31 2010
New Revision: 918032

URL: http://svn.apache.org/viewvc?rev=918032&view=rev
Log:
testcase for COMPRESS-84

Modified:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java?rev=918032&r1=918031&r2=918032&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GZipTestCase.java
Tue Mar  2 13:40:31 2010
@@ -23,6 +23,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
@@ -69,4 +70,44 @@
             is.close();
         }
     }
+
+    /**
+     * @see https://issues.apache.org/jira/browse/COMPRESS-84
+     */
+    public void testCorruptedInput() throws Exception {
+        InputStream in = null;
+        OutputStream out = null;
+        CompressorInputStream cin = null;
+        try {
+            in = new FileInputStream(getFile("bla.tgz"));
+            out = new ByteArrayOutputStream();
+            IOUtils.copy(in, out);
+            in.close();
+            out.close();
+
+            byte[] data = ((ByteArrayOutputStream) out).toByteArray();
+            in = new ByteArrayInputStream(data, 0, data.length - 1);
+            cin = new CompressorStreamFactory()
+                .createCompressorInputStream("gz", in);
+            out = new ByteArrayOutputStream();
+
+            try {
+                IOUtils.copy(cin, out);
+                fail("Expected an exception");
+            } catch (IOException ioex) {
+                // the whole point of the test
+            }
+
+        } finally {
+            if (out != null) {
+                out.close();
+            }
+            if (cin != null) {
+                in.close();
+            }
+            if (in != null) {
+                in.close();
+            }
+        }
+    }
 }



Mime
View raw message