com.ning.compress.lzf
Class ChunkDecoder

java.lang.Object
  extended by com.ning.compress.lzf.ChunkDecoder
Direct Known Subclasses:
UnsafeChunkDecoder, VanillaChunkDecoder

public abstract class ChunkDecoder
extends Object

Decoder that handles decoding of sequence of encoded LZF chunks, combining them into a single contiguous result byte array.

Since:
0.9
Author:
Tatu Saloranta (tatu@ning.com)

Field Summary
protected static byte BYTE_NULL
           
protected static int HEADER_BYTES
           
 
Constructor Summary
ChunkDecoder()
           
 
Method Summary
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.
 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.
 int decode(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.
 int decode(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  void decodeChunk(byte[] in, int inPos, byte[] out, int outPos, int outEnd)
          Main decode method for individual chunks.
abstract  int decodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer)
          Main decode from a stream.
protected static void readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len)
           
protected static int readHeader(InputStream is, byte[] inputBuffer)
          Helper method to forcibly load header bytes that must be read before chunk can be handled.
protected static int uint16(byte[] data, int ptr)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

ChunkDecoder

public ChunkDecoder()
Method Detail

decode

public final byte[] decode(byte[] inputBuffer)
                    throws IOException
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:
IOException

decode

public final byte[] decode(byte[] inputBuffer,
                           int inputPtr,
                           int inputLen)
                    throws IOException
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:
IOException

decode

public final int decode(byte[] inputBuffer,
                        byte[] targetBuffer)
                 throws IOException
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:
IOException

decode

public int decode(byte[] sourceBuffer,
                  int inPtr,
                  int inLength,
                  byte[] targetBuffer)
           throws IOException
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:
IOException

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 bytes
inputBuffer - 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 IOException
Main decode method for individual chunks.

Throws:
IOException

calculateUncompressedSize

public static int calculateUncompressedSize(byte[] data,
                                            int ptr,
                                            int length)
                                     throws IOException
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:
IOException

uint16

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

readHeader

protected static final int readHeader(InputStream is,
                                      byte[] inputBuffer)
                               throws IOException
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


Copyright © 2012. All Rights Reserved.