commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r670235 - in /commons/sandbox/compress/trunk: pom.xml src/test/org/apache/commons/compress/archivers/tar/TarTestCase.java src/test/org/apache/commons/compress/compressors/bzip2/BzipTestCase.java
Date Sat, 21 Jun 2008 17:31:49 GMT
Author: ebourg
Date: Sat Jun 21 10:31:49 2008
New Revision: 670235

URL: http://svn.apache.org/viewvc?rev=670235&view=rev
Log:
Replaced the shutdownStream() methods with IOUtils.closeQuietly() in the test cases

Modified:
    commons/sandbox/compress/trunk/pom.xml
    commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/archivers/tar/TarTestCase.java
    commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/compressors/bzip2/BzipTestCase.java

Modified: commons/sandbox/compress/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/pom.xml?rev=670235&r1=670234&r2=670235&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/pom.xml (original)
+++ commons/sandbox/compress/trunk/pom.xml Sat Jun 21 10:31:49 2008
@@ -20,6 +20,12 @@
       <version>3.8.1</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.4</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <developers>

Modified: commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/archivers/tar/TarTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/archivers/tar/TarTestCase.java?rev=670235&r1=670234&r2=670235&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/archivers/tar/TarTestCase.java
(original)
+++ commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/archivers/tar/TarTestCase.java
Sat Jun 21 10:31:49 2008
@@ -25,7 +25,8 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
 
 import junit.framework.TestCase;
 
@@ -92,9 +93,9 @@
         final FileInputStream fileInput = new FileInputStream( DATA_FILE1 );
         output.copyEntryContents( fileInput );
         output.closeEntry();
-        shutdownStream( fileInput );
-        shutdownStream( output );
-        shutdownStream( fileOutput );
+        IOUtils.closeQuietly( fileInput );
+        IOUtils.closeQuietly( output );
+        IOUtils.closeQuietly( fileOutput );
 
         assertTrue( "Tar files Equal", contentEquals( temp, POSIX_TAR_FILE ) );
         temp.delete();
@@ -115,9 +116,9 @@
         final FileInputStream fileInput = new FileInputStream( DATA_FILE1 );
         output.copyEntryContents( fileInput );
         output.closeEntry();
-        shutdownStream( fileInput );
-        shutdownStream( output );
-        shutdownStream( fileOutput );
+        IOUtils.closeQuietly( fileInput );
+        IOUtils.closeQuietly( output );
+        IOUtils.closeQuietly( fileOutput );
 
         //Have to compare it this way as the contents will differ
         //due to entry created for second part of name
@@ -169,11 +170,11 @@
         final File temp = new File( BASEDIR_FILE, entryName.length() + "data.txt" );//File.createTempFile(
"delete-me", "tar" );
         final FileOutputStream output = new FileOutputStream( temp );
         input.copyEntryContents( output );
-        shutdownStream( output );
+        IOUtils.closeQuietly( output );
 
         assertNull( "Next Entry", input.getNextEntry() );
 
-        shutdownStream( input );
+        IOUtils.closeQuietly( input );
 
         assertTrue( "Data Equals", contentEquals( temp, DATA_FILE1 ) );
         temp.delete();
@@ -218,8 +219,8 @@
         }
         finally
         {
-            shutdownStream( input1 );
-            shutdownStream( input2 );
+            IOUtils.closeQuietly( input1 );
+            IOUtils.closeQuietly( input2 );
         }
     }
 
@@ -263,36 +264,4 @@
             return true;
         }
     }
-
-    private void shutdownStream( final InputStream input )
-    {
-        if( null == input )
-        {
-            return;
-        }
-
-        try
-        {
-            input.close();
-        }
-        catch( final IOException ioe )
-        {
-        }
-    }
-
-    private void shutdownStream( final OutputStream output )
-    {
-        if( null == output )
-        {
-            return;
-        }
-
-        try
-        {
-            output.close();
-        }
-        catch( final IOException ioe )
-        {
-        }
-    }
 }

Modified: commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/compressors/bzip2/BzipTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/compressors/bzip2/BzipTestCase.java?rev=670235&r1=670234&r2=670235&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/compressors/bzip2/BzipTestCase.java
(original)
+++ commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/compressors/bzip2/BzipTestCase.java
Sat Jun 21 10:31:49 2008
@@ -28,6 +28,7 @@
 import java.io.OutputStream;
 
 import org.apache.commons.compress.CompressUtils;
+import org.apache.commons.io.IOUtils;
 
 import junit.framework.TestCase;
 
@@ -50,9 +51,9 @@
         final OutputStream output = new FileOutputStream( outputFile );
         final BZip2OutputStream packedOutput = getPackedOutput( output );
         CompressUtils.copy( input, packedOutput );
-        shutdownStream( input );
-        shutdownStream( packedOutput );
-        shutdownStream( output );
+        IOUtils.closeQuietly( input );
+        IOUtils.closeQuietly( packedOutput );
+        IOUtils.closeQuietly( output );
         compareContents( "asf-logo-huge.tar.bz2", outputFile );
         forceDelete( outputFile );
     }
@@ -74,9 +75,9 @@
         final OutputStream output = new FileOutputStream( outputFile );
         final BZip2InputStream packedInput = getPackedInput( input );
         CompressUtils.copy( packedInput, output );
-        shutdownStream( input );
-        shutdownStream( packedInput );
-        shutdownStream( output );
+        IOUtils.closeQuietly( input );
+        IOUtils.closeQuietly( packedInput );
+        IOUtils.closeQuietly( output );
         compareContents( "asf-logo-huge.tar", outputFile );
         forceDelete( outputFile );
     }
@@ -88,12 +89,12 @@
         final File outputFile = getOutputFile( ".tar.bz2" );
         final OutputStream output = new FileOutputStream( outputFile );
         CompressUtils.copy( input, output );
-        shutdownStream( input );
-        shutdownStream( output );
+        IOUtils.closeQuietly( input );
+        IOUtils.closeQuietly( output );
         assertTrue( "Check output file exists." , outputFile.exists() );
         final InputStream input2 = new FileInputStream( outputFile );
         final InputStream packedInput = getPackedInput( input2 );
-        shutdownStream( packedInput );
+        IOUtils.closeQuietly( packedInput );
         try
         {
             input2.read();
@@ -126,8 +127,8 @@
         final InputStream input1 = getInputStream( initial );
         final InputStream input2 = new FileInputStream( generated );
         final boolean test = contentEquals( input1, input2 );
-        shutdownStream( input1 );
-        shutdownStream( input2 );
+        IOUtils.closeQuietly( input1 );
+        IOUtils.closeQuietly( input2 );
         assertTrue( "Contents of " + initial + " matches generated version " + generated,
test );
     }
 
@@ -216,46 +217,4 @@
             return filepath.substring( 0, index );
         }
     }
-
-    /**
-     * Unconditionally close an <code>OutputStream</code>.
-     * Equivalent to {@link java.io.OutputStream#close()}, except any exceptions will be
ignored.
-     * @param output A (possibly null) OutputStream
-     */
-    private static void shutdownStream( final OutputStream output )
-    {
-        if( null == output )
-        {
-            return;
-        }
-
-        try
-        {
-            output.close();
-        }
-        catch( final IOException ioe )
-        {
-        }
-    }
-
-    /**
-     * Unconditionally close an <code>InputStream</code>.
-     * Equivalent to {@link InputStream#close()}, except any exceptions will be ignored.
-     * @param input A (possibly null) InputStream
-     */
-    private static void shutdownStream( final InputStream input )
-    {
-        if( null == input )
-        {
-            return;
-        }
-
-        try
-        {
-            input.close();
-        }
-        catch( final IOException ioe )
-        {
-        }
-    }
 }



Mime
View raw message