Top Description Inners Fields Constructors Methods
io.netty.util.internal

public final Class NativeLibraryLoader

extends Object
Class Inheritance
Imports
io.netty.util.CharsetUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.ByteArrayOutputStream, .Closeable, .File, .FileNotFoundException, .FileOutputStream, .IOException, .InputStream, .OutputStream, java.lang.reflect.Method, java.net.URL, java.security.AccessController, .MessageDigest, .NoSuchAlgorithmException, .PrivilegedAction, java.util.ArrayList, .Arrays, .Collections, .EnumSet, .Enumeration, .List, .Set

Helper class to load JNI resources.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private 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

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static String
calculateMangledPackagePrefix()

Calculates the mangled shading prefix added to this class's full name.

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 byte[]
digest(MessageDigest digest, URL url)

private static byte[]
generateUniqueId(int length)

private static URL
public static void
load(String originalName, ClassLoader loader)

Load the given library with the specified ClassLoader

public static void
loadFirstAvailable(ClassLoader loader, String... names)

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

private static void
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
)

Loading the native library into the specified ClassLoader.

private static void
loadLibraryByHelper(final Class<?> helper, final String name, final boolean absolute)

private static void
private static boolean
private static boolean
pack-priv static void
tryPatchShadedLibraryIdAndSign(File libraryFile, String originalName)

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_NATIVE_LIB_AFTER_LOADINGback to summary
private static final boolean DELETE_NATIVE_LIB_AFTER_LOADING
DETECT_NATIVE_LIBRARY_DUPLICATESback to summary
private static final boolean DETECT_NATIVE_LIBRARY_DUPLICATES
loggerback to summary
private static final InternalLogger logger
NATIVE_RESOURCE_HOMEback to summary
private static final String NATIVE_RESOURCE_HOME
TRY_TO_PATCH_SHADED_IDback to summary
private static final boolean TRY_TO_PATCH_SHADED_ID
UNIQUE_ID_BYTESback to summary
private static final byte[] UNIQUE_ID_BYTES
WORKDIRback to summary
private static final File WORKDIR

Constructor Detail

NativeLibraryLoaderback to summary
private NativeLibraryLoader()

Method Detail

calculateMangledPackagePrefixback to summary
private static 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:

Exceptions
UnsatisfiedLinkError:
if the shader used something other than a prefix
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)
digestback to summary
private static byte[] digest(MessageDigest digest, URL url)
generateUniqueIdback to summary
private static byte[] generateUniqueId(int length)
getResourceback to summary
private static URL getResource(String path, ClassLoader loader)
loadback to summary
public static void load(String originalName, ClassLoader loader)

Load the given library with the specified ClassLoader

loadFirstAvailableback to summary
public static void loadFirstAvailable(ClassLoader loader, String... names)

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

Exceptions
IllegalArgumentException:
if none of the given libraries load successfully.
loadLibraryback to summary
private static void loadLibrary(final ClassLoader loader, final String name, final boolean absolute)

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

loadLibraryByHelperback to summary
private static void loadLibraryByHelper(final Class<?> helper, final String name, final boolean absolute) throws UnsatisfiedLinkError
rethrowWithMoreDetailsIfPossibleback to summary
private static void rethrowWithMoreDetailsIfPossible(String name, NoSuchMethodError error)
Annotations
@SuppressJava6Requirement
reason:Guarded by version check
shouldShadedLibraryIdBePatchedback to summary
private static boolean shouldShadedLibraryIdBePatched(String packagePrefix)
tryExecback to summary
private static boolean tryExec(String cmd)
tryPatchShadedLibraryIdAndSignback to summary
pack-priv static void tryPatchShadedLibraryIdAndSign(File libraryFile, String originalName)
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
io.netty.util.internal back to summary

private final Class NativeLibraryLoader.NoexecVolumeDetector

extends Object
Class Inheritance
  • java.lang.Object
  • io.netty.util.internal.NativeLibraryLoader.NoexecVolumeDetector

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

NoexecVolumeDetectorback to summary
private NoexecVolumeDetector()

Method Detail

canExecuteExecutableback to summary
private static boolean canExecuteExecutable(File file) throws IOException
Annotations
@SuppressJava6Requirement
reason:Usage guarded by java version check