Package org.apache.jackrabbit.core.data
Class LazyFileInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.commons.io.input.ProxyInputStream
-
- org.apache.commons.io.input.AutoCloseInputStream
-
- org.apache.jackrabbit.core.data.LazyFileInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class LazyFileInputStream extends org.apache.commons.io.input.AutoCloseInputStreamThis input stream delays opening the file 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 FileDescriptorfdThe file descriptor to use.protected FilefileThe file to read from.protected booleanopenedTrue if the input stream was opened.-
Fields inherited from class java.io.FilterInputStream
in
-
-
Constructor Summary
Constructors Constructor Description LazyFileInputStream(File file)Creates a newLazyFileInputStreamfor the given file.LazyFileInputStream(FileDescriptor fd)Creates a newLazyFileInputStreamfor the given file descriptor.LazyFileInputStream(String name)Creates a newLazyFileInputStreamfor the given file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()voidmark(int readlimit)booleanmarkSupported()protected voidopen()Open the stream if required.intread()intread(byte[] b)intread(byte[] b, int off, int len)voidreset()longskip(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
-
fd
protected final FileDescriptor fd
The file descriptor to use.
-
file
protected final File file
The file 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 after the stream was closed).
-
-
Constructor Detail
-
LazyFileInputStream
public LazyFileInputStream(File file) throws FileNotFoundException
Creates a newLazyFileInputStreamfor the given file. If the file is unreadable, a FileNotFoundException is thrown. The file is not opened until the first byte is read from the stream.- Parameters:
file- the file- Throws:
FileNotFoundException
-
LazyFileInputStream
public LazyFileInputStream(FileDescriptor fd)
Creates a newLazyFileInputStreamfor the given file descriptor. The file is not opened until the first byte is read from the stream.- Parameters:
fd-
-
LazyFileInputStream
public LazyFileInputStream(String name) throws FileNotFoundException
Creates a newLazyFileInputStreamfor the given file. If the file is unreadable, a FileNotFoundException is thrown.- Parameters:
name-- Throws:
FileNotFoundException
-
-
Method Detail
-
open
protected void open() throws IOExceptionOpen the stream if required.- Throws:
IOException
-
read
public int read() throws IOException- Overrides:
readin classorg.apache.commons.io.input.ProxyInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classorg.apache.commons.io.input.ProxyInputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classorg.apache.commons.io.input.AutoCloseInputStream- Throws:
IOException
-
reset
public void reset() throws IOException- Overrides:
resetin classorg.apache.commons.io.input.ProxyInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classorg.apache.commons.io.input.ProxyInputStream
-
mark
public void mark(int readlimit)
- Overrides:
markin classorg.apache.commons.io.input.ProxyInputStream
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classorg.apache.commons.io.input.ProxyInputStream- Throws:
IOException
-
read
public int read(byte[] b) throws IOException- Overrides:
readin classorg.apache.commons.io.input.ProxyInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classorg.apache.commons.io.input.ProxyInputStream- Throws:
IOException
-
-