commons-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=918028&view=rev
Log:
ensure streams get closed

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=918028&r1=918027&r2=918028&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:29:12 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.commons.compress.compressors;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -33,21 +35,38 @@
         final File input = getFile("test1.xml");
         final File output = new File(dir, "test1.xml.gz");
         final OutputStream out = new FileOutputStream(output);
-        final CompressorOutputStream cos = new CompressorStreamFactory().createCompressorOutputStream("gz",
out);
-        IOUtils.copy(new FileInputStream(input), cos);
-        cos.close();
+        try {
+            final CompressorOutputStream cos = new CompressorStreamFactory()
+                .createCompressorOutputStream("gz", out);
+            try {
+                IOUtils.copy(new FileInputStream(input), cos);
+            } finally {
+                cos.close();
+            }
+        } finally {
+            out.close();
+        }
     }
 
     public void testGzipUnarchive() throws Exception {
         final File input = getFile("bla.tgz");
         final File output = new File(dir, "bla.tar");
         final InputStream is = new FileInputStream(input);
-        final CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream("gz",
is);
-        FileOutputStream out = new FileOutputStream(output);
-        IOUtils.copy(in, out);
-        in.close();
-        is.close();
-        out.close();
+        try {
+            final CompressorInputStream in = new CompressorStreamFactory()
+                .createCompressorInputStream("gz", is);
+            FileOutputStream out = null;
+            try {
+                out = new FileOutputStream(output);
+                IOUtils.copy(in, out);
+            } finally {
+                if (out != null) {
+                    out.close();
+                }
+                in.close();
+            }
+        } finally {
+            is.close();
+        }
     }
-
 }



Mime
View raw message