commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "B. K. Oxley (binkley)" <bink...@alumni.rice.edu>
Subject Re: [io] copyAndClose
Date Sun, 06 Feb 2005 15:12:16 GMT
Stephen Colebourne wrote:
>> public static void copyAndClose(final InputStream in,
>>         final OutputStream out)
>>         throws IOException {
>>     try {
>>         CopyUtils.copy(in, out);
>>         out.flush();
>>
>>     } finally {
> 
>           IOUtils.copyAndClose(in);
>           IOUtils.copyAndClose(out);
> 
>>     }
>> }

I do not understand.  What is being copied in the finally block?  Should 
that have been:

     finally {
         IOUtils.closeQuietly(in);
         IOUtils.closeQuietly(out);
     }

I do not want to swallow exceptions thrown by closing in or out as they 
might indicate to the caller some kind of important failure (say a 
network error).  That is why my original has nexted try/finally blocks:

     finally {
         try {
             out.close();
         } finally {
             in.close();
         }
     }

> Even so, this is quite a good suggestion. The main downside is that it 
> doubles the number of methods. (CopyUtils is being deprecated, with the 
> methods moving to IOUtils with better semantics and names to simplify 
> the overall API)
> 
> Were you interested in writing the patch and tests for IOUtils?

Do I just pull IO from SVN?  What form of patch: unified diff ok?


Cheers,
--binkley

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message