Class ChunkDecoder
java.lang.Object
com.ning.compress.lzf.ChunkDecoder
- Direct Known Subclasses:
UnsafeChunkDecoder, VanillaChunkDecoder
Decoder that handles decoding of sequence of encoded LZF chunks,
combining them into a single contiguous result byte array.
Note that instances have no state, so they are fully thread-safe and reusable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final byteprotected static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void_reportArrayOverflow(byte[] targetBuffer, int outPtr, int dataLen) Helper method called when it is determined that the target buffer can not hold all data to copy or uncompressprotected voidstatic intcalculateUncompressedSize(byte[] data, int ptr, int length) Helper method that will calculate total uncompressed size, for sequence of one or more LZF blocks stored in given byte array.final byte[]decode(byte[] inputBuffer) Method for decompressing a block of input data encoded in LZF block structure (compatible with lzf command line utility), and can consist of any number of blocks.final intdecode(byte[] inputBuffer, byte[] targetBuffer) Method for decompressing a block of input data encoded in LZF block structure (compatible with lzf command line utility), and can consist of any number of blocks.final byte[]decode(byte[] inputBuffer, int inputPtr, int inputLen) Method for decompressing a block of input data encoded in LZF block structure (compatible with lzf command line utility), and can consist of any number of blocks.intdecode(byte[] sourceBuffer, int inPtr, int inLength, byte[] targetBuffer) Method for decompressing a block of input data encoded in LZF block structure (compatible with LZF command line utility), and can consist of any number of blocks.abstract voiddecodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) Main decode method for individual chunks.abstract intdecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer) Main decode from a stream.protected static final voidreadFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) protected static final intreadHeader(InputStream is, byte[] inputBuffer) Helper method to forcibly load header bytes that must be read before chunk can be handled.protected static final voidskipFully(InputStream is, int amount) abstract intskipOrDecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip) protected static final intuint16(byte[] data, int ptr)
-
Field Details
-
BYTE_NULL
protected static final byte BYTE_NULL- See Also:
-
HEADER_BYTES
protected static final int HEADER_BYTES- See Also:
-
-
Constructor Details
-
ChunkDecoder
public ChunkDecoder()
-
-
Method Details
-
decode
Method for decompressing a block of input data encoded in LZF block structure (compatible with lzf command line utility), and can consist of any number of blocks. Note that input MUST consists of a sequence of one or more complete chunks; partial chunks can not be handled.- Throws:
LZFException
-
decode
Method for decompressing a block of input data encoded in LZF block structure (compatible with lzf command line utility), and can consist of any number of blocks. Note that input MUST consists of a sequence of one or more complete chunks; partial chunks can not be handled.- Throws:
LZFException
-
decode
Method for decompressing a block of input data encoded in LZF block structure (compatible with lzf command line utility), and can consist of any number of blocks. Note that input MUST consists of a sequence of one or more complete chunks; partial chunks can not be handled.- Throws:
LZFException
-
decode
public int decode(byte[] sourceBuffer, int inPtr, int inLength, byte[] targetBuffer) throws LZFException Method for decompressing a block of input data encoded in LZF block structure (compatible with LZF command line utility), and can consist of any number of blocks. Note that input MUST consists of a sequence of one or more complete chunks; partial chunks can not be handled.- Throws:
LZFException
-
decodeChunk
public abstract int decodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer) throws IOException Main decode from a stream. Decompressed bytes are placed in the outputBuffer, inputBuffer is a "scratch-area".- Parameters:
is- An input stream of LZF compressed bytesinputBuffer- A byte array used as a scratch area.outputBuffer- A byte array in which the result is returned- Returns:
- The number of bytes placed in the outputBuffer.
- Throws:
IOException
-
decodeChunk
public abstract void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) throws LZFException Main decode method for individual chunks.- Throws:
LZFException
-
skipOrDecodeChunk
public abstract int skipOrDecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip) throws IOException - Returns:
- If positive number, number of bytes skipped; if -1, end-of-stream was
reached; otherwise, amount of content
decoded (using formula of
returnValue = -(decodedAmount + 2)) - Throws:
IOException
-
calculateUncompressedSize
Helper method that will calculate total uncompressed size, for sequence of one or more LZF blocks stored in given byte array. Will do basic sanity checking, so that this method can be called to verify against some types of corruption.- Throws:
LZFException
-
uint16
protected static final int uint16(byte[] data, int ptr) -
readHeader
Helper method to forcibly load header bytes that must be read before chunk can be handled.- Throws:
IOException
-
readFully
protected static final void readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) throws IOException - Throws:
IOException
-
skipFully
- Throws:
IOException
-
_reportCorruptHeader
- Throws:
LZFException
-
_reportArrayOverflow
protected void _reportArrayOverflow(byte[] targetBuffer, int outPtr, int dataLen) throws LZFException Helper method called when it is determined that the target buffer can not hold all data to copy or uncompress- Throws:
LZFException
-