Package org.conscrypt
Class NativeLibraryLoader
java.lang.Object
org.conscrypt.NativeLibraryLoader
Helper class to load JNI resources.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final classA result of a single attempt to load a library. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static byte[]classToByteArray(Class<?> clazz) Load the helperClassas a byte array, to be redefined in specifiedClassLoader.private static voidprivate static voidcopyLibrary(URL classpathUrl, File tmpFile) Copies the given shared library file from classpath to a temporary file.private static voidprivate static Fileprivate static booleanload(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results) Load the given library with the specifiedClassLoader(package private) static booleanloadFirstAvailable(ClassLoader loader, List<NativeLibraryLoader.LoadResult> results, String... names) Loads the first available library in the collection with the specifiedClassLoader.private static booleanloadFromWorkdir(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results) private static booleanloadLibrary(ClassLoader loader, String name, boolean absolute, List<NativeLibraryLoader.LoadResult> results) Loading the native library into the specifiedClassLoader.private static NativeLibraryLoader.LoadResultloadLibraryFromCurrentClassloader(String name, boolean absolute) Attempts to load the library using theNativeLibraryUtilhelper from the current classloader.private static NativeLibraryLoader.LoadResultloadLibraryFromHelperClassloader(Class<?> helper, String name, boolean absolute) Attempts to load the library by reflectively using theNativeLibraryUtilhelper from its classloader.private static voidprivate static voidprivate static voidprivate static Class<?> tryToLoadClass(ClassLoader loader, Class<?> helper) Try to load the helperClassinto specifiedClassLoader.
-
Field Details
-
logger
-
WORK_DIR_PROPERTY_NAME
- See Also:
-
DELETE_LIB_PROPERTY_NAME
- See Also:
-
NATIVE_RESOURCE_HOME
- See Also:
-
WORKDIR
-
DELETE_NATIVE_LIB_AFTER_LOADING
private static final boolean DELETE_NATIVE_LIB_AFTER_LOADING
-
-
Constructor Details
-
NativeLibraryLoader
private NativeLibraryLoader()
-
-
Method Details
-
getWorkDir
-
loadFirstAvailable
static boolean loadFirstAvailable(ClassLoader loader, List<NativeLibraryLoader.LoadResult> results, String... names) Loads the first available library in the collection with the specifiedClassLoader. -
load
private static boolean load(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results) Load the given library with the specifiedClassLoader -
loadFromWorkdir
private static boolean loadFromWorkdir(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results) -
copyLibrary
Copies the given shared library file from classpath to a temporary file.- Parameters:
classpathUrl- the URL of the library on classpathtmpFile- the destination temporary file.- Throws:
IOException
-
loadLibrary
private static boolean loadLibrary(ClassLoader loader, String name, boolean absolute, List<NativeLibraryLoader.LoadResult> results) Loading the native library into the specifiedClassLoader.- Parameters:
loader- - TheClassLoaderwhere the native library will be loaded intoname- - The native library path or nameabsolute- - Whether the native library will be loaded by path or by name- Returns:
trueif the library was successfully loaded.
-
loadLibraryFromHelperClassloader
private static NativeLibraryLoader.LoadResult loadLibraryFromHelperClassloader(Class<?> helper, String name, boolean absolute) Attempts to load the library by reflectively using theNativeLibraryUtilhelper from its classloader.- Parameters:
helper- TheNativeLibraryUtilhelper classname- the name of the library to load.absolute- true ifnameis an absolute path to the file.- Returns:
- the result of the load operation.
-
loadLibraryFromCurrentClassloader
private static NativeLibraryLoader.LoadResult loadLibraryFromCurrentClassloader(String name, boolean absolute) Attempts to load the library using theNativeLibraryUtilhelper from the current classloader.- Parameters:
name- the name of the library to load.absolute- true ifnameis an absolute path- Returns:
- the result of the load operation.
-
tryToLoadClass
private static Class<?> tryToLoadClass(ClassLoader loader, Class<?> helper) throws ClassNotFoundException Try to load the helperClassinto specifiedClassLoader.- Parameters:
loader- - TheClassLoaderwhere to load the helperClasshelper- - The helperClass- Returns:
- A new helper Class defined in the specified ClassLoader.
- Throws:
ClassNotFoundException- Helper class not found or loading failed
-
classToByteArray
Load the helperClassas a byte array, to be redefined in specifiedClassLoader.- Parameters:
clazz- - The helperClassprovided by this bundle- Returns:
- The binary content of helper
Class. - Throws:
ClassNotFoundException- Helper class not found or loading failed
-
closeQuietly
-
log
-
log
-
log
-
debug
-