Top Description Fields Constructors Methods
net.jpountz.lz4

public final Class LZ4Factory

extends Object
Class Inheritance
Imports
java.lang.reflect.Constructor, .Field, .InvocationTargetException, java.util.Arrays, net.jpountz.util.Native, .Utils

Entry point for the LZ4 API.

This class has 3 instances

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.

Field Summary

Modifier and TypeField and Description
private final LZ4Compressor
private final LZ4FastDecompressor
fastDecompressor

Deprecated as a consequence of LZ4FastDecompressor being deprecated.
private final LZ4Compressor
private final LZ4Compressor[]
private final String
private static LZ4Factory
private static LZ4Factory
private static LZ4Factory
private final LZ4SafeDecompressor
safeDecompressor

Deprecated as a consequence of LZ4SafeDecompressor being deprecated.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static <T> T
public LZ4Decompressor
decompressor()

Deprecated use fastDecompressor()
Return a LZ4Decompressor instance.
public LZ4Compressor
fastCompressor()

Return a blazing fast LZ4Compressor.

public LZ4FastDecompressor
fastDecompressor()

Deprecated as a consequence of LZ4FastDecompressor being deprecated.
Return a LZ4FastDecompressor instance.
public static LZ4Factory
fastestInstance()

Return the fastest available LZ4Factory instance.

public static LZ4Factory
fastestJavaInstance()

Return the fastest available LZ4Factory instance which does not rely on JNI bindings.

public LZ4Compressor
highCompressor()

Return a LZ4Compressor which requires more memory than fastCompressor() and is slower but compresses more efficiently.

public LZ4Compressor
highCompressor(int compressionLevel)

Return a LZ4Compressor which requires more memory than fastCompressor() and is slower but compresses more efficiently.

private static LZ4Factory
public static void
main(String[] args)

Prints the fastest instance.

public static synchronized LZ4Factory
nativeInstance()

Return a LZ4Factory instance that returns compressors and decompressors that are native bindings to the original C library.

public LZ4SafeDecompressor
safeDecompressor()

Deprecated as a consequence of LZ4SafeDecompressor being deprecated.
Return a LZ4SafeDecompressor instance.
public static synchronized LZ4Factory
safeInstance()

Return a LZ4Factory instance that returns compressors and decompressors that are written with Java's official API.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
public LZ4UnknownSizeDecompressor
public static synchronized LZ4Factory
unsafeInstance()

Return a LZ4Factory instance that returns compressors and decompressors that may use sun.misc.Unsafe to speed up compression and decompression.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fastCompressorback to summary
private final LZ4Compressor fastCompressor
fastDecompressorback to summary
private final LZ4FastDecompressor fastDecompressor

Deprecated

as a consequence of LZ4FastDecompressor being deprecated. See corresponding docs for further information.

highCompressorback to summary
private final LZ4Compressor highCompressor
highCompressorsback to summary
private final LZ4Compressor[] highCompressors
implback to summary
private final String impl
JAVA_SAFE_INSTANCEback to summary
private static LZ4Factory JAVA_SAFE_INSTANCE
JAVA_UNSAFE_INSTANCEback to summary
private static LZ4Factory JAVA_UNSAFE_INSTANCE
NATIVE_INSTANCEback to summary
private static LZ4Factory NATIVE_INSTANCE
safeDecompressorback to summary
private final LZ4SafeDecompressor safeDecompressor

Deprecated

as a consequence of LZ4SafeDecompressor being deprecated. See corresponding docs for further information.

Constructor Detail

LZ4Factoryback to summary
private LZ4Factory(String impl) throws ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, NoSuchMethodException, InstantiationException, InvocationTargetException

Method Detail

classInstanceback to summary
private static <T> T classInstance(String cls) throws NoSuchFieldException, SecurityException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException
Annotations
@SuppressWarnings:unchecked
decompressorback to summary
public LZ4Decompressor decompressor()

Deprecated

use fastDecompressor()

Return a LZ4Decompressor instance.

fastCompressorback to summary
public LZ4Compressor fastCompressor()

Return a blazing fast LZ4Compressor.

fastDecompressorback to summary
public LZ4FastDecompressor fastDecompressor()

Deprecated

as a consequence of LZ4FastDecompressor being deprecated. See corresponding docs for further information.

Return a LZ4FastDecompressor instance.

fastestInstanceback to summary
public static LZ4Factory fastestInstance()

Return the fastest available LZ4Factory instance. If the class loader is the system class loader and if the native instance loads successfully, then the native instance is returned, otherwise the fastest Java instance is returned.

Please read javadocs of nativeInstance() before using this method.

fastestJavaInstanceback to summary
public static LZ4Factory fastestJavaInstance()

Return the fastest available LZ4Factory instance which does not rely on JNI bindings. It first tries to load the unsafe instance, and then the safe Java instance if the JVM doesn't have a working sun.misc.Unsafe.

highCompressorback to summary
public LZ4Compressor highCompressor()

Return a LZ4Compressor which requires more memory than fastCompressor() and is slower but compresses more efficiently.

highCompressorback to summary
public LZ4Compressor highCompressor(int compressionLevel)

Return a LZ4Compressor which requires more memory than fastCompressor() and is slower but compresses more efficiently. The compression level can be customized.

For current implementations, the following is true about compression level:

  1. It should be in range [1, 17]
  2. A compression level higher than 17 would be treated as 17.
  3. A compression level lower than 1 would be treated as 9.

instanceback to summary
private static LZ4Factory instance(String impl)
mainback to summary
public static void main(String[] args)

Prints the fastest instance.

nativeInstanceback to summary
public static synchronized LZ4Factory nativeInstance()

Return a LZ4Factory 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:

  1. 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.
  2. 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.
safeDecompressorback to summary
public LZ4SafeDecompressor safeDecompressor()

Deprecated

as a consequence of LZ4SafeDecompressor being deprecated. See corresponding docs for further information.

Return a LZ4SafeDecompressor instance.

safeInstanceback to summary
public static synchronized LZ4Factory safeInstance()

Return a LZ4Factory instance that returns compressors and decompressors that are written with Java's official API.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
unknownSizeDecompressorback to summary
public LZ4UnknownSizeDecompressor unknownSizeDecompressor()

Deprecated

use safeDecompressor()

Return a LZ4UnknownSizeDecompressor instance.

unsafeInstanceback to summary
public static synchronized LZ4Factory unsafeInstance()

Return a LZ4Factory instance that returns compressors and decompressors that may use sun.misc.Unsafe to speed up compression and decompression.