Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/java/net/jpountz/lz4/LZ4Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,16 @@ private static LZ4Factory instance(String impl) {
}
}

private static final boolean PREFER_NATIVE;
private static LZ4Factory NATIVE_INSTANCE,
JAVA_UNSAFE_INSTANCE,
JAVA_SAFE_INSTANCE;

static {
final String preferNativeStr = System.getProperty("net.jpountz.lz4.PREFER_NATIVE");
PREFER_NATIVE = preferNativeStr == null || Boolean.valueOf(preferNativeStr);
}

/**
* Returns a {@link LZ4Factory} instance that returns compressors and
* decompressors that are native bindings to the original C library.
Expand Down Expand Up @@ -160,8 +166,8 @@ public static LZ4Factory fastestJavaInstance() {
* @return the fastest available {@link LZ4Factory} instance
*/
public static LZ4Factory fastestInstance() {
if (Native.isLoaded()
|| Native.class.getClassLoader() == ClassLoader.getSystemClassLoader()) {
if (PREFER_NATIVE && (Native.isLoaded()
|| Native.class.getClassLoader() == ClassLoader.getSystemClassLoader())) {
try {
return nativeInstance();
} catch (Throwable t) {
Expand Down