commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: [fileupload] file stream leaks?
Date Thu, 06 Feb 2014 15:03:23 GMT
On Thu, Feb 6, 2014 at 9:04 AM, sebb <sebbaz@gmail.com> wrote:

> On 6 February 2014 13:53, Gary Gregory <garydgregory@gmail.com> wrote:
> > Looking at code like DiskFileItem:684:
> >
> >             FileInputStream input = new FileInputStream(dfosFile);
> >             IOUtils.copy(input, output);
> >
> > Why is this not:
> >
> >             FileInputStream input = new FileInputStream(dfosFile);
> >             try {
> >                 IOUtils.copy(input, output);
> >             } finally {
> >                 input.close();
> >             }
> >
> > ?
>
> Oversight?
>
The local Streams.copy() methods do close input and optionally output.
> Maybe it was thought IO did the same?
>

I can imagine some confusion about having both the util Streams class AND
IOUtils around.

I would change Stream impl to call IOUtils. Since we already depend on
[io], we might as well use it.

Gary


> The close should perhaps be
>
> IOUtils.closeQuietly()
>
> Are we interested in knowibg about input close() failures?
>
> > Gary
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition<
> http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message