Package net.jpountz.lz4
Class LZ4Factory
java.lang.Object
net.jpountz.lz4.LZ4Factory
Entry point for the LZ4 API.
This class has 3 instances
- a
native
instance which is a JNI binding to the original LZ4 C implementation. - a
safe Java
instance which is a pure Java port of the original C library,
Only the safe instance
is guaranteed to work on your
JVM, as a consequence it is advised to use the fastestInstance()
or
fastestJavaInstance()
to pull a LZ4Factory
instance.
All methods from this class are very costly, so you should get an instance
once, and then reuse it whenever possible. This is typically done by storing
a LZ4Factory
instance in a static field.
-
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Returns a blazing fastLZ4Compressor
.Returns aLZ4FastDecompressor
instance.static LZ4Factory
Returns the fastest availableLZ4Factory
instance.static LZ4Factory
Returns the fastest availableLZ4Factory
instance which does not rely on JNI bindings.Returns aLZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.highCompressor
(int compressionLevel) Returns aLZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.static void
Prints the fastest instance.static LZ4Factory
Returns aLZ4Factory
instance that returns compressors and decompressors that are native bindings to the original C library.Returns aLZ4SafeDecompressor
instance.static LZ4Factory
Returns aLZ4Factory
instance that returns compressors and decompressors that are written with Java's official API.toString()
Deprecated.
-
Method Details
-
nativeInstance
Returns aLZ4Factory
instance that returns compressors and decompressors that are native bindings to the original C library.Please note that this instance has some traps you should be aware of:
- Upon loading this instance, files will be written to the temporary directory of the system. Although these files are supposed to be deleted when the JVM exits, they might remain on systems that don't support removal of files being used such as Windows.
- The instance can only be loaded once per JVM. This can be a problem if your application uses multiple class loaders (such as most servlet containers): this instance will only be available to the children of the class loader which has loaded it. As a consequence, it is advised to either not use this instance in webapps or to put this library in the lib directory of your servlet container so that it is loaded by the system class loader.
- From lz4-java version 1.6.0, a
LZ4FastDecompressor
instance returned byfastDecompressor()
of this instance is SLOWER than aLZ4SafeDecompressor
instance returned bysafeDecompressor()
, due to a change in the original LZ4 C implementation. The corresponding C API function is deprecated. Hence use offastDecompressor()
is deprecated for this instance.
- Returns:
- a
LZ4Factory
instance that returns compressors and decompressors that are native bindings to the original C library
-
safeInstance
Returns aLZ4Factory
instance that returns compressors and decompressors that are written with Java's official API.- Returns:
- a
LZ4Factory
instance that returns compressors and decompressors that are written with Java's official API.
-
fastestJavaInstance
Returns the fastest availableLZ4Factory
instance which does not rely on JNI bindings. It loadssafe Java instance
- Returns:
- the fastest available
LZ4Factory
instance which does not rely on JNI bindings.
-
fastestInstance
Returns the fastest availableLZ4Factory
instance. If the class loader is the system class loader and if thenative instance
loads successfully, then thenative instance
is returned, otherwise thefastest Java instance
is returned.Please read
javadocs of nativeInstance()
before using this method.- Returns:
- the fastest available
LZ4Factory
instance
-
fastCompressor
Returns a blazing fastLZ4Compressor
.- Returns:
- a blazing fast
LZ4Compressor
-
highCompressor
Returns aLZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.- Returns:
- a
LZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.
-
highCompressor
Returns aLZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently. The compression level can be customized.For current implementations, the following is true about compression level:
- It should be in range [1, 17]
- A compression level higher than 17 would be treated as 17.
- A compression level lower than 1 would be treated as 9.
- Parameters:
compressionLevel
- the compression level between [1, 17]; the higher the level, the higher the compression ratio- Returns:
- a
LZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.
-
fastDecompressor
Returns aLZ4FastDecompressor
instance. Use of this method is deprecated for thenative instance
.- Returns:
- a
LZ4FastDecompressor
instance - See Also:
-
safeDecompressor
Returns aLZ4SafeDecompressor
instance.- Returns:
- a
LZ4SafeDecompressor
instance
-
unknownSizeDecompressor
Deprecated.Returns aLZ4UnknownSizeDecompressor
instance.- Returns:
- a
LZ4UnknownSizeDecompressor
instance
-
decompressor
Deprecated.Returns aLZ4Decompressor
instance.- Returns:
- a
LZ4Decompressor
instance
-
main
Prints the fastest instance.- Parameters:
args
- no argument required
-
toString
-
fastDecompressor()