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:
java.io.Closeable,java.lang.AutoCloseable
public class LazyFileInputStream extends AutoCloseInputStream
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
Constructors Constructor Description LazyFileInputStream(java.io.File file)Creates a newLazyFileInputStreamfor the given file.LazyFileInputStream(java.io.FileDescriptor fd)Creates a newLazyFileInputStreamfor the given file descriptor.LazyFileInputStream(java.lang.String name)Creates a newLazyFileInputStreamfor the given file.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Invokes the delegate'savailable()method.voidclose()Closes the underlying input stream and replaces the reference to it with aClosedInputStreaminstance.voidmark(int readlimit)Invokes the delegate'smark(int)method.booleanmarkSupported()Invokes the delegate'smarkSupported()method.intread()Invokes the delegate'sread()method.intread(byte[] b)Invokes the delegate'sread(byte[])method.intread(byte[] b, int off, int len)Invokes the delegate'sread(byte[], int, int)method.voidreset()Invokes the delegate'sreset()method.longskip(long n)Invokes the delegate'sskip(long)method.-
Methods inherited from class org.apache.commons.io.input.AutoCloseInputStream
builder
-
Methods inherited from class org.apache.commons.io.input.ProxyInputStream
unwrap
-
-
-
-
Constructor Detail
-
LazyFileInputStream
public LazyFileInputStream(java.io.File file) throws java.io.FileNotFoundExceptionCreates 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:
java.io.FileNotFoundException
-
LazyFileInputStream
public LazyFileInputStream(java.io.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(java.lang.String name) throws java.io.FileNotFoundExceptionCreates a newLazyFileInputStreamfor the given file. If the file is unreadable, a FileNotFoundException is thrown.- Parameters:
name-- Throws:
java.io.FileNotFoundException
-
-
Method Detail
-
read
public int read() throws java.io.IOExceptionDescription copied from class:ProxyInputStreamInvokes the delegate'sread()method.- Overrides:
readin classProxyInputStream- Returns:
- the byte read or -1 if the end of stream
- Throws:
java.io.IOException- if an I/O error occurs.
-
available
public int available() throws java.io.IOExceptionDescription copied from class:ProxyInputStreamInvokes the delegate'savailable()method.- Overrides:
availablein classProxyInputStream- Returns:
- the number of available bytes
- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOExceptionDescription 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 interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classAutoCloseInputStream- Throws:
java.io.IOException- if the underlying input stream can not be closed
-
reset
public void reset() throws java.io.IOExceptionDescription copied from class:ProxyInputStreamInvokes the delegate'sreset()method.- Overrides:
resetin classProxyInputStream- Throws:
java.io.IOException- if an I/O error occurs.
-
markSupported
public boolean markSupported()
Description copied from class:ProxyInputStreamInvokes the delegate'smarkSupported()method.- Overrides:
markSupportedin classProxyInputStream- Returns:
- true if mark is supported, otherwise false
-
mark
public void mark(int readlimit)
Description copied from class:ProxyInputStreamInvokes the delegate'smark(int)method.- Overrides:
markin classProxyInputStream- Parameters:
readlimit- read ahead limit
-
skip
public long skip(long n) throws java.io.IOExceptionDescription copied from class:ProxyInputStreamInvokes the delegate'sskip(long)method.- Overrides:
skipin classProxyInputStream- Parameters:
n- the number of bytes to skip- Returns:
- the actual number of bytes skipped
- Throws:
java.io.IOException- if an I/O error occurs.
-
read
public int read(byte[] b) throws java.io.IOExceptionDescription copied from class:ProxyInputStreamInvokes the delegate'sread(byte[])method.- Overrides:
readin classProxyInputStream- Parameters:
b- the buffer to read the bytes into- Returns:
- the number of bytes read or EOF if the end of stream
- Throws:
java.io.IOException- if an I/O error occurs.
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionDescription copied from class:ProxyInputStreamInvokes the delegate'sread(byte[], int, int)method.- Overrides:
readin classProxyInputStream- Parameters:
b- the buffer to read the bytes intooff- The start offsetlen- The number of bytes to read- Returns:
- the number of bytes read or -1 if the end of stream
- Throws:
java.io.IOException- if an I/O error occurs.
-
-