Class ChunkDecoder

java.lang.Object
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.

Note that instances have no state, so they are fully thread-safe and reusable.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final byte
     
    protected static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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 uncompress
    protected void
     
    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.
    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 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.
    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.
    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 final void
    readFully(InputStream is, boolean compressed, byte[] outputBuffer, int offset, int len)
     
    protected static final int
    readHeader(InputStream is, byte[] inputBuffer)
    Helper method to forcibly load header bytes that must be read before chunk can be handled.
    protected static final void
    skipFully(InputStream is, int amount)
     
    abstract int
    skipOrDecodeChunk(InputStream is, byte[] inputBuffer, byte[] outputBuffer, long maxToSkip)
     
    protected static final 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 Details

  • Constructor Details

    • ChunkDecoder

      public ChunkDecoder()
  • Method Details

    • decode

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

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

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

      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.
      Throws:
      LZFException
    • 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
    • skipFully

      protected static final void skipFully(InputStream is, int amount) throws IOException
      Throws:
      IOException
    • _reportCorruptHeader

      protected void _reportCorruptHeader() throws LZFException
      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