getTypeMapper and getStructureAlignment are provided
to avoid having to explicitly pass these parameters to Structures,
which would require every Structure which requires custom mapping
or alignment to define a constructor and pass parameters to the superclass.
To avoid lots of boilerplate, the base Structure constructor
figures out these properties based on its enclosing interface.
When JNA classes are loaded, the native shared library (jnidispatch) is
loaded as well. An attempt is made to load it from the any paths defined
in jna.boot.library.path (if defined), then the system library
path using System#loadLibrary, unless jna.nosys=true.
If not found, the appropriate library will be extracted from the class path
(into a temporary directory if found within a jar file) and loaded from
there, unless jna.noclasspath=true. If your system has
additional security constraints regarding execution or load of files
(SELinux, for example), you should probably install the native library in
an accessible location and configure your system accordingly, rather than
relying on JNA to extract the library from its own jar file.
To avoid the automatic unpacking (in situations where you want to force a
failure if the JNA native library is not properly installed on the system),
set the system property jna.nounpack=true.
While this class and its corresponding native library are loaded, the
system property jna.loaded will be set. The property will be
cleared when native support has been unloaded (i.e. the Native class and
its underlying native support has been GC'd).
Note
all native functions are provided within this class to ensure that all other JNA-provided classes and objects are GC'd and/or finalized/disposed before this class is disposed and/or removed from memory (most notably Memory and any other class which by default frees its resources in a finalizer).
load(Class) may be found in
several locations.
Library
| Modifier and Type | Class and Description |
|---|---|
| private static class | Native.AWT
Provides separation of JAWT functionality for the sake of J2ME ports which do not include AWT support. |
| private static class | |
| public static interface |
| Modifier and Type | Field and Description |
|---|---|
| private static final String | |
| public static final int | BOOL_SIZE
Size of a native |
| private static Callback. | |
| pack-priv static final int | CB_HAS_INITIALIZER
Indicates whether the callback has an initializer. |
| pack-priv static final int | CB_OPTION_DIRECT
Use direct mapping for callback. |
| pack-priv static final int | CB_OPTION_IN_DLL
Return a DLL-resident fucntion pointer. |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| public static final boolean | |
| private static final Level | |
| public static final boolean | |
| public static final Charset | |
| public static final String | |
| private static final Callback. | |
| private static final Object | finalizer
Force a dispose when the Native class is GC'd. |
| pack-priv static final String | |
| pack-priv static String | |
| private static final Map | |
| private static final Logger | |
| public static final int | LONG_DOUBLE_SIZE
Size of a native |
| public static final int | LONG_SIZE
Size of a native |
| pack-priv static final int | |
| pack-priv static final int | |
| private static final Map | |
| private static final ThreadLocal | |
| public static final int | POINTER_SIZE
The size of a native pointer ( |
| private static final Map | |
| private static final Map | |
| public static final int | SIZE_T_SIZE
Size of a native |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final Map | |
| public static final int | WCHAR_SIZE
Size of a native |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private static native long | |
| private static native long | |
| private static Map | |
| pack-priv static native void | |
| pack-priv static synchronized native long | |
| pack-priv static boolean | |
| public static void | detach(boolean detach)
Indicate whether the JVM should detach the current native thread when the current Java code finishes execution. |
| private static void | |
| public static File | Returns: File indicating extracted resource on diskBase name of native library to extract. May also be an
absolute resource path (i.e. starts with "/"), in which case the
no transformations of the library name are performed. If only the base
name is given, the resource path is attempted both with and without
name)Platform#RESOURCE_PREFIX, after mapping the library name via
NativeLibrary#mapSharedLibraryName(String).Attempt to extract a native library from the current resource path, using the current thread context class loader. |
| public static File | Returns: File indicating extracted resource on diskBase name of native library to extract. May also be an
absolute resource path (i.e. starts with "/"), in which case the
no transformations of the library name are performed. If only the base
name is given, the resource path is attempted both with and without
name, ClassLoader Platform#RESOURCE_PREFIX, after mapping the library name via
NativeLibrary#mapSharedLibraryName(String).Class loader to use to load resources loader)Attempt to extract a native library from the resource path using the given class loader. |
| public static native void | |
| public static native void | |
| public static native long | |
| public static native long | |
| pack-priv static Class | |
| pack-priv static Class | Returns: The enclosing classThe given class cls)Find the library interface corresponding to the given class. |
| pack-priv static native long | |
| public static native void | free(long
native address to be freed; a value of zero has no effect,
passing an already-freed pointer will cause pain. ptr)Call the real native free |
| pack-priv static synchronized native void | |
| private static NativeMapped | |
| private static NativeMapped | |
| private static Object | |
| private static native String | |
| pack-priv static native byte | |
| pack-priv static byte[] | Returns: A byte array corresponding to the given String. The encoding used is obtained fromgetDefaultStringEncoding().The input string s)
|
| pack-priv static byte[] | |
| pack-priv static byte[] | |
| public static Callback. | |
| pack-priv static Class | |
| pack-priv static native char | |
| private static Charset | Returns: The charset belonging to the givenencoding or the platform default.
Never null.The encoding - if encoding)null then the default platform
encoding is used.Gets the charset belonging to the given |
| public static long | getComponentID(Component c)
Utility method to get the native window ID for a heavyweight Java
|
| public static Pointer | getComponentPointer(Component c)
Utility method to get the native window pointer for a heavyweight Java
|
| private static int | |
| public static String | Returns: The default string encoding. Returns the value of the system propertyjna.encoding or Native#DEFAULT_ENCODING.
|
| public static Pointer | |
| pack-priv static native ByteBuffer | |
| pack-priv static native double | |
| pack-priv static native float | |
| pack-priv static native int | |
| public static native int | |
| public static Map | Returns: The options mapThe type class type)Return the preferred native library configuration options for the given class. |
| pack-priv static native long | |
| public static int | Returns: the native size of the given class, in bytes. For use with arrays.The Java class for which the native size is to be determined type, Object an instance of said class (if available) value)
|
| public static int | Returns: The native size for the classThe Java class cls)Returns the native size for a given Java class. |
| private static native String | |
| pack-priv static Pointer | |
| pack-priv static native short | |
| pack-priv static String | |
| pack-priv static String | |
| pack-priv static String | |
| pack-priv static native byte[] | |
| public static String | Returns: The preferred string encoding for the given native interface. If there is no setting, defaults to thegetDefaultStringEncoding().The native interface type cls)
|
| public static int | Returns: The preferred structure alignment for the given native interface.The native interface type cls)
|
| pack-priv static File | |
| pack-priv static Pointer | |
| public static TypeMapper | |
| public static String | Returns: null if unable to query the web start loader.If running web start, determine the location of a given native library. |
| pack-priv static native String | |
| pack-priv static native long | |
| public static long | |
| public static Pointer | getWindowPointer(Window w)
Utility method to get the native window pointer for a Java
|
| pack-priv static native long | |
| pack-priv static native int | |
| private static native void | |
| pack-priv static native double | Returns: The value returned by the target native functionPresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function. |
| pack-priv static native float | Returns: The value returned by the target native functionPresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function. |
| pack-priv static native int | Returns: The value returned by the target native functionPresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function. |
| pack-priv static native long | Returns: The value returned by the target native functionPresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function. |
| pack-priv static native Object | Returns: The returned JavaObjectPresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function, returning a Java |
| pack-priv static native long | Returns: The value returned by the target native functionPresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function. |
| private static native void | invokeStructure(Function
Present to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args, long Memory for pre-allocated structure to hold the result memory, long Native type information for the Structure type_info)Call the native function, returning a struct by value. |
| pack-priv static Structure | Returns: the passed-in StructurePresent to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args, Structure s)Call the native function, returning a struct by value. |
| pack-priv static native void | invokeVoid(Function
Present to prevent the GC to collect the Function object
prematurely function, long function pointer fp, int calling convention to be used callFlags, Object[] Arguments to pass to the native function args)Call the native function. |
| pack-priv static boolean | Returns: true if nativeVersion describes a version compatible to expectedVersionVersion string must have the structure <major>. |
| public static synchronized native boolean | |
| public static boolean | Returns: true whether the given class is supported as a native argument type.The Java class cls)
|
| pack-priv static boolean | |
| public static < Type of expected wrapper T extends Library> T | |
| public static < Type of expected wrapper T extends Library> T | |
| public static < Type of expected wrapper T extends Library> T | |
| public static < Type of expected wrapper T extends Library> T | Returns: an instance of the requested interface, mapped to the indicated native library.Library base name name, Class<T> The implementation wrapper interface interfaceClass, Map<String, ?> Map of library options options)Load a library interface from the given shared library, providing the explicit interface class and a map of options for the library. |
| public static <T> T | loadLibrary(Class<T> interfaceClass)
Deprecated
Provided for improved compatibility between JNA 4.X and 5.X
|
| public static <T> T | loadLibrary(Class<T> interfaceClass, Map<String, ?> options)
Deprecated
Provided for improved compatibility between JNA 4.X and 5.X
|
| public static <T> T | loadLibrary(String name, Class<T> interfaceClass)
Deprecated
Provided for improved compatibility between JNA 4.X and 5.X
|
| public static <T> T | loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options)
Deprecated
Provided for improved compatibility between JNA 4.X and 5.X
|
| private static void | loadLibraryInstance(Class<?> cls)
Attempts to force initialization of an instance of the library interface by loading a public static field of the requisite type. |
| private static void | |
| private static void | loadNativeDispatchLibraryFromClasspath()
Attempts to load the native library resource from the filesystem, extracting the JNA stub library from jna.jar if not already available. |
| private static Object | |
| public static void | |
| public static native long | Returns: native address of the allocated memory block; zero if the allocation failed.size of the memory to be allocated size)Call the real native malloc |
| pack-priv static void | |
| private static Class | |
| pack-priv static long | |
| pack-priv static native long | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| public static void | |
| public static void | register(NativeLibrary
native library to which functions should be bound lib)When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface. |
| public static void | |
| public static void | register(Class<?>
Class with native methods to register cls, NativeLibrary library to which functions should be bound lib)When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface. |
| public static boolean | Returns: whether the given class's native components are registered.The type cls)Class
|
| private static native long | registerMethod(Class<?> cls, String name, String signature, int[] conversions, long[] closure_arg_types, long[] arg_types, int rconversion, long closure_rtype, long rtype, Method method, long fptr, int callingConvention, boolean throwLastError, ToNativeConverter[] toNative, FromNativeConverter fromNative, String encoding)
|
| pack-priv static void | |
| pack-priv static String | |
| pack-priv static native void | |
| public static void | setCallbackExceptionHandler(Callback.
The default handler ehSet the default handler invoked when a callback throws an uncaught exception. |
| public static void | setCallbackThreadInitializer(Callback
The callback to invoke cb, CallbackThreadInitializer The thread initializer indicates desired thread configuration when the
given Callback is invoked on a native thread not yet attached to the VM. initializer)Set a thread initializer for the given callback. |
| pack-priv static native void | |
| private static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| public static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| public static synchronized native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| private static native int | |
| public static Library | Returns: a synchronized view of the specified library.the library to be "wrapped" in a synchronized library. library)Returns a synchronized (thread-safe) library backed by the specified library. |
| public static byte[] | Returns: A NUL-terminated byte buffer equivalent to the given String, using the encoding returned bygetDefaultStringEncoding().The string s)
|
| public static byte[] | Returns: A NUL-terminated byte buffer equivalent to the given String, using the given encoding.The string. Must not be s, String null.The encoding - if encoding)null then the default platform
encoding is used
|
| public static byte[] | Returns: A NUL-terminated byte buffer equivalent to the given String, using the given charset.The string. Must not be s, Charset null.The charset used to encode charset)s. Must not be null.
|
| public static char[] | Returns: A NUL-terminated wide character buffer equivalent to the given string.The string s)
|
| private static Object | |
| public static String | toString(byte[]
The buffer containing the encoded bytes buf)Obtain a Java String from the given native byte array. |
| public static String | |
| public static String | |
| public static String | toString(char[]
The buffer containing the characters buf)Obtain a Java String from the given native wchar_t array. |
| public static List | Returns: AList of all the strings in the bufferThe buffer containing the strings buf)Converts a "list" of strings each null terminated
into a |
| public static List | Returns: AList of all the strings in the bufferThe buffer containing the strings buf, int Offset to start parsing offset, int The total characters to parse len)Converts a "list" of strings each null terminated
into a |
| public static void | |
| public static void | |
| private static native void | |
| private static void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void | |
| pack-priv static native void |