[Carbon-dev] FindBugs hackathon on 23rd Sep 2010

Afkham Azeez azeez at wso2.com
Sun Sep 26 21:56:48 PDT 2010


Yes, if that is better, and if we don't have to introduce a dependency just
to do this. Can you post the relevant sample code segment?

Azeez



On Mon, Sep 27, 2010 at 10:23 AM, Ruchira Wageesha <ruchira at wso2.com> wrote:

> Hi,
>
> I also encountered the same error in mashup components. But, I used the
> commons-io for that. i.e.
>
> org.apache.commons.io.IOUtils.closeQuietly(fileWriter);
>
> where try-catch within the following final block has been wrapped within
> IOUtils class. I decided to use above method as it gives us a more readable
> code. I guess it is all right to use commons-io??
>
> regards,
> Ruchira
>
>
>
>> public void archiveFile(String from, String to) throws IOException {
>>         ZipOutputStream out = null;
>>         FileInputStream in = new FileInputStream(from);
>>         try {
>>             out = new ZipOutputStream(new FileOutputStream(to));
>>             byte[] buffer = new byte[40960];
>>             int bytesRead;
>>             while ((bytesRead = in.read(buffer)) != -1) {
>>                 out.write(buffer, 0, bytesRead);
>>             }
>>         } finally {
>>             try {
>>                 in.close();
>>             } catch (IOException e) {
>>                 log.warn("Unable to close the InputStream " +
>> e.getMessage(), e);
>>             }
>>
>>             try {
>>                 if (out != null) {
>>                     out.close();
>>                 }
>>             } catch (IOException e) {
>>                 log.warn("Unable to close the OutputStream " +
>> e.getMessage(), e);
>>             }
>>         }
>>     }
>>
>> IMV, we need to close streams in the above manner, otherwise output stream
>> won't get closed, if an error occurs while closing the input stream.
>>
>> Thanks
>> Sameera
>>
>
>
> _______________________________________________
> Carbon-dev mailing list
> Carbon-dev at wso2.org
> https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
>
>


-- 
*Afkham Azeez*
Senior Software Architect & Senior Manager; WSO2, Inc.; http://wso2.com,
*
*
*Member; Apache Software Foundation;
**http://www.apache.org/*<http://www.apache.org/>
*
email: **azeez at wso2.com* <azeez at wso2.com>* cell: +94 77 3320919
blog: **http://blog.afkham.org* <http://blog.afkham.org>*
twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez>
*
linked-in: **http://lk.linkedin.com/in/afkhamazeez*
*
*
*Lean . Enterprise . Middleware*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.wso2.org/pipermail/carbon-dev/attachments/20100927/0e6c73b5/attachment.htm 


More information about the Carbon-dev mailing list