Package org.apache.jackrabbit.vfs.ext.ds
Class LazyFileContentInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.commons.io.input.ProxyInputStream
-
- org.apache.commons.io.input.AutoCloseInputStream
-
- org.apache.jackrabbit.vfs.ext.ds.LazyFileContentInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class LazyFileContentInputStream extends org.apache.commons.io.input.AutoCloseInputStream
This input stream delays opening the file content until the first byte is read, and closes and discards the underlying stream as soon as the end of input has been reached or when the stream is explicitly closed.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.vfs2.FileObject
fileObject
The file object to read from.protected boolean
opened
True if the input stream was opened.-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description LazyFileContentInputStream(org.apache.commons.vfs2.FileObject fileObject)
Creates a newLazyFileInputStream
for the given file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
void
mark(int readlimit)
boolean
markSupported()
protected void
open()
Open the stream if required.int
read()
int
read(byte[] b)
int
read(byte[] b, int off, int len)
void
reset()
long
skip(long n)
-
Methods inherited from class org.apache.commons.io.input.AutoCloseInputStream
afterRead, builder, finalize
-
Methods inherited from class org.apache.commons.io.input.ProxyInputStream
beforeRead, handleIOException, unwrap
-
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Field Detail
-
fileObject
protected final org.apache.commons.vfs2.FileObject fileObject
The file object to read from.
-
opened
protected boolean opened
True if the input stream was opened. It is also set to true if the stream was closed without reading (to avoid opening the file content after the stream was closed).
-
-
Constructor Detail
-
LazyFileContentInputStream
public LazyFileContentInputStream(org.apache.commons.vfs2.FileObject fileObject) throws org.apache.commons.vfs2.FileSystemException
Creates a newLazyFileInputStream
for the given file. If the file is unreadable, a FileSystemException is thrown. The file is not opened until the first byte is read from the stream.- Parameters:
fileObject
- the file- Throws:
org.apache.commons.vfs2.FileNotFoundException
org.apache.commons.vfs2.FileSystemException
-
-
Method Detail
-
open
protected void open() throws IOException
Open the stream if required.- Throws:
IOException
-
read
public int read() throws IOException
- Overrides:
read
in classorg.apache.commons.io.input.ProxyInputStream
- Throws:
IOException
-
available
public int available() throws IOException
- Overrides:
available
in classorg.apache.commons.io.input.ProxyInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classorg.apache.commons.io.input.AutoCloseInputStream
- Throws:
IOException
-
reset
public void reset() throws IOException
- Overrides:
reset
in classorg.apache.commons.io.input.ProxyInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classorg.apache.commons.io.input.ProxyInputStream
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classorg.apache.commons.io.input.ProxyInputStream
-
skip
public long skip(long n) throws IOException
- Overrides:
skip
in classorg.apache.commons.io.input.ProxyInputStream
- Throws:
IOException
-
read
public int read(byte[] b) throws IOException
- Overrides:
read
in classorg.apache.commons.io.input.ProxyInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classorg.apache.commons.io.input.ProxyInputStream
- Throws:
IOException
-
-