Package com.ning.compress.lzf.util
Class LZFFileInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FileInputStream
-
- com.ning.compress.lzf.util.LZFFileInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class LZFFileInputStream extends java.io.FileInputStreamHelper class that allows use of LZF compression even if a library requires use ofFileInputStream.Note that use of this class is not recommended unless you absolutely must use a
FileInputStreaminstance; otherwise basicLZFInputStream(which uses aggregation for underlying streams) is more appropriateImplementation note: much of the code is just copied from
LZFInputStream, so care must be taken to keep implementations in sync if there are fixes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classLZFFileInputStream.WrapperThis simple wrapper is needed to re-route read calls so that they will use "raw" reads
-
Field Summary
Fields Modifier and Type Field Description protected int_bufferLengthLength of the current uncompressed bytes bufferprotected int_bufferPositionThe current position (next char to output) in the uncompressed bytes buffer.protected boolean_cfgFullReadsFlag that indicates whether we force full reads (reading of as many bytes as requested), or 'optimal' reads (up to as many as available, but at least one).protected byte[]_decodedBytesthe buffer of uncompressed bytes from which content is readprotected ChunkDecoder_decompressorUnderlying decoder in use.protected byte[]_inputBufferthe current buffer of compressed bytes (from which to decode)protected boolean_inputStreamClosedFlag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)protected BufferRecycler_recyclerObject that handles details of buffer recyclingprotected LZFFileInputStream.Wrapper_wrapperWrapper object we use to allow decoder to read directly from the stream, without ending in infinite loop...
-
Constructor Summary
Constructors Constructor Description LZFFileInputStream(java.io.File file)LZFFileInputStream(java.io.FileDescriptor fdObj)LZFFileInputStream(java.io.FileDescriptor fdObj, ChunkDecoder decompressor)LZFFileInputStream(java.io.FileDescriptor fdObj, ChunkDecoder decompressor, BufferRecycler bufferRecycler)LZFFileInputStream(java.io.File file, ChunkDecoder decompressor)LZFFileInputStream(java.io.File file, ChunkDecoder decompressor, BufferRecycler bufferRecycler)LZFFileInputStream(java.lang.String name)LZFFileInputStream(java.lang.String name, ChunkDecoder decompressor)LZFFileInputStream(java.lang.String name, ChunkDecoder decompressor, BufferRecycler bufferRecycler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()intread()intread(byte[] b)intread(byte[] buffer, int offset, int length)intreadAndWrite(java.io.OutputStream out)Convenience method that will read and uncompress all data available, and write it using givenOutputStream.protected intreadRaw(byte[] buffer, int offset, int length)protected booleanreadyBuffer()Fill the uncompressed bytes buffer by reading the underlying inputStream.voidsetUseFullReads(boolean b)Method that can be used define whether reads should be "full" or "optimal": former means that full compressed blocks are read right away as needed, optimal that only smaller chunks are read at a time, more being read as needed.longskip(long n)Overridden to implement efficient skipping by skipping full chunks whenever possible.protected longskipRaw(long amount)
-
-
-
Field Detail
-
_decompressor
protected final ChunkDecoder _decompressor
Underlying decoder in use.
-
_recycler
protected final BufferRecycler _recycler
Object that handles details of buffer recycling
-
_inputStreamClosed
protected boolean _inputStreamClosed
Flag that indicates if we have already called 'inputStream.close()' (to avoid calling it multiple times)
-
_cfgFullReads
protected boolean _cfgFullReads
Flag that indicates whether we force full reads (reading of as many bytes as requested), or 'optimal' reads (up to as many as available, but at least one). Default is false, meaning that 'optimal' read is used.
-
_inputBuffer
protected byte[] _inputBuffer
the current buffer of compressed bytes (from which to decode)
-
_decodedBytes
protected byte[] _decodedBytes
the buffer of uncompressed bytes from which content is read
-
_bufferPosition
protected int _bufferPosition
The current position (next char to output) in the uncompressed bytes buffer.
-
_bufferLength
protected int _bufferLength
Length of the current uncompressed bytes buffer
-
_wrapper
protected final LZFFileInputStream.Wrapper _wrapper
Wrapper object we use to allow decoder to read directly from the stream, without ending in infinite loop...
-
-
Constructor Detail
-
LZFFileInputStream
public LZFFileInputStream(java.io.File file) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
LZFFileInputStream
public LZFFileInputStream(java.io.FileDescriptor fdObj)
-
LZFFileInputStream
public LZFFileInputStream(java.lang.String name) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
LZFFileInputStream
public LZFFileInputStream(java.io.File file, ChunkDecoder decompressor) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
LZFFileInputStream
public LZFFileInputStream(java.io.FileDescriptor fdObj, ChunkDecoder decompressor)
-
LZFFileInputStream
public LZFFileInputStream(java.lang.String name, ChunkDecoder decompressor) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
LZFFileInputStream
public LZFFileInputStream(java.io.File file, ChunkDecoder decompressor, BufferRecycler bufferRecycler) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
LZFFileInputStream
public LZFFileInputStream(java.io.FileDescriptor fdObj, ChunkDecoder decompressor, BufferRecycler bufferRecycler)
-
LZFFileInputStream
public LZFFileInputStream(java.lang.String name, ChunkDecoder decompressor, BufferRecycler bufferRecycler) throws java.io.FileNotFoundException- Throws:
java.io.FileNotFoundException
-
-
Method Detail
-
setUseFullReads
public void setUseFullReads(boolean b)
Method that can be used define whether reads should be "full" or "optimal": former means that full compressed blocks are read right away as needed, optimal that only smaller chunks are read at a time, more being read as needed.
-
available
public int available()
- Overrides:
availablein classjava.io.FileInputStream
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FileInputStream- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FileInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException- Overrides:
readin classjava.io.FileInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] buffer, int offset, int length) throws java.io.IOException- Overrides:
readin classjava.io.FileInputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOExceptionOverridden to implement efficient skipping by skipping full chunks whenever possible.- Overrides:
skipin classjava.io.FileInputStream- Throws:
java.io.IOException
-
readAndWrite
public int readAndWrite(java.io.OutputStream out) throws java.io.IOExceptionConvenience method that will read and uncompress all data available, and write it using givenOutputStream. This avoids having to make an intermediate copy of uncompressed data which would be needed when doing the same manually.- Parameters:
out- OutputStream to use for writing content- Returns:
- Number of bytes written (uncompressed)
- Throws:
java.io.IOException
-
readyBuffer
protected boolean readyBuffer() throws java.io.IOExceptionFill the uncompressed bytes buffer by reading the underlying inputStream.- Throws:
java.io.IOException
-
readRaw
protected final int readRaw(byte[] buffer, int offset, int length) throws java.io.IOException- Throws:
java.io.IOException
-
skipRaw
protected final long skipRaw(long amount) throws java.io.IOException- Throws:
java.io.IOException
-
-