commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (IO-391) DeferredFileInputStream
Date Sat, 20 Jul 2013 02:40:48 GMT

    [ https://issues.apache.org/jira/browse/IO-391?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13714306#comment-13714306
] 

Gary Gregory commented on IO-391:
---------------------------------

Hi Beluga,

Thank you for your contribution. Can you provide unit tests please?

Gary
                
> DeferredFileInputStream
> -----------------------
>
>                 Key: IO-391
>                 URL: https://issues.apache.org/jira/browse/IO-391
>             Project: Commons IO
>          Issue Type: Wish
>          Components: Streams/Writers
>            Reporter: BELUGA BEHR
>            Priority: Minor
>         Attachments: DeferredFileInputStream.java
>
>
> I have included an implementation of a "DeferredFileInputStream".  It wraps a Java Util
FileInputStream, but it opens a file handle when it's absolutely required.  This goes well
with DeferredFileOutputStream.  What I like to do is...
> {code}
> InputStream is = null;
> DeferredFileOutputStream dfos = new DeferredFileOutputStream(1024, file);
> // InputStream opened earlier
> IoUtils.copy(in, dfos);
> if (dfos.ifIsInMemory())
> {
>     is = new ByteInputStream(dfos.getData());
> }
> else
> {
>     is = new DeferredFileInputStream(dfos.getFile());
> }
> IoUtils.closeQuietly(dfos);
> return is;
> {code}
> That way, I can generate a large list of InputStreams (for a a batch job as an example)
and queue them up for different threads to take without creating lots of file handles.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message