Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to prefer java #219

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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