Class LZ4DecompressorWithLength

java.lang.Object
net.jpountz.lz4.LZ4DecompressorWithLength

public class LZ4DecompressorWithLength extends Object
Convenience class to decompress data compressed by LZ4CompressorWithLength. This decompressor is NOT compatible with any other compressors in lz4-java or any other lz4 tools. The user does not need to specify the length of the compressed data or original data because the length of the original decompressed data is included in the compressed data.
  • Constructor Details

    • LZ4DecompressorWithLength

      public LZ4DecompressorWithLength(LZ4FastDecompressor fastDecompressor)
      Creates a new decompressor to decompress data compressed by LZ4CompressorWithLength. Methods that allocate their output buffer reject decompressed lengths greater than 64 MiB. Note that it is deprecated to use a JNI-binding instance of LZ4FastDecompressor. Please see LZ4Factory.nativeInstance() for details.
      Parameters:
      fastDecompressor - fast decompressor to use
    • LZ4DecompressorWithLength

      public LZ4DecompressorWithLength(LZ4FastDecompressor fastDecompressor, int maxDecompressedLength)
      Creates a new decompressor to decompress data compressed by LZ4CompressorWithLength. Note that it is deprecated to use a JNI-binding instance of LZ4FastDecompressor. Please see LZ4Factory.nativeInstance() for details.
      Parameters:
      fastDecompressor - fast decompressor to use
      maxDecompressedLength - maximum decompressed length for methods that allocate their output buffer
      Throws:
      IllegalArgumentException - if maxDecompressedLength is negative
      Since:
      1.11.2
    • LZ4DecompressorWithLength

      public LZ4DecompressorWithLength(LZ4SafeDecompressor safeDecompressor)
      Creates a new decompressor to decompress data compressed by LZ4CompressorWithLength. Methods that allocate their output buffer reject decompressed lengths greater than 64 MiB.
      Parameters:
      safeDecompressor - safe decompressor to use
    • LZ4DecompressorWithLength

      public LZ4DecompressorWithLength(LZ4SafeDecompressor safeDecompressor, int maxDecompressedLength)
      Creates a new decompressor to decompress data compressed by LZ4CompressorWithLength.
      Parameters:
      safeDecompressor - safe decompressor to use
      maxDecompressedLength - maximum decompressed length for methods that allocate their output buffer
      Throws:
      IllegalArgumentException - if maxDecompressedLength is negative
      Since:
      1.11.2
  • Method Details

    • getDecompressedLength

      public static int getDecompressedLength(byte[] src)
      Returns the decompressed length of compressed data in src.
      Parameters:
      src - the compressed data
      Returns:
      the decompressed length, without validating it against the compressed data
    • getDecompressedLength

      public static int getDecompressedLength(byte[] src, int srcOff)
      Returns the decompressed length of compressed data in src[srcOff:].
      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      Returns:
      the decompressed length, without validating it against the compressed data
    • getDecompressedLength

      public static int getDecompressedLength(ByteBuffer src)
      Returns the decompressed length of compressed data in src.
      Parameters:
      src - the compressed data
      Returns:
      the decompressed length, without validating it against the compressed data
    • getDecompressedLength

      public static int getDecompressedLength(ByteBuffer src, int srcOff)
      Returns the decompressed length of compressed data in src[srcOff:].
      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      Returns:
      the decompressed length, without validating it against the compressed data
    • decompress

      public int decompress(byte[] src, byte[] dest)
      Convenience method, equivalent to calling decompress(src, 0, dest, 0).
      Parameters:
      src - the compressed data
      dest - the destination buffer to store the decompressed data
      Returns:
      the number of bytes read to restore the original input
    • decompress

      public int decompress(byte[] src, int srcOff, byte[] dest, int destOff)
      When LZ4FastDecompressor was specified to the constructor, decompresses src[srcOff:] into dest[destOff:] and returns the number of bytes read from src, and when LZ4SafeDecompressor was specified to the constructor, decompresses src[srcOff:src.length] into dest[destOff:] and returns the number of decompressed bytes written into dest.
      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      dest - the destination buffer to store the decompressed data
      destOff - the start offset in dest
      Returns:
      the number of bytes read to restore the original input (when LZ4FastDecompressor is used), or the number of decompressed bytes (when LZ4SafeDecompressor is used)
    • decompress

      public int decompress(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff)
      When LZ4FastDecompressor was specified to the constructor, decompresses src[srcOff:] into dest[destOff:] and returns the number of bytes read from src, and when LZ4SafeDecompressor was specified to the constructor, decompresses src[srcOff:srcOff+srcLen] into dest[destOff:] and returns the number of decompressed bytes written into dest.
      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      srcLen - the exact size of the compressed data (ignored when LZ4FastDecompressor is used)
      dest - the destination buffer to store the decompressed data
      destOff - the start offset in dest
      Returns:
      the number of bytes read to restore the original input (when LZ4FastDecompressor is used), or the number of decompressed bytes (when LZ4SafeDecompressor is used)
    • decompress

      public byte[] decompress(byte[] src)
      Convenience method, equivalent to calling decompress(src, 0).
      Parameters:
      src - the compressed data
      Returns:
      the decompressed data
      Throws:
      LZ4Exception - if the declared decompressed length is invalid or exceeds the configured maximum
    • decompress

      public byte[] decompress(byte[] src, int srcOff)
      Convenience method which returns src[srcOff:] decompressed when LZ4FastDecompressor was specified to the constructor, or src[srcOff:src.length] decompressed when LZ4SafeDecompressor was specified to the constructor.

      Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to decompress into.

      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      Returns:
      the decompressed data
      Throws:
      LZ4Exception - if the declared decompressed length is invalid or exceeds the configured maximum
    • decompress

      public byte[] decompress(byte[] src, int srcOff, int srcLen)
      Convenience method which returns src[srcOff:] decompressed when LZ4FastDecompressor was specified to the constructor, or src[srcOff:srcOff+srcLen] decompressed when LZ4SafeDecompressor was specified to the constructor.

      Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to decompress into.

      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      srcLen - the exact size of the compressed data (ignored when LZ4FastDecompressor is used)
      Returns:
      the decompressed data
      Throws:
      LZ4Exception - if the declared decompressed length is invalid or exceeds the configured maximum
    • decompress

      public void decompress(ByteBuffer src, ByteBuffer dest)
      Decompresses src into dest. When LZ4SafeDecompressor was specified to the constructor, src's Buffer.remaining() must be exactly the size of the compressed data. This method moves the positions of the buffers.
      Parameters:
      src - the compressed data
      dest - the destination buffer to store the decompressed data
    • decompress

      public int decompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff)
      When LZ4FastDecompressor was specified to the constructor, decompresses src[srcOff:] into dest[destOff:] and returns the number of bytes read from src, and when LZ4SafeDecompressor was specified to the constructor, decompresses src[srcOff:src.remaining()] into dest[destOff:] and returns the number of decompressed bytes written into dest. The positions and limits of the ByteBuffers remain unchanged.
      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      dest - the destination buffer to store the decompressed data
      destOff - the start offset in dest
      Returns:
      the number of bytes read to restore the original input (when LZ4FastDecompressor is used), or the number of decompressed bytes (when LZ4SafeDecompressor is used)
    • decompress

      public int decompress(ByteBuffer src, int srcOff, int srcLen, ByteBuffer dest, int destOff)
      When LZ4FastDecompressor was specified to the constructor, decompresses src[srcOff:] into dest[destOff:] and returns the number of bytes read from src, and when LZ4SafeDecompressor was specified to the constructor, decompresses src[srcOff:srcOff+srcLen] into dest[destOff:] and returns the number of decompressed bytes written into dest. The positions and limits of the ByteBuffers remain unchanged.
      Parameters:
      src - the compressed data
      srcOff - the start offset in src
      srcLen - the exact size of the compressed data (ignored when LZ4FastDecompressor is used)
      dest - the destination buffer to store the decompressed data
      destOff - the start offset in dest
      Returns:
      the number of bytes read to restore the original input (when LZ4FastDecompressor is used), or the number of decompressed bytes (when LZ4SafeDecompressor is used)