Package io.netty.util.internal
Class NativeLibraryLoader
- java.lang.Object
-
- io.netty.util.internal.NativeLibraryLoader
-
public final class NativeLibraryLoader extends java.lang.Object
Helper class to load JNI resources.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
NativeLibraryLoader.NoexecVolumeDetector
-
Field Summary
Fields Modifier and Type Field Description private static boolean
DELETE_NATIVE_LIB_AFTER_LOADING
private static InternalLogger
logger
private static java.lang.String
NATIVE_RESOURCE_HOME
private static boolean
TRY_TO_PATCH_SHADED_ID
private static byte[]
UNIQUE_ID_BYTES
private static java.io.File
WORKDIR
-
Constructor Summary
Constructors Modifier Constructor Description private
NativeLibraryLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
calculatePackagePrefix()
The shading prefix added to this class's full name.private static byte[]
classToByteArray(java.lang.Class<?> clazz)
Load the helperClass
as a byte array, to be redefined in specifiedClassLoader
.private static void
closeQuietly(java.io.Closeable c)
static void
load(java.lang.String originalName, java.lang.ClassLoader loader)
Load the given library with the specifiedClassLoader
static void
loadFirstAvailable(java.lang.ClassLoader loader, java.lang.String... names)
Loads the first available library in the collection with the specifiedClassLoader
.private static void
loadLibrary(java.lang.ClassLoader loader, java.lang.String name, boolean absolute)
Loading the native library into the specifiedClassLoader
.private static void
loadLibraryByHelper(java.lang.Class<?> helper, java.lang.String name, boolean absolute)
private static boolean
patchShadedLibraryId(byte[] bytes, java.lang.String originalName, java.lang.String name)
Try to patch shaded library to ensure it uses a unique ID.(package private) static boolean
patchShadedLibraryId(java.io.InputStream in, java.io.OutputStream out, java.lang.String originalName, java.lang.String name)
private static boolean
shouldShadedLibraryIdBePatched(java.lang.String packagePrefix)
private static java.lang.Class<?>
tryToLoadClass(java.lang.ClassLoader loader, java.lang.Class<?> helper)
Try to load the helperClass
into 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
-
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.
-
calculatePackagePrefix
private static java.lang.String calculatePackagePrefix()
The shading prefix added to this class's full name.- 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
-
patchShadedLibraryId
static boolean patchShadedLibraryId(java.io.InputStream in, java.io.OutputStream out, java.lang.String originalName, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
shouldShadedLibraryIdBePatched
private static boolean shouldShadedLibraryIdBePatched(java.lang.String packagePrefix)
-
patchShadedLibraryId
private static boolean patchShadedLibraryId(byte[] bytes, java.lang.String originalName, java.lang.String name)
Try to patch shaded library to ensure it uses a unique ID.
-
loadLibrary
private static void loadLibrary(java.lang.ClassLoader loader, java.lang.String name, boolean absolute)
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
-
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.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:
java.lang.ClassNotFoundException
- Helper class not found or loading failed
-
classToByteArray
private static byte[] classToByteArray(java.lang.Class<?> clazz) throws java.lang.ClassNotFoundException
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:
java.lang.ClassNotFoundException
- Helper class not found or loading failed
-
closeQuietly
private static void closeQuietly(java.io.Closeable c)
-
-