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 <[email protected]> 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 > [email protected] > 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: **[email protected]* <[email protected]>* 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*
_______________________________________________ Carbon-dev mailing list [email protected] https://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
