Class CompressLZF
- All Implemented Interfaces:
Compressor
This class implements the LZF lossless data compression algorithm. LZF is a Lempel-Ziv variant with byte-aligned output, and optimized for speed.
Safety/Use Notes:
- Each instance should be used by a single thread only.
- The data buffers should be smaller than 1 GB.
- For performance reasons, safety checks on expansion are omitted.
- Invalid compressed data can cause an ArrayIndexOutOfBoundsException.
The LZF compressed format knows literal runs and back-references:
- Literal run: directly copy bytes from input to output.
- Back-reference: copy previous data to output stream, with specified offset from location and length. The length is at least 3 bytes.
The first byte of the compressed stream is the control byte. For literal runs, the highest three bits of the control byte are not set, the lower bits are the literal run length, and the next bytes are data to copy directly into the output. For back-references, the highest three bits of the control byte are the back-reference length. If all three bits are set, then the back-reference length is stored in the next byte. The lower bits of the control byte combined with the next byte form the offset for the back-reference.
-
Field Summary
Fields inherited from interface org.h2.compress.Compressor
DEFLATE, LZF, NO -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintcompress(byte[] in, int inPos, int inLen, byte[] out, int outPos) Compress a number of bytes.intcompress(ByteBuffer in, int inPos, byte[] out, int outPos) Compress a number of bytes.voidexpand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen) Expand a number of compressed bytes.static voidexpand(ByteBuffer in, ByteBuffer out) Expand a number of compressed bytes.intGet the compression algorithm type.voidsetOptions(String options) Set the compression options.
-
Constructor Details
-
CompressLZF
public CompressLZF()
-
-
Method Details
-
setOptions
Description copied from interface:CompressorSet the compression options. This may include settings for higher performance but less compression.- Specified by:
setOptionsin interfaceCompressor- Parameters:
options- the options
-
compress
public int compress(byte[] in, int inPos, int inLen, byte[] out, int outPos) Description copied from interface:CompressorCompress a number of bytes.- Specified by:
compressin interfaceCompressor- Parameters:
in- the input datainPos- the offset at the input arrayinLen- the number of bytes to compressout- the output areaoutPos- the offset at the output array- Returns:
- the end position
-
compress
Compress a number of bytes.- Parameters:
in- the input datainPos- the offset at the input bufferout- the output areaoutPos- the offset at the output array- Returns:
- the end position
-
expand
public void expand(byte[] in, int inPos, int inLen, byte[] out, int outPos, int outLen) Description copied from interface:CompressorExpand a number of compressed bytes.- Specified by:
expandin interfaceCompressor- Parameters:
in- the compressed datainPos- the offset at the input arrayinLen- the number of bytes to readout- the output areaoutPos- the offset at the output arrayoutLen- the size of the uncompressed data
-
expand
Expand a number of compressed bytes.- Parameters:
in- the compressed dataout- the output area
-
getAlgorithm
public int getAlgorithm()Description copied from interface:CompressorGet the compression algorithm type.- Specified by:
getAlgorithmin interfaceCompressor- Returns:
- the type
-