Class FastLz

java.lang.Object
io.netty.handler.codec.compression.FastLz

final class FastLz extends java.lang.Object
Core of FastLZ compression algorithm. This class provides methods for compression and decompression of buffers and saves constants which use by FastLzFrameEncoder and FastLzFrameDecoder. This is refactored code of jfastlz library written by William Kinney.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final byte
     
    (package private) static final byte
     
    (package private) static final byte
     
    (package private) static final byte
     
    (package private) static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    (package private) static final int
    Level 1 is the fastest compression and generally useful for short data.
    (package private) static final int
    Level 2 is slightly slower but it gives better compression ratio.
    (package private) static final int
    In this case compress(ByteBuf, int, int, ByteBuf, int, int) will choose level automatically depending on the length of the input buffer.
    (package private) static final int
     
    (package private) static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    (package private) static final int
    Do not call compress(ByteBuf, int, int, ByteBuf, int, int) for input buffers which length less than this value.
    private static final int
     
    (package private) static final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static int
    calculateOutputBufferLength(int inputLength)
    The output buffer must be at least 6% larger than the input buffer and can not be smaller than 66 bytes.
    (package private) static int
    compress(ByteBuf input, int inOffset, int inLength, ByteBuf output, int outOffset, int proposedLevel)
    Compress a block of data in the input buffer and returns the size of compressed block.
    (package private) static int
    decompress(ByteBuf input, int inOffset, int inLength, ByteBuf output, int outOffset, int outLength)
    Decompress a block of compressed data and returns the size of the decompressed block.
    private static int
    hashFunction(ByteBuf p, int offset)
     
    private static int
    readU16(ByteBuf data, int offset)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • FastLz

      private FastLz()
  • Method Details

    • calculateOutputBufferLength

      static int calculateOutputBufferLength(int inputLength)
      The output buffer must be at least 6% larger than the input buffer and can not be smaller than 66 bytes.
      Parameters:
      inputLength - length of input buffer
      Returns:
      Maximum output buffer length
    • compress

      static int compress(ByteBuf input, int inOffset, int inLength, ByteBuf output, int outOffset, int proposedLevel)
      Compress a block of data in the input buffer and returns the size of compressed block. The size of input buffer is specified by length. The minimum input buffer size is 32. If the input is not compressible, the return value might be larger than length (input buffer size).
    • decompress

      static int decompress(ByteBuf input, int inOffset, int inLength, ByteBuf output, int outOffset, int outLength)
      Decompress a block of compressed data and returns the size of the decompressed block. If error occurs, e.g. the compressed data is corrupted or the output buffer is not large enough, then 0 (zero) will be returned instead. Decompression is memory safe and guaranteed not to write the output buffer more than what is specified in outLength.
    • hashFunction

      private static int hashFunction(ByteBuf p, int offset)
    • readU16

      private static int readU16(ByteBuf data, int offset)