-
Notifications
You must be signed in to change notification settings - Fork 40
Home
This is the Wiki home for Ning Compress library.
Ning-compress is a Java library for encoding and decoding data, written by Tatu Saloranta ([email protected])
The primary compression format is LZF; but starting with version 0.9, there is also improved support for basic GZIP; latter uses low-level JDK-provided Deflate functionality (which is based on native zlib).
LZF data format is compatible with the original LZF library by Marc A Lehmann. LZF Format differs slightly from some other adaptations, such as one used by H2 database project (by Thomas Mueller); although internal block compression structure is the same, block identifiers differ. This package uses the original LZF identifiers to be 100% compatible with existing command-line lzf tool(s).
LZF alfgorithm itself is optimized for speed, with somewhat more modest compression: compared to GZIP, LZF can be 5-6 times as fast to compress, and twice as fast to decompress.
- JavaDocs:
- LZF Format description
From Maven repository (http://repo1.maven.org/maven2/com/ning/compress-lzf/)
Typical usage is by using one of programmatic interfaces:
- block-based interface (
LZFEncoder
,LZFDecoder
) - streaming interface (
LZFInputStream
,LZFOutputStream
) - or, for 'reverse' direction: 'LZFCompressingInputStream'
- "push" interface (reverse of streaming):
LZFUncompressor
(NOTE: only for un-/decompression)
When reading compressed data from a file you can do it simply creating a LZFInputStream
and use it fo
r reading content
InputStream in = new LZFInputStream(new FileInputStream("data.lzf"));
(note, too, that stream is buffered: there is no need to or benefit from using BufferedInputStream
!)
and similarly you can compress content using LZFOutputStream
:
OutputStream out = new LZFOutputStream(new FileOutputStream("results.lzf"));
or, you can even do the reverse, and read uncompressed data, compress as you read by doing this:
InputStream compressingIn = new LZFCompressingInputStream(
Compressing and decompressing individual blocks is as simple:
byte[] compressed = LZFEncoder.encode(uncompressedData);
byte[] uncompressed = LZFDecoder.decode(compressedData);
Finally, note that LZF encoded chunks have length of at most 64 kB; longer content will be split into such chunks. This is done transparently so that you can compress/uncompressed blocks of any size; chunking is handled by LZF encoders and decoders.
It is also possibly to use jar as a command-line tool since it has manifest that points to 'com.ning.compress.lzf.LZF' as the class having main() method to call.
This means that you can use it like:
java -jar compress-lzf-0.9.6.jar
(which will display necessary usage arguments)
Finally, jar is also a valid (and extremely simple) OSGi bundle to make it work nicely on OSGi containers.
Check out jvm-compress-benchmark for comparison of space- and time-efficiency of this LZF implementation, relative other available Java-accessible compression libraries.