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 class
A 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 helperClass
as a byte array, to be redefined in specifiedClassLoader
.private static void
private static void
copyLibrary
(URL classpathUrl, File tmpFile) Copies the given shared library file from classpath to a temporary file.private static void
private static File
private static boolean
load
(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results) Load the given library with the specifiedClassLoader
(package private) static boolean
loadFirstAvailable
(ClassLoader loader, List<NativeLibraryLoader.LoadResult> results, String... names) Loads the first available library in the collection with the specifiedClassLoader
.private static boolean
loadFromWorkdir
(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results) private static boolean
loadLibrary
(ClassLoader loader, String name, boolean absolute, List<NativeLibraryLoader.LoadResult> results) Loading the native library into the specifiedClassLoader
.private static NativeLibraryLoader.LoadResult
loadLibraryFromCurrentClassloader
(String name, boolean absolute) Attempts to load the library using theNativeLibraryUtil
helper from the current classloader.private static NativeLibraryLoader.LoadResult
loadLibraryFromHelperClassloader
(Class<?> helper, String name, boolean absolute) Attempts to load the library by reflectively using theNativeLibraryUtil
helper from its classloader.private static void
private static void
private static void
private static Class
<?> tryToLoadClass
(ClassLoader loader, Class<?> helper) Try to load the helperClass
into 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
- - TheClassLoader
where 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:
true
if 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 theNativeLibraryUtil
helper from its classloader.- Parameters:
helper
- TheNativeLibraryUtil
helper classname
- the name of the library to load.absolute
- true ifname
is 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 theNativeLibraryUtil
helper from the current classloader.- Parameters:
name
- the name of the library to load.absolute
- true ifname
is 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 helperClass
into specifiedClassLoader
.- Parameters:
loader
- - TheClassLoader
where to load the helperClass
helper
- - The helperClass
- Returns:
- A new helper Class defined in the specified ClassLoader.
- Throws:
ClassNotFoundException
- Helper class not found or loading failed
-
classToByteArray
Load the helperClass
as a byte array, to be redefined in specifiedClassLoader
.- Parameters:
clazz
- - The helperClass
provided by this bundle- Returns:
- The binary content of helper
Class
. - Throws:
ClassNotFoundException
- Helper class not found or loading failed
-
closeQuietly
-
log
-
log
-
log
-
debug
-