Package net.jpountz.lz4
Class LZ4Factory
- java.lang.Object
-
- net.jpountz.lz4.LZ4Factory
-
public final class LZ4Factory extends java.lang.Object
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, - an
unsafe Java
instance which is a Java port using the unofficialUnsafe
API.
Only the
safe instance
is guaranteed to work on your JVM, as a consequence it is advised to use thefastestInstance()
orfastestJavaInstance()
to pull aLZ4Factory
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. - a
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description LZ4Decompressor
decompressor()
Deprecated.LZ4Compressor
fastCompressor()
Returns a blazing fastLZ4Compressor
.LZ4FastDecompressor
fastDecompressor()
Returns aLZ4FastDecompressor
instance.static LZ4Factory
fastestInstance()
Returns the fastest availableLZ4Factory
instance.static LZ4Factory
fastestJavaInstance()
Returns the fastest availableLZ4Factory
instance which does not rely on JNI bindings.LZ4Compressor
highCompressor()
Returns aLZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.LZ4Compressor
highCompressor(int compressionLevel)
Returns aLZ4Compressor
which requires more memory thanfastCompressor()
and is slower but compresses more efficiently.static void
main(java.lang.String[] args)
Prints the fastest instance.static LZ4Factory
nativeInstance()
Returns aLZ4Factory
instance that returns compressors and decompressors that are native bindings to the original C library.LZ4SafeDecompressor
safeDecompressor()
Returns aLZ4SafeDecompressor
instance.static LZ4Factory
safeInstance()
Returns aLZ4Factory
instance that returns compressors and decompressors that are written with Java's official API.java.lang.String
toString()
LZ4UnknownSizeDecompressor
unknownSizeDecompressor()
Deprecated.static LZ4Factory
unsafeInstance()
Returns aLZ4Factory
instance that returns compressors and decompressors that may useUnsafe
to speed up compression and decompression.
-
-
-
Method Detail
-
nativeInstance
public static LZ4Factory 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
public static LZ4Factory 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.
-
unsafeInstance
public static LZ4Factory unsafeInstance()
Returns aLZ4Factory
instance that returns compressors and decompressors that may useUnsafe
to speed up compression and decompression.- Returns:
- a
LZ4Factory
instance that returns compressors and decompressors that may useUnsafe
to speed up compression and decompression.
-
fastestJavaInstance
public static LZ4Factory fastestJavaInstance()
Returns the fastest availableLZ4Factory
instance which does not rely on JNI bindings. It first tries to load theunsafe instance
, and then thesafe Java instance
if the JVM doesn't have a workingUnsafe
.- Returns:
- the fastest available
LZ4Factory
instance which does not rely on JNI bindings.
-
fastestInstance
public static LZ4Factory 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
public LZ4Compressor fastCompressor()
Returns a blazing fastLZ4Compressor
.- Returns:
- a blazing fast
LZ4Compressor
-
highCompressor
public 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
public LZ4Compressor highCompressor(int compressionLevel)
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
public LZ4FastDecompressor fastDecompressor()
Returns aLZ4FastDecompressor
instance. Use of this method is deprecated for thenative instance
.- Returns:
- a
LZ4FastDecompressor
instance - See Also:
nativeInstance()
-
safeDecompressor
public LZ4SafeDecompressor safeDecompressor()
Returns aLZ4SafeDecompressor
instance.- Returns:
- a
LZ4SafeDecompressor
instance
-
unknownSizeDecompressor
public LZ4UnknownSizeDecompressor unknownSizeDecompressor()
Deprecated.Returns aLZ4UnknownSizeDecompressor
instance.- Returns:
- a
LZ4UnknownSizeDecompressor
instance
-
decompressor
public LZ4Decompressor decompressor()
Deprecated.Returns aLZ4Decompressor
instance.- Returns:
- a
LZ4Decompressor
instance
-
main
public static void main(java.lang.String[] args)
Prints the fastest instance.- Parameters:
args
- no argument required
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-