[
https://issues.apache.org/jira/browse/IO-393?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
BELUGA BEHR updated IO-393:
---------------------------
Description:
I have included, with this ticket, an implementation of a FileBasedInputStream.
It can be used as a generic wrapper for a FileInputStream and
ByteArrayInputStream. I use it with Spring-Batch as a way to allow an "Item
Reader" to load files into memory or leave it on disk.
{code}
public static FileBasedInputStream getFileBasedInputStream(File file)
{
InputStream is = null;
DeferredFileOutputStream dfos = new DeferredFileOutputStream(1024, file);
InputStream is = null;
IoUtils.copy(in, dfos);
if (dfos.ifIsInMemory())
{
is = new ByteInputStream(dfos.getData());
}
else
{
is = new DeferredFileInputStream(dfos.getFile());
}
IoUtils.closeQuietly(dfos);
return new FileBasedInputStream(file, is);
}
void test1(OutputStream os)
{
FileBasedInputStream fbis = getFileBasedInputStream(new
File("/usr/local/test.txt"));
IoUtils.copy(fbis, os);
fbis.close();
fbis.getFile.delete();
}
void test2(OutputStream os)
{
FileBasedInputStream fbis = getFileBasedInputStream(new
File("/usr/local/test.txt"));
for (int i = 0; i < 10; i++)
{
IoUtils.copy(fbis, os);
fbis.reset();
}
fbis.close();
fbis.getFile.delete();
{code}
was:I have included, with this ticket, an implementation of a
FileBasedInputStream. It can be used as a generic wrapper for a
FileInputStream and ByteArrayInputStream. I use it with Spring-Batch as a way
to allow an "Item Reader" to load files into memory or leave it on disk.
> [IO] FileBasedInputStream
> -------------------------
>
> Key: IO-393
> URL: https://issues.apache.org/jira/browse/IO-393
> Project: Commons IO
> Issue Type: New Feature
> Components: Streams/Writers
> Reporter: BELUGA BEHR
> Priority: Minor
> Attachments: FileBackedInputStream.java
>
>
> I have included, with this ticket, an implementation of a
> FileBasedInputStream. It can be used as a generic wrapper for a
> FileInputStream and ByteArrayInputStream. I use it with Spring-Batch as a
> way to allow an "Item Reader" to load files into memory or leave it on disk.
> {code}
> public static FileBasedInputStream getFileBasedInputStream(File file)
> {
> InputStream is = null;
> DeferredFileOutputStream dfos = new DeferredFileOutputStream(1024, file);
> InputStream is = null;
> IoUtils.copy(in, dfos);
> if (dfos.ifIsInMemory())
> {
> is = new ByteInputStream(dfos.getData());
> }
> else
> {
> is = new DeferredFileInputStream(dfos.getFile());
> }
> IoUtils.closeQuietly(dfos);
> return new FileBasedInputStream(file, is);
> }
> void test1(OutputStream os)
> {
> FileBasedInputStream fbis = getFileBasedInputStream(new
> File("/usr/local/test.txt"));
> IoUtils.copy(fbis, os);
> fbis.close();
> fbis.getFile.delete();
> }
> void test2(OutputStream os)
> {
> FileBasedInputStream fbis = getFileBasedInputStream(new
> File("/usr/local/test.txt"));
> for (int i = 0; i < 10; i++)
> {
> IoUtils.copy(fbis, os);
> fbis.reset();
> }
> fbis.close();
> fbis.getFile.delete();
> {code}
--
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