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 boolean
private static final boolean
private static final InternalLogger
private static final String
private static final boolean
private static final byte[]
private static final File
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
Calculates the mangled shading prefix added to this class's full name.private static byte[]
classToByteArray
(Class<?> clazz) Load the helperClass
as a byte array, to be redefined in specifiedClassLoader
.private static void
private static byte[]
digest
(MessageDigest digest, URL url) private static byte[]
generateUniqueId
(int length) private static URL
getResource
(String path, ClassLoader loader) static void
load
(String originalName, ClassLoader loader) Load the given library with the specifiedClassLoader
static void
loadFirstAvailable
(ClassLoader loader, String... names) Loads the first available library in the collection with the specifiedClassLoader
.private static void
loadLibrary
(ClassLoader loader, String name, boolean absolute) Loading the native library into the specifiedClassLoader
.private static void
loadLibraryByHelper
(Class<?> helper, String name, boolean absolute) private static void
rethrowWithMoreDetailsIfPossible
(String name, NoSuchMethodError error) private static boolean
shouldShadedLibraryIdBePatched
(String packagePrefix) private static boolean
(package private) static void
tryPatchShadedLibraryIdAndSign
(File libraryFile, String originalName) private static Class
<?> tryToLoadClass
(ClassLoader loader, Class<?> helper) Try to load the helperClass
into 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
- - 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
-
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 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
-