Class LZ4SafeDecompressor

  • All Implemented Interfaces:
    LZ4UnknownSizeDecompressor

    public abstract class LZ4SafeDecompressor
    extends java.lang.Object
    implements LZ4UnknownSizeDecompressor
    LZ4 decompressor that requires the size of the compressed data to be known.

    Implementations of this class are usually a little slower than those of LZ4FastDecompressor but do not require the size of the original data to be known.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      int decompress​(byte[] src, byte[] dest)
      Convenience method, equivalent to calling decompress(src, 0, src.length, dest, 0)
      byte[] decompress​(byte[] src, int maxDestLen)
      Convenience method, equivalent to calling decompress(src, 0, src.length, maxDestLen).
      int decompress​(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff)
      abstract int decompress​(byte[] src, int srcOff, int srcLen, byte[] dest, int destOff, int maxDestLen)
      Decompresses src[srcOff:srcOff+srcLen] into dest[destOff:destOff+maxDestLen] and returns the number of decompressed bytes written into dest.
      byte[] decompress​(byte[] src, int srcOff, int srcLen, int maxDestLen)
      Convenience method which returns src[srcOff:srcOff+srcLen] decompressed.
      abstract int decompress​(java.nio.ByteBuffer src, int srcOff, int srcLen, java.nio.ByteBuffer dest, int destOff, int maxDestLen)
      Decompresses src[srcOff:srcOff+srcLen] into dest[destOff:destOff+maxDestLen] and returns the number of decompressed bytes written into dest.
      void decompress​(java.nio.ByteBuffer src, java.nio.ByteBuffer dest)
      Decompresses src into dest.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LZ4SafeDecompressor

        public LZ4SafeDecompressor()
    • Method Detail

      • decompress

        public abstract int decompress​(byte[] src,
                                       int srcOff,
                                       int srcLen,
                                       byte[] dest,
                                       int destOff,
                                       int maxDestLen)
        Decompresses src[srcOff:srcOff+srcLen] into dest[destOff:destOff+maxDestLen] and returns the number of decompressed bytes written into dest.
        Specified by:
        decompress in interface LZ4UnknownSizeDecompressor
        Parameters:
        src - the compressed data
        srcOff - the start offset in src
        srcLen - the exact size of the compressed data
        dest - the destination buffer to store the decompressed data
        destOff - the start offset in dest
        maxDestLen - the maximum number of bytes to write in dest
        Returns:
        the original input size
        Throws:
        LZ4Exception - if maxDestLen is too small
      • decompress

        public abstract int decompress​(java.nio.ByteBuffer src,
                                       int srcOff,
                                       int srcLen,
                                       java.nio.ByteBuffer dest,
                                       int destOff,
                                       int maxDestLen)
        Decompresses src[srcOff:srcOff+srcLen] into dest[destOff:destOff+maxDestLen] 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
        dest - the destination buffer to store the decompressed data
        destOff - the start offset in dest
        maxDestLen - the maximum number of bytes to write in dest
        Returns:
        the original input size
        Throws:
        LZ4Exception - if maxDestLen is too small
      • decompress

        public final int decompress​(byte[] src,
                                    byte[] dest)
        Convenience method, equivalent to calling decompress(src, 0, src.length, dest, 0)
        Parameters:
        src - the compressed data
        dest - the destination buffer to store the decompressed data
        Returns:
        the original input size
        Throws:
        LZ4Exception - if dest is too small
      • decompress

        public final byte[] decompress​(byte[] src,
                                       int srcOff,
                                       int srcLen,
                                       int maxDestLen)
        Convenience method which returns src[srcOff:srcOff+srcLen] decompressed.

        Warning: this method has an important overhead due to the fact that it needs to allocate a buffer to decompress into, and then needs to resize this buffer to the actual decompressed length.

        Here is how this method is implemented:

         byte[] decompressed = new byte[maxDestLen];
         final int decompressedLength = decompress(src, srcOff, srcLen, decompressed, 0, maxDestLen);
         if (decompressedLength != decompressed.length) {
           decompressed = Arrays.copyOf(decompressed, decompressedLength);
         }
         return decompressed;
         
        Parameters:
        src - the compressed data
        srcOff - the start offset in src
        srcLen - the exact size of the compressed data
        maxDestLen - the maximum number of bytes to write in dest
        Returns:
        the decompressed data
        Throws:
        LZ4Exception - if maxDestLen is too small
      • decompress

        public final byte[] decompress​(byte[] src,
                                       int maxDestLen)
        Convenience method, equivalent to calling decompress(src, 0, src.length, maxDestLen).
        Parameters:
        src - the compressed data
        maxDestLen - the maximum number of bytes to write in dest
        Returns:
        the decompressed data
        Throws:
        LZ4Exception - if maxDestLen is too small
      • decompress

        public final void decompress​(java.nio.ByteBuffer src,
                                     java.nio.ByteBuffer dest)
        Decompresses src into dest. 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
        Throws:
        LZ4Exception - if dest is too small
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object