Package io.netty.util.internal
Class NativeLibraryLoader
java.lang.Object
io.netty.util.internal.NativeLibraryLoader
Helper class to load JNI resources.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate static final booleanprivate static final InternalLoggerprivate static final Stringprivate static final booleanprivate static final byte[]private static final File -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static StringCalculates the mangled shading prefix added to this class's full name.private static byte[]classToByteArray(Class<?> clazz) Load the helperClassas a byte array, to be redefined in specifiedClassLoader.private static voidprivate static byte[]digest(MessageDigest digest, URL url) private static byte[]generateUniqueId(int length) private static URLgetResource(String path, ClassLoader loader) static voidload(String originalName, ClassLoader loader) Load the given library with the specifiedClassLoaderstatic voidloadFirstAvailable(ClassLoader loader, String... names) Loads the first available library in the collection with the specifiedClassLoader.private static voidloadLibrary(ClassLoader loader, String name, boolean absolute) Loading the native library into the specifiedClassLoader.private static voidloadLibraryByHelper(Class<?> helper, String name, boolean absolute) private static voidrethrowWithMoreDetailsIfPossible(String name, NoSuchMethodError error) private static booleanshouldShadedLibraryIdBePatched(String packagePrefix) private static boolean(package private) static voidtryPatchShadedLibraryIdAndSign(File libraryFile, String originalName) private static Class<?> tryToLoadClass(ClassLoader loader, Class<?> helper) Try to load the helperClassinto specifiedClassLoader.
-
Field Details
-
logger
-
NATIVE_RESOURCE_HOME
- See Also:
-
WORKDIR
-
DELETE_NATIVE_LIB_AFTER_LOADING
private static final boolean DELETE_NATIVE_LIB_AFTER_LOADING -
TRY_TO_PATCH_SHADED_ID
private static final boolean TRY_TO_PATCH_SHADED_ID -
DETECT_NATIVE_LIBRARY_DUPLICATES
private static final boolean DETECT_NATIVE_LIBRARY_DUPLICATES -
UNIQUE_ID_BYTES
private static final byte[] UNIQUE_ID_BYTES
-
-
Constructor Details
-
NativeLibraryLoader
private NativeLibraryLoader()
-
-
Method Details
-
loadFirstAvailable
Loads the first available library in the collection with the specifiedClassLoader.- Throws:
IllegalArgumentException- if none of the given libraries load successfully.
-
calculateMangledPackagePrefix
Calculates the mangled shading prefix added to this class's full name.This method mangles the package name as follows, so we can unmangle it back later:
_to_1.to_
Note that we don't mangle non-ASCII characters here because it's extremely unlikely to have a non-ASCII character in a package name. For more information, see:
- JNI specification
parsePackagePrefix()innetty_jni_util.c.
- Throws:
UnsatisfiedLinkError- if the shader used something other than a prefix
-
load
Load the given library with the specifiedClassLoader -
getResource
-
digest
-
tryPatchShadedLibraryIdAndSign
-
tryExec
-
shouldShadedLibraryIdBePatched
-
generateUniqueId
private static byte[] generateUniqueId(int length) -
loadLibrary
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
-
rethrowWithMoreDetailsIfPossible
-
loadLibraryByHelper
private static void loadLibraryByHelper(Class<?> helper, String name, boolean absolute) throws UnsatisfiedLinkError - Throws:
UnsatisfiedLinkError
-
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
-