mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-25 23:14:34 +02:00
use static call instead of call by reflection
This commit is contained in:
parent
94b879fe12
commit
8d49dddbba
@ -170,25 +170,42 @@ public class SnappyLoader
|
||||
e.printStackTrace();
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare SnappyNativeLoader or LocalSnappyNativeLoader
|
||||
Class< ? > nativeLoader = prepareNativeLoader();
|
||||
// Load the code
|
||||
loadNativeLibrary(nativeLoader);
|
||||
}
|
||||
else {
|
||||
if (!isLoaded) {
|
||||
// load locally
|
||||
File nativeLib = findNativeLibrary();
|
||||
if (nativeLib != null) {
|
||||
System.load(nativeLib.getAbsolutePath());
|
||||
}
|
||||
else {
|
||||
// Load preinstalled snappyjava (in the path -Djava.library.path)
|
||||
System.loadLibrary("snappyjava");
|
||||
}
|
||||
|
||||
try {
|
||||
api = (SnappyNativeAPI) Class.forName("org.xerial.snappy.SnappyNative").newInstance();
|
||||
isLoaded = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
private static Class< ? > prepareNativeLoader() {
|
||||
boolean useNativeCodeInjection = !Boolean.parseBoolean(System.getProperty(KEY_SNAPPY_DISABLE_NATIVE_INJECTION,
|
||||
"false"));
|
||||
|
||||
try {
|
||||
if (!useNativeCodeInjection) {
|
||||
// Use the local loader
|
||||
return LocalSnappyNativeLoader.class;
|
||||
}
|
||||
else {
|
||||
// Use parent class loader to load SnappyNative, since Tomcat, which uses different class loaders for each webapps, cannot load JNI interface twice
|
||||
|
||||
final String nativeLoaderClassName = "org.xerial.snappy.SnappyNativeLoader";
|
||||
@ -205,8 +222,8 @@ public class SnappyLoader
|
||||
|
||||
// Create SnappyNative class from a byte code
|
||||
Class< ? > classLoader = Class.forName("java.lang.ClassLoader");
|
||||
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class,
|
||||
byte[].class, int.class, int.class });
|
||||
Method defineClass = classLoader.getDeclaredMethod("defineClass", new Class[] { String.class, byte[].class,
|
||||
int.class, int.class });
|
||||
|
||||
//ProtectionDomain pd = System.class.getProtectionDomain();
|
||||
|
||||
@ -228,7 +245,7 @@ public class SnappyLoader
|
||||
|
||||
// Load the SnappyNativeLoader class
|
||||
return rootClassLoader.loadClass(nativeLoaderClassName);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user