Class LZFEncoder
- java.lang.Object
-
- com.ning.compress.lzf.LZFEncoder
-
public class LZFEncoder extends java.lang.Object
Encoder that handles splitting of input into chunks to encode, callsChunkEncoder
to compress individual chunks and combines resulting chunks into contiguous output byte array.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
FULL_UNCOMP_ENCODED_CHUNK
static int
MAX_CHUNK_RESULT_SIZE
private static int
MAX_CHUNK_WORKSPACE_SIZE
-
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 specifiedChunkEncoder
for actual encoding.static byte[]
encode(ChunkEncoder enc, byte[] data, int offset, int length)
Method that encodes given input using providedChunkEncoder
, 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 byChunkEncoderFactory.safeInstance()
, for encoding.static byte[]
safeEncode(byte[] data, int offset, int length)
Method that will use "safe"ChunkEncoder
, as produced byChunkEncoderFactory.safeInstance()
, for encoding.static byte[]
safeEncode(byte[] data, int offset, int length, BufferRecycler bufferRecycler)
Method that will use "safe"ChunkEncoder
, as produced byChunkEncoderFactory.safeInstance()
, for encoding.
-
-
-
Field Detail
-
MAX_CHUNK_RESULT_SIZE
public static final int MAX_CHUNK_RESULT_SIZE
- See Also:
- Constant Field Values
-
MAX_CHUNK_WORKSPACE_SIZE
private static final int MAX_CHUNK_WORKSPACE_SIZE
- See Also:
- Constant Field Values
-
FULL_UNCOMP_ENCODED_CHUNK
private static final int FULL_UNCOMP_ENCODED_CHUNK
- See Also:
- Constant Field Values
-
-
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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 specifiedChunkEncoder
for actual encoding.
-
encode
public static byte[] encode(ChunkEncoder enc, byte[] data, int offset, int length)
Method that encodes given input using providedChunkEncoder
, 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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 byChunkEncoderFactory.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 byChunkEncoderFactory.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.
-
-