net.jpountz.lz4
Class LZ4Factory
- java.lang.Object
-
- net.jpountz.lz4.LZ4Factory
-
public final class LZ4Factory extends java.lang.ObjectEntry point for the LZ4 API.This class has 3 instances
- a
nativeinstance which is a JNI binding to the original LZ4 C implementation. - a
safe Javainstance which is a pure Java port of the original C library, - an
unsafe Javainstance which is a Java port using the unofficialUnsafeAPI.
Only the
safe instanceis guaranteed to work on your JVM, as a consequence it is advised to use thefastestInstance()orfastestJavaInstance()to pull aLZ4Factoryinstance.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
LZ4Factoryinstance in a static field. - a
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description LZ4Decompressordecompressor()Deprecated.LZ4CompressorfastCompressor()Return a blazing fastLZ4Compressor.LZ4FastDecompressorfastDecompressor()Return aLZ4FastDecompressorinstance.static LZ4FactoryfastestInstance()Return the fastest availableLZ4Factoryinstance.static LZ4FactoryfastestJavaInstance()Return the fastest availableLZ4Factoryinstance which does not rely on JNI bindings.LZ4CompressorhighCompressor()Return aLZ4Compressorwhich requires more memory thanfastCompressor()and is slower but compresses more efficiently.LZ4CompressorhighCompressor(int compressionLevel)Return aLZ4Compressorwhich requires more memory thanfastCompressor()and is slower but compresses more efficiently.static voidmain(java.lang.String[] args)Prints the fastest instance.static LZ4FactorynativeInstance()Return aLZ4Factoryinstance that returns compressors and decompressors that are native bindings to the original C library.LZ4SafeDecompressorsafeDecompressor()Return aLZ4SafeDecompressorinstance.static LZ4FactorysafeInstance()Return aLZ4Factoryinstance that returns compressors and decompressors that are written with Java's official API.java.lang.StringtoString()LZ4UnknownSizeDecompressorunknownSizeDecompressor()Deprecated.static LZ4FactoryunsafeInstance()Return aLZ4Factoryinstance that returns compressors and decompressors that may useUnsafeto speed up compression and decompression.
-
-
-
Method Detail
-
nativeInstance
public static LZ4Factory nativeInstance()
Return aLZ4Factoryinstance 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.
-
safeInstance
public static LZ4Factory safeInstance()
Return aLZ4Factoryinstance that returns compressors and decompressors that are written with Java's official API.
-
unsafeInstance
public static LZ4Factory unsafeInstance()
Return aLZ4Factoryinstance that returns compressors and decompressors that may useUnsafeto speed up compression and decompression.
-
fastestJavaInstance
public static LZ4Factory fastestJavaInstance()
Return the fastest availableLZ4Factoryinstance which does not rely on JNI bindings. It first tries to load theunsafe instance, and then thesafe Java instanceif the JVM doesn't have a workingUnsafe.
-
fastestInstance
public static LZ4Factory fastestInstance()
Return the fastest availableLZ4Factoryinstance. If the class loader is the system class loader and if thenative instanceloads successfully, then thenative instanceis returned, otherwise thefastest Java instanceis returned.Please read
javadocs of nativeInstance()before using this method.
-
fastCompressor
public LZ4Compressor fastCompressor()
Return a blazing fastLZ4Compressor.
-
highCompressor
public LZ4Compressor highCompressor()
Return aLZ4Compressorwhich requires more memory thanfastCompressor()and is slower but compresses more efficiently.
-
highCompressor
public LZ4Compressor highCompressor(int compressionLevel)
Return aLZ4Compressorwhich 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.
-
fastDecompressor
public LZ4FastDecompressor fastDecompressor()
Return aLZ4FastDecompressorinstance.
-
safeDecompressor
public LZ4SafeDecompressor safeDecompressor()
Return aLZ4SafeDecompressorinstance.
-
unknownSizeDecompressor
public LZ4UnknownSizeDecompressor unknownSizeDecompressor()
Deprecated. usesafeDecompressor()Return aLZ4UnknownSizeDecompressorinstance.
-
decompressor
public LZ4Decompressor decompressor()
Deprecated. usefastDecompressor()Return aLZ4Decompressorinstance.
-
main
public static void main(java.lang.String[] args)
Prints the fastest instance.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG