Top Description Fields Constructors Methods
com.ning.compress.lzf

public abstract Class ChunkDecoder

extends Object
Class Inheritance
Known Direct Subclasses
com.ning.compress.lzf.impl.UnsafeChunkDecoder, com.ning.compress.lzf.impl.VanillaChunkDecoder
Imports
java.io.IOException, .InputStream

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.

Author
Tatu Saloranta ([email protected])

Field Summary

Modifier and TypeField and Description
protected static final byte
protected static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and 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 uncompress

protected void
public static int
calculateUncompressedSize(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.

public final byte[]
decode(final 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.

public final byte[]
decode(final 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.

public final int
decode(final byte[] inputBuffer, final 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.

public int
decode(final byte[] sourceBuffer, int inPtr, int inLength, final 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.

public abstract int

Returns:

The number of bytes placed in the outputBuffer.
decodeChunk
(final InputStream
An input stream of LZF compressed bytes
is
,
final byte[]
A byte array used as a scratch area.
inputBuffer
,
final byte[]
A byte array in which the result is returned
outputBuffer
)

Main decode from a stream.

public abstract void
decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd)

Main decode method for individual chunks.

protected static final void
readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len)

protected static final int
readHeader(final InputStream is, final byte[] inputBuffer)

Helper method to forcibly load header bytes that must be read before chunk can be handled.

protected static final void
skipFully(final InputStream is, int amount)

public abstract int

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))
skipOrDecodeChunk
(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer, final long maxToSkip)

protected static final int
uint16(byte[] data, int ptr)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE_NULLback to summary
protected static final byte BYTE_NULL
HEADER_BYTESback to summary
protected static final int HEADER_BYTES

Constructor Detail

ChunkDecoderback to summary
public ChunkDecoder()

Method Detail

_reportArrayOverflowback to summary
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

_reportCorruptHeaderback to summary
protected void _reportCorruptHeader() throws LZFException
calculateUncompressedSizeback to summary
public static int calculateUncompressedSize(byte[] data, int ptr, int length) throws LZFException

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.

decodeback to summary
public final byte[] decode(final byte[] inputBuffer) 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.

decodeback to summary
public final byte[] decode(final byte[] inputBuffer, int inputPtr, int inputLen) 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.

decodeback to summary
public final int decode(final byte[] inputBuffer, final 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.

decodeback to summary
public int decode(final byte[] sourceBuffer, int inPtr, int inLength, final 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.

decodeChunkback to summary
public abstract int decodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer) throws IOException

Main decode from a stream. Decompressed bytes are placed in the outputBuffer, inputBuffer is a "scratch-area".

Parameters
is:InputStream

An input stream of LZF compressed bytes

inputBuffer:byte[]

A byte array used as a scratch area.

outputBuffer:byte[]

A byte array in which the result is returned

Returns:int

The number of bytes placed in the outputBuffer.

decodeChunkback to summary
public abstract void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd) throws LZFException

Main decode method for individual chunks.

readFullyback to summary
protected static final void readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len) throws IOException
readHeaderback to summary
protected static final int readHeader(final InputStream is, final byte[] inputBuffer) throws IOException

Helper method to forcibly load header bytes that must be read before chunk can be handled.

skipFullyback to summary
protected static final void skipFully(final InputStream is, int amount) throws IOException
skipOrDecodeChunkback to summary
public abstract int skipOrDecodeChunk(final InputStream is, final byte[] inputBuffer, final byte[] outputBuffer, final long maxToSkip) throws IOException
Returns:int

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))

uint16back to summary
protected static final int uint16(byte[] data, int ptr)