Package io.netty.util.internal
Class NativeLibraryLoader
- java.lang.Object
-
- io.netty.util.internal.NativeLibraryLoader
-
public final class NativeLibraryLoader extends java.lang.ObjectHelper class to load JNI resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classNativeLibraryLoader.NoexecVolumeDetector
-
Field Summary
Fields Modifier and Type Field Description private static booleanDELETE_NATIVE_LIB_AFTER_LOADINGprivate static booleanDETECT_NATIVE_LIBRARY_DUPLICATESprivate static InternalLoggerloggerprivate static java.lang.StringNATIVE_RESOURCE_HOMEprivate static booleanTRY_TO_PATCH_SHADED_IDprivate static byte[]UNIQUE_ID_BYTESprivate static java.io.FileWORKDIR
-
Constructor Summary
Constructors Modifier Constructor Description privateNativeLibraryLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringcalculateMangledPackagePrefix()Calculates the mangled shading prefix added to this class's full name.private static byte[]classToByteArray(java.lang.Class<?> clazz)Load the helperClassas a byte array, to be redefined in specifiedClassLoader.private static voidcloseQuietly(java.io.Closeable c)private static byte[]digest(java.security.MessageDigest digest, java.net.URL url)private static byte[]generateUniqueId(int length)private static java.net.URLgetResource(java.lang.String path, java.lang.ClassLoader loader)static voidload(java.lang.String originalName, java.lang.ClassLoader loader)Load the given library with the specifiedClassLoaderstatic voidloadFirstAvailable(java.lang.ClassLoader loader, java.lang.String... names)Loads the first available library in the collection with the specifiedClassLoader.private static voidloadLibrary(java.lang.ClassLoader loader, java.lang.String name, boolean absolute)Loading the native library into the specifiedClassLoader.private static voidloadLibraryByHelper(java.lang.Class<?> helper, java.lang.String name, boolean absolute)private static voidrethrowWithMoreDetailsIfPossible(java.lang.String name, java.lang.NoSuchMethodError error)private static booleanshouldShadedLibraryIdBePatched(java.lang.String packagePrefix)private static booleantryExec(java.lang.String cmd)(package private) static voidtryPatchShadedLibraryIdAndSign(java.io.File libraryFile, java.lang.String originalName)private static java.lang.Class<?>tryToLoadClass(java.lang.ClassLoader loader, java.lang.Class<?> helper)Try to load the helperClassinto specifiedClassLoader.
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
NATIVE_RESOURCE_HOME
private static final java.lang.String NATIVE_RESOURCE_HOME
- See Also:
- Constant Field Values
-
WORKDIR
private static final java.io.File 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
-
-
Method Detail
-
loadFirstAvailable
public static void loadFirstAvailable(java.lang.ClassLoader loader, java.lang.String... names)Loads the first available library in the collection with the specifiedClassLoader.- Throws:
java.lang.IllegalArgumentException- if none of the given libraries load successfully.
-
calculateMangledPackagePrefix
private static java.lang.String 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:
java.lang.UnsatisfiedLinkError- if the shader used something other than a prefix
-
load
public static void load(java.lang.String originalName, java.lang.ClassLoader loader)Load the given library with the specifiedClassLoader
-
getResource
private static java.net.URL getResource(java.lang.String path, java.lang.ClassLoader loader)
-
digest
private static byte[] digest(java.security.MessageDigest digest, java.net.URL url)
-
tryPatchShadedLibraryIdAndSign
static void tryPatchShadedLibraryIdAndSign(java.io.File libraryFile, java.lang.String originalName)
-
tryExec
private static boolean tryExec(java.lang.String cmd)
-
shouldShadedLibraryIdBePatched
private static boolean shouldShadedLibraryIdBePatched(java.lang.String packagePrefix)
-
generateUniqueId
private static byte[] generateUniqueId(int length)
-
loadLibrary
private static void loadLibrary(java.lang.ClassLoader loader, java.lang.String name, boolean absolute)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
private static void rethrowWithMoreDetailsIfPossible(java.lang.String name, java.lang.NoSuchMethodError error)
-
loadLibraryByHelper
private static void loadLibraryByHelper(java.lang.Class<?> helper, java.lang.String name, boolean absolute) throws java.lang.UnsatisfiedLinkError- Throws:
java.lang.UnsatisfiedLinkError
-
tryToLoadClass
private static java.lang.Class<?> tryToLoadClass(java.lang.ClassLoader loader, java.lang.Class<?> helper) throws java.lang.ClassNotFoundExceptionTry 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:
java.lang.ClassNotFoundException- Helper class not found or loading failed
-
classToByteArray
private static byte[] classToByteArray(java.lang.Class<?> clazz) throws java.lang.ClassNotFoundExceptionLoad 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:
java.lang.ClassNotFoundException- Helper class not found or loading failed
-
closeQuietly
private static void closeQuietly(java.io.Closeable c)
-
-