Class LZFEncoder


  • public class LZFEncoder
    extends java.lang.Object
    Encoder that handles splitting of input into chunks to encode, calls ChunkEncoder to compress individual chunks and combines resulting chunks into contiguous output byte array.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private LZFEncoder()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int appendEncoded​(byte[] input, int inputPtr, int inputLength, byte[] outputBuffer, int outputPtr)
      Alternate version that accepts pre-allocated output buffer.
      static int appendEncoded​(byte[] input, int inputPtr, int inputLength, byte[] outputBuffer, int outputPtr, BufferRecycler bufferRecycler)
      Alternate version that accepts pre-allocated output buffer.
      static int appendEncoded​(ChunkEncoder enc, byte[] input, int inputPtr, int inputLength, byte[] outputBuffer, int outputPtr)
      Alternate version that accepts pre-allocated output buffer.
      static byte[] encode​(byte[] data)
      Method for compressing given input data using LZF encoding and block structure (compatible with lzf command line utility).
      static byte[] encode​(byte[] data, int offset, int length)
      Method for compressing given input data using LZF encoding and block structure (compatible with lzf command line utility).
      static byte[] encode​(byte[] data, int offset, int length, BufferRecycler bufferRecycler)
      Method for compressing given input data using LZF encoding and block structure (compatible with lzf command line utility).
      static byte[] encode​(ChunkEncoder enc, byte[] data, int length)
      Compression method that uses specified ChunkEncoder for actual encoding.
      static byte[] encode​(ChunkEncoder enc, byte[] data, int offset, int length)
      Method that encodes given input using provided ChunkEncoder, and aggregating it into a single byte array and returning that.
      static int estimateMaxWorkspaceSize​(int inputSize)
      Helper method that can be used to estimate maximum space needed to try compression of given amount of data.
      static int safeAppendEncoded​(byte[] input, int inputPtr, int inputLength, byte[] outputBuffer, int outputPtr)
      Alternate version that accepts pre-allocated output buffer.
      static int safeAppendEncoded​(byte[] input, int inputPtr, int inputLength, byte[] outputBuffer, int outputPtr, BufferRecycler bufferRecycler)
      Alternate version that accepts pre-allocated output buffer.
      static byte[] safeEncode​(byte[] data)
      Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding.
      static byte[] safeEncode​(byte[] data, int offset, int length)
      Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding.
      static byte[] safeEncode​(byte[] data, int offset, int length, BufferRecycler bufferRecycler)
      Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding.
      • Methods inherited from class java.lang.Object

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

      • LZFEncoder

        private LZFEncoder()
    • Method Detail

      • estimateMaxWorkspaceSize

        public static int estimateMaxWorkspaceSize​(int inputSize)
        Helper method that can be used to estimate maximum space needed to try compression of given amount of data. This is slightly larger than maximum resulting content since compressor has a choice of uncompressed chunks to use, but that is only done after compression fails to reduce size; and this temporary expansion of up to 3.3% or so (1 indicator for every 31 bytes of uncompressed data) is more than what eventual expansion would be (5 bytes header per each uncompressed chunk, usually 0.01%).
      • encode

        public static byte[] encode​(byte[] data)
        Method for compressing given input data using LZF encoding and block structure (compatible with lzf command line utility). Result consists of a sequence of chunks.

        Note that ChunkEncoder instance used is one produced by ChunkEncoderFactory.optimalInstance(), which typically is "unsafe" instance if one can be used on current JVM.

      • safeEncode

        public static byte[] safeEncode​(byte[] data)
        Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding. Safe here means that it does not use any non-compliant features beyond core JDK.
      • encode

        public static byte[] encode​(byte[] data,
                                    int offset,
                                    int length)
        Method for compressing given input data using LZF encoding and block structure (compatible with lzf command line utility). Result consists of a sequence of chunks.

        Note that ChunkEncoder instance used is one produced by ChunkEncoderFactory.optimalInstance(), which typically is "unsafe" instance if one can be used on current JVM.

      • safeEncode

        public static byte[] safeEncode​(byte[] data,
                                        int offset,
                                        int length)
        Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding. Safe here means that it does not use any non-compliant features beyond core JDK.
      • encode

        public static byte[] encode​(byte[] data,
                                    int offset,
                                    int length,
                                    BufferRecycler bufferRecycler)
        Method for compressing given input data using LZF encoding and block structure (compatible with lzf command line utility). Result consists of a sequence of chunks.

        Note that ChunkEncoder instance used is one produced by ChunkEncoderFactory.optimalInstance(), which typically is "unsafe" instance if one can be used on current JVM.

      • safeEncode

        public static byte[] safeEncode​(byte[] data,
                                        int offset,
                                        int length,
                                        BufferRecycler bufferRecycler)
        Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding. Safe here means that it does not use any non-compliant features beyond core JDK.
      • encode

        public static byte[] encode​(ChunkEncoder enc,
                                    byte[] data,
                                    int length)
        Compression method that uses specified ChunkEncoder for actual encoding.
      • encode

        public static byte[] encode​(ChunkEncoder enc,
                                    byte[] data,
                                    int offset,
                                    int length)
        Method that encodes given input using provided ChunkEncoder, and aggregating it into a single byte array and returning that.

        NOTE: method does NOT call ChunkEncoder.close(); caller is responsible for doing that after it is done using the encoder.

      • appendEncoded

        public static int appendEncoded​(byte[] input,
                                        int inputPtr,
                                        int inputLength,
                                        byte[] outputBuffer,
                                        int outputPtr)
        Alternate version that accepts pre-allocated output buffer.

        Note that ChunkEncoder instance used is one produced by ChunkEncoderFactory.optimalNonAllocatingInstance(int), which typically is "unsafe" instance if one can be used on current JVM.

      • safeAppendEncoded

        public static int safeAppendEncoded​(byte[] input,
                                            int inputPtr,
                                            int inputLength,
                                            byte[] outputBuffer,
                                            int outputPtr)
        Alternate version that accepts pre-allocated output buffer.

        Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding. Safe here means that it does not use any non-compliant features beyond core JDK.

      • appendEncoded

        public static int appendEncoded​(byte[] input,
                                        int inputPtr,
                                        int inputLength,
                                        byte[] outputBuffer,
                                        int outputPtr,
                                        BufferRecycler bufferRecycler)
        Alternate version that accepts pre-allocated output buffer.

        Note that ChunkEncoder instance used is one produced by ChunkEncoderFactory.optimalNonAllocatingInstance(int), which typically is "unsafe" instance if one can be used on current JVM.

      • safeAppendEncoded

        public static int safeAppendEncoded​(byte[] input,
                                            int inputPtr,
                                            int inputLength,
                                            byte[] outputBuffer,
                                            int outputPtr,
                                            BufferRecycler bufferRecycler)
        Alternate version that accepts pre-allocated output buffer.

        Method that will use "safe" ChunkEncoder, as produced by ChunkEncoderFactory.safeInstance(), for encoding. Safe here means that it does not use any non-compliant features beyond core JDK.

      • appendEncoded

        public static int appendEncoded​(ChunkEncoder enc,
                                        byte[] input,
                                        int inputPtr,
                                        int inputLength,
                                        byte[] outputBuffer,
                                        int outputPtr)
        Alternate version that accepts pre-allocated output buffer.