commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r758656 - /commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
Date Thu, 26 Mar 2009 14:17:51 GMT
Author: bodewig
Date: Thu Mar 26 14:17:43 2009
New Revision: 758656

URL: http://svn.apache.org/viewvc?rev=758656&view=rev
Log:
free resources in tests more aggressivly

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

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java?rev=758656&r1=758655&r2=758656&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/AbstractTestCase.java
Thu Mar 26 14:17:43 2009
@@ -51,6 +51,12 @@
     }
 
     protected void tearDown() throws Exception {
+        String[] f = dir.list();
+        if (f != null) {
+            for (int i = 0; i < f.length; i++) {
+                new File(dir, f[i]).delete();
+            }
+        }
         dir.delete();
         dir = null;
     }
@@ -79,10 +85,11 @@
      */
     protected File createArchive(String archivename) throws Exception {
         ArchiveOutputStream out = null;
+        OutputStream stream = null;
         try {
             File temp = File.createTempFile("test", "." + archivename);
 
-            final OutputStream stream = new FileOutputStream(temp);
+            stream = new FileOutputStream(temp);
             out = new ArchiveStreamFactory().createArchiveOutputStream(
                     archivename, stream);
 
@@ -149,8 +156,11 @@
 
             return temp;
         } finally {
-            if (out != null)
+            if (out != null) {
                 out.close();
+            } else if (stream != null) {
+                stream.close();
+            }
         }
     }
 
@@ -166,10 +176,14 @@
     protected void checkArchiveContent(File archive, List expected)
             throws Exception {
         final InputStream is = new FileInputStream(archive);
-        final BufferedInputStream buf = new BufferedInputStream(is);
-        final ArchiveInputStream in = new ArchiveStreamFactory()
+        try {
+            final BufferedInputStream buf = new BufferedInputStream(is);
+            final ArchiveInputStream in = new ArchiveStreamFactory()
                 .createArchiveInputStream(buf);
-        this.checkArchiveContent(in, expected);
+            this.checkArchiveContent(in, expected);
+        } finally {
+            is.close();
+        }
     }
 
     protected void checkArchiveContent(ArchiveInputStream in, List expected)
@@ -184,8 +198,11 @@
                     + entry.getName());
             outfile.getParentFile().mkdirs();
             OutputStream out = new FileOutputStream(outfile);
-            IOUtils.copy(in, out);
-            out.close();
+            try {
+                IOUtils.copy(in, out);
+            } finally {
+                out.close();
+            }
 
             if (!outfile.exists()) {
                 fail("extraction failed: " + entry.getName());



Mime
View raw message