Package com.ning.compress.lzf
Class ChunkDecoder
- java.lang.Object
-
- com.ning.compress.lzf.ChunkDecoder
-
- Direct Known Subclasses:
UnsafeChunkDecoder,VanillaChunkDecoder
public abstract class ChunkDecoder extends java.lang.ObjectDecoder 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
Fields Modifier and Type Field Description protected static byteBYTE_NULLprotected static intHEADER_BYTES
-
Constructor Summary
Constructors Constructor Description ChunkDecoder()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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 void_reportCorruptHeader()static 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.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.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.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(java.io.InputStream is, byte[] inputBuffer, byte[] outputBuffer)Main decode from a stream.protected static voidreadFully(java.io.InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len)protected static intreadHeader(java.io.InputStream is, byte[] inputBuffer)Helper method to forcibly load header bytes that must be read before chunk can be handled.protected static voidskipFully(java.io.InputStream is, int amount)abstract intskipOrDecodeChunk(java.io.InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip)protected static intuint16(byte[] data, int ptr)
-
-
-
Field Detail
-
BYTE_NULL
protected static final byte BYTE_NULL
- See Also:
- Constant Field Values
-
HEADER_BYTES
protected static final int HEADER_BYTES
- See Also:
- Constant Field Values
-
-
Method Detail
-
decode
public final byte[] decode(byte[] inputBuffer) throws LZFExceptionMethod 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 final byte[] decode(byte[] inputBuffer, int inputPtr, int inputLen) throws LZFExceptionMethod 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 final int decode(byte[] inputBuffer, byte[] targetBuffer) throws LZFExceptionMethod 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 LZFExceptionMethod 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(java.io.InputStream is, byte[] inputBuffer, byte[] outputBuffer) throws java.io.IOExceptionMain 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:
java.io.IOException
-
decodeChunk
public abstract void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) throws LZFExceptionMain decode method for individual chunks.- Throws:
LZFException
-
skipOrDecodeChunk
public abstract int skipOrDecodeChunk(java.io.InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip) throws java.io.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:
java.io.IOException
-
calculateUncompressedSize
public static int calculateUncompressedSize(byte[] data, int ptr, int length) throws LZFExceptionHelper 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
protected static final int readHeader(java.io.InputStream is, byte[] inputBuffer) throws java.io.IOExceptionHelper method to forcibly load header bytes that must be read before chunk can be handled.- Throws:
java.io.IOException
-
readFully
protected static final void readFully(java.io.InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) throws java.io.IOException- Throws:
java.io.IOException
-
skipFully
protected static final void skipFully(java.io.InputStream is, int amount) throws java.io.IOException- Throws:
java.io.IOException
-
_reportCorruptHeader
protected void _reportCorruptHeader() throws LZFException- Throws:
LZFException
-
_reportArrayOverflow
protected void _reportArrayOverflow(byte[] targetBuffer, int outPtr, int dataLen) throws LZFExceptionHelper method called when it is determined that the target buffer can not hold all data to copy or uncompress- Throws:
LZFException
-
-