Author: imario
Date: Sun Sep 11 07:01:25 2005
New Revision: 280140

URL: http://svn.apache.org/viewcvs?rev=280140&view=rev
Log:
PR: 36597
Submitted by: Hiroki Ata <hiroki.ata -at- mail.com>

underlaying inputStream wasnt correctly closed.

Thanks for the patch!


Modified:
    
jakarta/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/bzip2/CBZip2InputStream.java
    
jakarta/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/bzip2/test/BzipTestCase.java

Modified: 
jakarta/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/bzip2/CBZip2InputStream.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/bzip2/CBZip2InputStream.java?rev=280140&r1=280139&r2=280140&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/bzip2/CBZip2InputStream.java
 (original)
+++ 
jakarta/commons/sandbox/compress/trunk/src/java/org/apache/commons/compress/bzip2/CBZip2InputStream.java
 Sun Sep 11 07:01:25 2005
@@ -624,6 +624,16 @@
 
     private void bsFinishedWithStream()
     {
+        if (m_input != null)
+        {
+            try
+            {
+                m_input.close();
+            }
+            catch ( IOException e )
+            {
+            }
+        }
         m_input = null;
     }
 
@@ -967,6 +977,6 @@
     
     public void close() throws IOException 
     {
-        m_input.close();
+       bsFinishedWithStream();
     }
 }

Modified: 
jakarta/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/bzip2/test/BzipTestCase.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/bzip2/test/BzipTestCase.java?rev=280140&r1=280139&r2=280140&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/bzip2/test/BzipTestCase.java
 (original)
+++ 
jakarta/commons/sandbox/compress/trunk/src/test/org/apache/commons/compress/bzip2/test/BzipTestCase.java
 Sun Sep 11 07:01:25 2005
@@ -83,6 +83,30 @@
         forceDelete( outputFile );
     }
 
+    public void testCBZip2InputStreamClose()
+        throws Exception
+    {
+        final InputStream input = getInputStream( "asf-logo-huge.tar.bz2" );
+        final File outputFile = getOutputFile( ".tar.bz2" );
+        final OutputStream output = new FileOutputStream( outputFile );
+        copy( input, output );
+        shutdownStream( input );
+        shutdownStream( output );
+        assertTrue( "Check output file exists." , outputFile.exists() );
+        final InputStream input2 = new FileInputStream( outputFile );
+        final InputStream packedInput = getPackedInput( input2 );
+        shutdownStream( packedInput );
+        try
+        {
+            input2.read();
+            assertTrue("Source input stream is still opened.", false);
+        } catch ( Exception e )
+        {
+            // Read closed stream.
+        }
+        forceDelete( outputFile );
+    }
+
     /**
      * Copy bytes from an <code>InputStream</code> to an 
<code>OutputStream</code>.
      */



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to