Top Description Inners Fields Constructors Methods
org.conscrypt

pack-priv final Class NativeLibraryLoader

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .Closeable, .File, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.lang.reflect.InvocationTargetException, .Method, java.net.URL, java.security.AccessController, .PrivilegedAction, java.text.MessageFormat, java.util.List, java.util.logging.Level, .Logger

Helper class to load JNI resources.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
NativeLibraryLoader.LoadResult

A result of a single attempt to load a library.

Field Summary

Modifier and TypeField and Description
private static final String
private static final boolean
private static final Logger
private static final String
private static final String
private static final File

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static byte[]

Returns:

The binary content of helper Class.
classToByteArray
(Class<?>
- The helper Class provided by this bundle
clazz
)

Load the helper Class as a byte array, to be redefined in specified ClassLoader.

private static void
private static void
copyLibrary(URL
the URL of the library on classpath
classpathUrl
,
File
the destination temporary file.
tmpFile
)

Copies the given shared library file from classpath to a temporary file.

private static void
debug(String message, Throwable t)

private static File
private static boolean
load(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results)

Load the given library with the specified ClassLoader

pack-priv static boolean
loadFirstAvailable(ClassLoader loader, List<NativeLibraryLoader.LoadResult> results, String... names)

Loads the first available library in the collection with the specified ClassLoader.

private static boolean
private static boolean

Returns:

true if the library was successfully loaded.
loadLibrary
(final ClassLoader
- The ClassLoader where the native library will be loaded into
loader
,
final String
- The native library path or name
name
,
final boolean
- Whether the native library will be loaded by path or by name
absolute
,
List<NativeLibraryLoader.LoadResult> results)

Loading the native library into the specified ClassLoader.

private static NativeLibraryLoader.LoadResult

Returns:

the result of the load operation.
loadLibraryFromCurrentClassloader
(String
the name of the library to load.
name
,
boolean
true if name is an absolute path
absolute
)

Attempts to load the library using the NativeLibraryUtil helper from the current classloader.

private static NativeLibraryLoader.LoadResult

Returns:

the result of the load operation.
loadLibraryFromHelperClassloader
(final Class<?>
The NativeLibraryUtil helper class
helper
,
final String
the name of the library to load.
name
,
final boolean
true if name is an absolute path to the file.
absolute
)

Attempts to load the library by reflectively using the NativeLibraryUtil helper from its classloader.

private static void
log(String format, Object arg)

private static void
log(String format, Object arg1, Object arg2)

private static void
log(String format, Object arg1, Object arg2, Throwable t)

private static Class<?>

Returns:

A new helper Class defined in the specified ClassLoader.
tryToLoadClass
(final ClassLoader
- The ClassLoader where to load the helper Class
loader
,
final Class<?>
- The helper Class
helper
)

Try to load the helper Class into specified ClassLoader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DELETE_LIB_PROPERTY_NAMEback to summary
private static final String DELETE_LIB_PROPERTY_NAME
DELETE_NATIVE_LIB_AFTER_LOADINGback to summary
private static final boolean DELETE_NATIVE_LIB_AFTER_LOADING
loggerback to summary
private static final Logger logger
NATIVE_RESOURCE_HOMEback to summary
private static final String NATIVE_RESOURCE_HOME
WORK_DIR_PROPERTY_NAMEback to summary
private static final String WORK_DIR_PROPERTY_NAME
WORKDIRback to summary
private static final File WORKDIR

Constructor Detail

NativeLibraryLoaderback to summary
private NativeLibraryLoader()

Method Detail

classToByteArrayback to summary
private static byte[] classToByteArray(Class<?> clazz) throws ClassNotFoundException

Load the helper Class as a byte array, to be redefined in specified ClassLoader.

Parameters
clazz:Class<?>

- The helper Class provided by this bundle

Returns:byte[]

The binary content of helper Class.

Exceptions
ClassNotFoundException:
Helper class not found or loading failed
closeQuietlyback to summary
private static void closeQuietly(Closeable c)
copyLibraryback to summary
private static void copyLibrary(URL classpathUrl, File tmpFile) throws IOException

Copies the given shared library file from classpath to a temporary file.

Parameters
classpathUrl:URL

the URL of the library on classpath

tmpFile:File

the destination temporary file.

debugback to summary
private static void debug(String message, Throwable t)
getWorkDirback to summary
private static File getWorkDir()
loadback to summary
private static boolean load(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results)

Load the given library with the specified ClassLoader

loadFirstAvailableback to summary
pack-priv static boolean loadFirstAvailable(ClassLoader loader, List<NativeLibraryLoader.LoadResult> results, String... names)

Loads the first available library in the collection with the specified ClassLoader.

loadFromWorkdirback to summary
private static boolean loadFromWorkdir(String name, ClassLoader loader, List<NativeLibraryLoader.LoadResult> results)
loadLibraryback to summary
private static boolean loadLibrary(final ClassLoader loader, final String name, final boolean absolute, List<NativeLibraryLoader.LoadResult> results)

Loading the native library into the specified ClassLoader.

Parameters
loader:ClassLoader

- The ClassLoader where the native library will be loaded into

name:String

- The native library path or name

absolute:boolean

- Whether the native library will be loaded by path or by name

Returns:boolean

true if the library was successfully loaded.

loadLibraryFromCurrentClassloaderback to summary
private static NativeLibraryLoader.LoadResult loadLibraryFromCurrentClassloader(String name, boolean absolute)

Attempts to load the library using the NativeLibraryUtil helper from the current classloader.

Parameters
name:String

the name of the library to load.

absolute:boolean

true if name is an absolute path

Returns:NativeLibraryLoader.LoadResult

the result of the load operation.

loadLibraryFromHelperClassloaderback to summary
private static NativeLibraryLoader.LoadResult loadLibraryFromHelperClassloader(final Class<?> helper, final String name, final boolean absolute)

Attempts to load the library by reflectively using the NativeLibraryUtil helper from its classloader.

Parameters
helper:Class<?>

The NativeLibraryUtil helper class

name:String

the name of the library to load.

absolute:boolean

true if name is an absolute path to the file.

Returns:NativeLibraryLoader.LoadResult

the result of the load operation.

logback to summary
private static void log(String format, Object arg)
logback to summary
private static void log(String format, Object arg1, Object arg2)
logback to summary
private static void log(String format, Object arg1, Object arg2, Throwable t)
tryToLoadClassback to summary
private static Class<?> tryToLoadClass(final ClassLoader loader, final Class<?> helper) throws ClassNotFoundException

Try to load the helper Class into specified ClassLoader.

Parameters
loader:ClassLoader

- The ClassLoader where to load the helper Class

helper:Class<?>

- The helper Class

Returns:Class<?>

A new helper Class defined in the specified ClassLoader.

Exceptions
ClassNotFoundException:
Helper class not found or loading failed
org.conscrypt back to summary

pack-priv final Class NativeLibraryLoader.LoadResult

extends Object
Class Inheritance

A result of a single attempt to load a library.

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
pack-priv final Throwable
pack-priv final boolean
pack-priv final String
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
private
LoadResult(String name, boolean absolute, boolean loaded, boolean usingHelperClassloader, Throwable error)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
log()

private static NativeLibraryLoader.LoadResult
newFailureResult(String name, boolean absolute, boolean usingHelperClassloader, Throwable error)

private static NativeLibraryLoader.LoadResult
newSuccessResult(String name, boolean absolute, boolean usingHelperClassloader)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

absoluteback to summary
pack-priv final boolean absolute
errorback to summary
pack-priv final Throwable error
loadedback to summary
pack-priv final boolean loaded
nameback to summary
pack-priv final String name
usingHelperClassloaderback to summary
pack-priv final boolean usingHelperClassloader

Constructor Detail

LoadResultback to summary
private LoadResult(String name, boolean absolute, boolean loaded, boolean usingHelperClassloader, Throwable error)

Method Detail

logback to summary
pack-priv void log()
newFailureResultback to summary
private static NativeLibraryLoader.LoadResult newFailureResult(String name, boolean absolute, boolean usingHelperClassloader, Throwable error)
newSuccessResultback to summary
private static NativeLibraryLoader.LoadResult newSuccessResult(String name, boolean absolute, boolean usingHelperClassloader)