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
This 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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.io.input.AutoCloseInputStream
AutoCloseInputStream.Builder -
Constructor Summary
ConstructorsConstructorDescriptionLazyFileInputStream(File file) Creates a newLazyFileInputStreamfor the given file.Creates a newLazyFileInputStreamfor the given file descriptor.LazyFileInputStream(String name) Creates a newLazyFileInputStreamfor the given file. -
Method Summary
Modifier and TypeMethodDescriptionintInvokes the delegate'sInputStream.available()method.voidclose()Closes the underlying input stream and replaces the reference to it with aClosedInputStreaminstance.voidmark(int readlimit) Invokes the delegate'sInputStream.mark(int)method.booleanInvokes the delegate'sInputStream.markSupported()method.intread()Invokes the delegate'sInputStream.read()method unless the stream is closed.intread(byte[] b) Invokes the delegate'sInputStream.read(byte[])method.intread(byte[] b, int off, int len) Invokes the delegate'sInputStream.read(byte[], int, int)method.voidreset()Invokes the delegate'sInputStream.reset()method.longskip(long n) Invokes the delegate'sInputStream.skip(long)method.Methods inherited from class org.apache.commons.io.input.AutoCloseInputStream
builderMethods inherited from class org.apache.commons.io.input.ProxyInputStream
setReference, unwrapMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
LazyFileInputStream
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
Creates a newLazyFileInputStreamfor the given file descriptor. The file is not opened until the first byte is read from the stream.- Parameters:
fd-
-
LazyFileInputStream
Creates a newLazyFileInputStreamfor the given file. If the file is unreadable, a FileNotFoundException is thrown.- Parameters:
name-- Throws:
FileNotFoundException
-
-
Method Details
-
read
Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.read()method unless the stream is closed.- Overrides:
readin classProxyInputStream- Returns:
- the byte read or
EOFif we reached the end of stream. - Throws:
IOException- if an I/O error occurs.
-
available
Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.available()method.- Overrides:
availablein classProxyInputStream- Returns:
- the number of available bytes, 0 if the stream is closed.
- Throws:
IOException- if an I/O error occurs.
-
close
Description copied from class:AutoCloseInputStreamCloses the underlying input stream and replaces the reference to it with aClosedInputStreaminstance.This method is automatically called by the read methods when the end of input has been reached.
Note that it is safe to call this method any number of times. The original underlying input stream is closed and discarded only once when this method is first called.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classAutoCloseInputStream- Throws:
IOException- if the underlying input stream cannot be closed
-
reset
Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.reset()method.- Overrides:
resetin classProxyInputStream- Throws:
IOException- if this stream has not been marked or if the mark has been invalidated.
-
markSupported
public boolean markSupported()Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.markSupported()method.- Overrides:
markSupportedin classProxyInputStream- Returns:
trueif this stream instance supports the mark and reset methods;falseotherwise.- See Also:
-
mark
public void mark(int readlimit) Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.mark(int)method.- Overrides:
markin classProxyInputStream- Parameters:
readlimit- read ahead limit.
-
skip
Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.skip(long)method.- Overrides:
skipin classProxyInputStream- Parameters:
n- the number of bytes to skip.- Returns:
- the actual number of bytes skipped.
- Throws:
IOException- if the stream does not support seek, or if some other I/O error occurs.
-
read
Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.read(byte[])method.- Overrides:
readin classProxyInputStream- Parameters:
b- the buffer to read the bytes into.- Returns:
- the number of bytes read or
EOFif we reached the end of stream. - Throws:
IOException-- If the first byte cannot be read for any reason other than the end of the file,
- if the input stream has been closed, or
- if some other I/O error occurs.
-
read
Description copied from class:ProxyInputStreamInvokes the delegate'sInputStream.read(byte[], int, int)method.- Overrides:
readin classProxyInputStream- Parameters:
b- the buffer to read the bytes into.off- The start offset.len- The number of bytes to read.- Returns:
- the number of bytes read or
EOFif we reached the end of stream. - Throws:
IOException-- If the first byte cannot be read for any reason other than the end of the file,
- if the input stream has been closed, or
- if some other I/O error occurs.
-