diff --git a/src/java/net/jpountz/lz4/LZ4Factory.java b/src/java/net/jpountz/lz4/LZ4Factory.java index 1350c40..31932fc 100644 --- a/src/java/net/jpountz/lz4/LZ4Factory.java +++ b/src/java/net/jpountz/lz4/LZ4Factory.java @@ -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. @@ -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) {