Klasse Native
- Alle implementierten Schnittstellen:
Version
getTypeMapper(java.lang.Class<?>)
and getStructureAlignment(java.lang.Class<?>)
are provided
to avoid having to explicitly pass these parameters to Structure
s,
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.
Library Loading
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(java.lang.String)
, 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).
Native Library Loading
Native libraries loaded viaload(Class)
may be found in
several locations.- Autor:
- Todd Fast, [email protected], [email protected]
- Siehe auch:
-
Verschachtelte Klassen - Übersicht
Verschachtelte Klassen -
Feldübersicht
FelderModifizierer und TypFeldBeschreibungstatic final int
Size of a nativebool
type (C99 and later), in bytes.(Package privat) static final int
Indicates whether the callback has an initializer.(Package privat) static final int
Use direct mapping for callback.(Package privat) static final int
Return a DLL-resident fucntion pointer.static final boolean
static final boolean
static final Charset
static final String
(Package privat) static final String
(Package privat) static String
static final int
Size of a nativelong double
type (C99 and later), in bytes.static final int
Size of a nativelong
type, in bytes.(Package privat) static final int
(Package privat) static final int
static final int
The size of a native pointer (void*
) on the current platform, in bytes.static final int
Size of a nativesize_t
type, in bytes.static final int
Size of a nativewchar_t
type, in bytes.Von Schnittstelle geerbte Felder com.sun.jna.Version
VERSION, VERSION_NATIVE
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibung(Package privat) static void
close
(long handle) Close the given native library.(Package privat) static long
createNativeCallback
(Callback callback, Method method, Class<?>[] parameterTypes, Class<?> returnType, int callingConvention, int flags, String encoding) Create a native trampoline to delegate execution to the Java callback.(Package privat) static boolean
deleteLibrary
(File lib) Remove any automatically unpacked native library.static void
detach
(boolean detach) Indicate whether the JVM should detach the current native thread when the current Java code finishes execution.static File
Attempt to extract a native library from the current resource path, using the current thread context class loader.static File
extractFromResourcePath
(String name, ClassLoader loader) Attempt to extract a native library from the resource path using the given class loader.static void
ffi_call
(long cif, long fptr, long resp, long args) Make an FFI function call.static void
ffi_free_closure
(long closure) static long
ffi_prep_cif
(int abi, int nargs, long ffi_return_type, long ffi_types) Create a new cif structure.static long
ffi_prep_closure
(long cif, Native.ffi_callback cb) (Package privat) static Class
<?> findDirectMappedClass
(Class<?> cls) Find the nearest enclosing class with native methods.(Package privat) static Class
<?> findEnclosingLibraryClass
(Class<?> cls) Find the library interface corresponding to the given class.(Package privat) static long
findSymbol
(long handle, String name) static void
free
(long ptr) Call the real native free(Package privat) static void
freeNativeCallback
(long ptr) Free the given callback trampoline.(Package privat) static byte
(Package privat) static byte[]
(Package privat) static byte[]
(Package privat) static byte[]
(Package privat) static Class
<?> Try to determine the class context in which aregister(String)
call was made.(Package privat) static char
static long
Utility method to get the native window ID for a heavyweight JavaComponent
as along
value.static Pointer
static String
static Pointer
(Package privat) static ByteBuffer
getDirectByteBuffer
(Pointer pointer, long addr, long offset, long length) (Package privat) static double
(Package privat) static float
(Package privat) static int
static int
Retrieve last error set by the OS.getLibraryOptions
(Class<?> type) Return the preferred native library configuration options for the given class.(Package privat) static long
static NativeLibrary
getNativeLibrary
(Library library) Get theNativeLibrary
instance that is wrapped by the givenLibrary
interface instance.static NativeLibrary
getNativeLibrary
(Class<?> cls) Get theNativeLibrary
instance to which the given "registered" class is bound.static int
getNativeSize
(Class<?> cls) Returns the native size for a given Java class.static int
getNativeSize
(Class<?> type, Object value) (Package privat) static Pointer
getPointer
(long addr) (Package privat) static short
(Package privat) static String
getSignature
(Class<?> cls) (Package privat) static String
(Package privat) static String
(Package privat) static byte[]
getStringBytes
(Pointer pointer, long baseaddr, long offset) static String
getStringEncoding
(Class<?> cls) static int
getStructureAlignment
(Class<?> cls) (Package privat) static File
Obtain a directory suitable for writing JNA-specific temporary files.(Package privat) static Pointer
static TypeMapper
getTypeMapper
(Class<?> cls) Return the preferredTypeMapper
for the given native interface.static String
getWebStartLibraryPath
(String libName) If running web start, determine the location of a given native library.(Package privat) static String
getWideString
(Pointer pointer, long baseaddr, long offset) (Package privat) static long
static long
Utility method to get the native window ID for a JavaWindow
as along
value.static Pointer
(Package privat) static long
(Package privat) static int
initialize_ffi_type
(long type_info) Returns the size (calculated by libffi) of the given type.(Package privat) static double
invokeDouble
(Function function, long fp, int callFlags, Object[] args) Call the native function.(Package privat) static float
invokeFloat
(Function function, long fp, int callFlags, Object[] args) Call the native function.(Package privat) static int
Call the native function.(Package privat) static long
invokeLong
(Function function, long fp, int callFlags, Object[] args) Call the native function.(Package privat) static Object
invokeObject
(Function function, long fp, int callFlags, Object[] args) Call the native function, returning a JavaObject
.(Package privat) static long
invokePointer
(Function function, long fp, int callFlags, Object[] args) Call the native function.(Package privat) static Structure
invokeStructure
(Function function, long fp, int callFlags, Object[] args, Structure s) Call the native function, returning a struct by value.(Package privat) static void
invokeVoid
(Function function, long fp, int callFlags, Object[] args) Call the native function.(Package privat) static boolean
isCompatibleVersion
(String expectedVersion, String nativeVersion) Version string must have the structure. . a bugfix change in the native code increments revision, the minor is incremented for backwards compatible changes and the major version is changed for backwards incompatbile changes. static boolean
Returns whether protection is enabled.static boolean
isSupportedNativeType
(Class<?> cls) (Package privat) static boolean
isUnpacked
(File file) Identify temporary files unpacked from classpath jar files.static <T extends Library>
TMap a library interface to the current process, providing the explicit interface class.static <T extends Library>
TMap a library interface to the current process, providing the explicit interface class.static <T extends Library>
TMap a library interface to the given shared library, providing the explicit interface class.static <T extends Library>
TLoad a library interface from the given shared library, providing the explicit interface class and a map of options for the library.static <T> T
loadLibrary
(Class<T> interfaceClass) Veraltet.static <T> T
loadLibrary
(Class<T> interfaceClass, Map<String, ?> options) Veraltet.static <T> T
loadLibrary
(String name, Class<T> interfaceClass) Veraltet.static <T> T
loadLibrary
(String name, Class<T> interfaceClass, Map<String, ?> options) Veraltet.static void
Prints JNA library details to the console.static long
malloc
(long size) Call the real native malloc(Package privat) static void
markTemporaryFile
(File file) Perform cleanup of automatically unpacked native shared library.(Package privat) static long
Open the requested native library with default options.(Package privat) static long
Open the requested native library with the specified platform-specific otions.(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
static void
register
(NativeLibrary 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.static void
register
(Class<?> cls, NativeLibrary 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.static void
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.static void
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.static boolean
registered
(Class<?> cls) (Package privat) static void
Remove all marked temporary files in the given directory.(Package privat) static String
(Package privat) static void
static void
Set the default handler invoked when a callback throws an uncaught exception.static void
setCallbackThreadInitializer
(Callback cb, CallbackThreadInitializer initializer) Set a thread initializer for the given callback.(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
static void
setLastError
(int code) Set the OS last error code.(Package privat) static void
(Package privat) static void
(Package privat) static void
setPointer
(Pointer pointer, long baseaddr, long offset, long value) static void
setProtected
(boolean enable) Set whether native memory accesses are protected from invalid accesses.(Package privat) static void
(Package privat) static void
setWideString
(Pointer pointer, long baseaddr, long offset, String value) static Library
synchronizedLibrary
(Library library) Returns a synchronized (thread-safe) library backed by the specified library.static byte[]
static byte[]
toByteArray
(String s, String encoding) static byte[]
toByteArray
(String s, Charset charset) static char[]
static String
toString
(byte[] buf) Obtain a Java String from the given native byte array.static String
Obtain a Java String from the given native byte array, using the given encoding.static String
Obtain a Java String from the given native byte array, using the given encoding.static String
toString
(char[] buf) Obtain a Java String from the given native wchar_t array.toStringList
(char[] buf) toStringList
(char[] buf, int offset, int len) static void
Remove all native mappings for the calling class.static void
unregister
(Class<?> cls) Remove all native mappings for the given class.(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
(Package privat) static void
-
Felddetails
-
DEFAULT_CHARSET
-
DEFAULT_ENCODING
-
DEBUG_LOAD
public static final boolean DEBUG_LOAD -
DEBUG_JNA_LOAD
public static final boolean DEBUG_JNA_LOAD -
jnidispatchPath
-
POINTER_SIZE
public static final int POINTER_SIZEThe size of a native pointer (void*
) on the current platform, in bytes. -
LONG_SIZE
public static final int LONG_SIZESize of a nativelong
type, in bytes. -
WCHAR_SIZE
public static final int WCHAR_SIZESize of a nativewchar_t
type, in bytes. -
SIZE_T_SIZE
public static final int SIZE_T_SIZESize of a nativesize_t
type, in bytes. -
BOOL_SIZE
public static final int BOOL_SIZESize of a nativebool
type (C99 and later), in bytes. -
LONG_DOUBLE_SIZE
public static final int LONG_DOUBLE_SIZESize of a nativelong double
type (C99 and later), in bytes. -
MAX_ALIGNMENT
static final int MAX_ALIGNMENT -
MAX_PADDING
static final int MAX_PADDING -
JNA_TMPLIB_PREFIX
- Siehe auch:
-
CB_HAS_INITIALIZER
static final int CB_HAS_INITIALIZERIndicates whether the callback has an initializer.- Siehe auch:
-
CB_OPTION_DIRECT
static final int CB_OPTION_DIRECTUse direct mapping for callback.- Siehe auch:
-
CB_OPTION_IN_DLL
static final int CB_OPTION_IN_DLLReturn a DLL-resident fucntion pointer.- Siehe auch:
-
-
Methodendetails
-
isCompatibleVersion
Version string must have the structure. . a bugfix change in the native code increments revision, the minor is incremented for backwards compatible changes and the major version is changed for backwards incompatbile changes. - Parameter:
expectedVersion
-nativeVersion
-- Gibt zurück:
- true if nativeVersion describes a version compatible to expectedVersion
-
deleteLibrary
Remove any automatically unpacked native library. This will fail on windows, which disallows removal of any file that is still in use, so an alternative is required in that case. Mark the file that could not be deleted, and attempt to delete any temporaries on next startup. Do NOT force the class loader to unload the native library, since that introduces issues with cleaning up any extant JNA bits (e.g. Memory) which may still need use of the library before shutdown. -
setProtected
public static void setProtected(boolean enable) Set whether native memory accesses are protected from invalid accesses. This should only be set true when testing or debugging, and should not be considered reliable or robust for applications where JNA native calls are occurring on multiple threads. Protected mode will be automatically set if the system propertyjna.protected
has a value of "true" when the JNA library is first loaded.If not supported by the underlying platform, this setting will have no effect.
NOTE: On platforms which support signals (non-Windows), JNA uses signals to trap errors. This may interfere with the JVM's own use of signals. When protected mode is enabled, you should make use of the jsig library, if available (see Signal Chaining). In short, set the environment variable
LD_PRELOAD
to the path tolibjsig.so
in your JRE lib directory (usually ${java.home}/lib/${os.arch}/libjsig.so) before launching your Java application. -
isProtected
public static boolean isProtected()Returns whether protection is enabled. Check the result of this method after callingsetProtected(true)
to determine if this platform supports protecting memory accesses. -
getWindowID
Utility method to get the native window ID for a JavaWindow
as along
value. This method is primarily for X11-based systems, which use an opaqueXID
(usuallylong int
) to identify windows.- Löst aus:
HeadlessException
- if the current VM is running headless
-
getComponentID
Utility method to get the native window ID for a heavyweight JavaComponent
as along
value. This method is primarily for X11-based systems, which use an opaqueXID
(usuallylong int
) to identify windows.- Löst aus:
HeadlessException
- if the current VM is running headless
-
getWindowPointer
Utility method to get the native window pointer for a JavaWindow
as aPointer
value. This method is primarily for w32, which uses theHANDLE
type (actuallyvoid *
) to identify windows.- Löst aus:
HeadlessException
- if the current VM is running headless
-
getComponentPointer
Utility method to get the native window pointer for a heavyweight JavaComponent
as aPointer
value. This method is primarily for w32, which uses theHWND
type (actuallyvoid *
) to identify windows.- Löst aus:
HeadlessException
- if the current VM is running headless
-
getWindowHandle0
-
getDirectBufferPointer
- Löst aus:
IllegalArgumentException
- if the buffer is not direct.
-
toString
Obtain a Java String from the given native byte array. If there is no NUL terminator, the String will comprise the entire array. The encoding is obtained fromgetDefaultStringEncoding()
.- Parameter:
buf
- The buffer containing the encoded bytes- Siehe auch:
-
toString
Obtain a Java String from the given native byte array, using the given encoding. If there is no NUL terminator, the String will comprise the entire array.Usage note: This function assumes, that
buf
holds achar
array. This means only single-byte encodings are supported.- Parameter:
buf
- The buffer containing the encoded bytes. Must not benull
.encoding
- The encoding name - ifnull
then the platform default encoding will be used
-
toString
Obtain a Java String from the given native byte array, using the given encoding. If there is no NUL terminator, the String will comprise the entire array.Usage note: This function assumes, that
buf
holds achar
array. This means only single-byte encodings are supported.- Parameter:
buf
- The buffer containing the encoded bytes. Must not benull
.charset
- The charset to decodebuf
. Must not benull
.
-
toString
Obtain a Java String from the given native wchar_t array. If there is no NUL terminator, the String will comprise the entire array.- Parameter:
buf
- The buffer containing the characters
-
toStringList
Converts a "list" of strings each null terminated into aList
ofString
values. The end of the list is signaled by an extra NULL value at the end or by the end of the buffer.- Parameter:
buf
- The buffer containing the strings- Gibt zurück:
- A
List
of all the strings in the buffer - Siehe auch:
-
toStringList
Converts a "list" of strings each null terminated into aList
ofString
values. The end of the list is signaled by an extra NULL value at the end or by the end of the data.- Parameter:
buf
- The buffer containing the stringsoffset
- Offset to start parsinglen
- The total characters to parse- Gibt zurück:
- A
List
of all the strings in the buffer
-
load
Map a library interface to the current process, providing the explicit interface class. Native libraries loaded via this method may be found in several locations.- Typparameter:
T
- Type of expected wrapper- Parameter:
interfaceClass
- The implementation wrapper interface- Gibt zurück:
- an instance of the requested interface, mapped to the current process.
- Löst aus:
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.
-
load
Map a library interface to the current process, providing the explicit interface class. Any options provided for the library are cached and associated with the library and any of its defined structures and/or functions. Native libraries loaded via this method may be found in several locations.- Typparameter:
T
- Type of expected wrapper- Parameter:
interfaceClass
- The implementation wrapper interfaceoptions
- Map of library options- Gibt zurück:
- an instance of the requested interface, mapped to the current process.
- Löst aus:
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.- Siehe auch:
-
load
Map a library interface to the given shared library, providing the explicit interface class. Ifname
is null, attempts to map onto the current process. Native libraries loaded via this method may be found in several locations.- Typparameter:
T
- Type of expected wrapper- Parameter:
name
- Library base nameinterfaceClass
- The implementation wrapper interface- Gibt zurück:
- an instance of the requested interface, mapped to the indicated native library.
- Löst aus:
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.- Siehe auch:
-
load
public static <T extends Library> T load(String name, Class<T> interfaceClass, Map<String, ?> options) Load a library interface from the given shared library, providing the explicit interface class and a map of options for the library. If no library options are detected the map is interpreted as a map of Java method names to native function names.If
name
is null, attempts to map onto the current process. Native libraries loaded via this method may be found in several locations.- Typparameter:
T
- Type of expected wrapper- Parameter:
name
- Library base nameinterfaceClass
- The implementation wrapper interfaceoptions
- Map of library options- Gibt zurück:
- an instance of the requested interface, mapped to the indicated native library.
- Löst aus:
UnsatisfiedLinkError
- if the library cannot be found or dependent libraries are missing.
-
loadLibrary
Veraltet.Provided for improved compatibility between JNA 4.X and 5.X- Siehe auch:
-
loadLibrary
Veraltet.Provided for improved compatibility between JNA 4.X and 5.X- Siehe auch:
-
loadLibrary
Veraltet.Provided for improved compatibility between JNA 4.X and 5.X- Siehe auch:
-
loadLibrary
@Deprecated public static <T> T loadLibrary(String name, Class<T> interfaceClass, Map<String, ?> options) Veraltet.Provided for improved compatibility between JNA 4.X and 5.X- Siehe auch:
-
findEnclosingLibraryClass
Find the library interface corresponding to the given class. Checks all ancestor classes and interfaces for a declaring class which implementsLibrary
.- Parameter:
cls
- The given class- Gibt zurück:
- The enclosing class
-
getLibraryOptions
Return the preferred native library configuration options for the given class. First attempts to load any field of the interface type within the interface mapping, then checks the cache for any specified library options. If none found, a set of library options will be generated from the fields (by order of precedence)OPTIONS
(aMap
),TYPE_MAPPER
(aTypeMapper
),STRUCTURE_ALIGNMENT
(anInteger
), andSTRING_ENCODING
(aString
).- Parameter:
type
- The type class- Gibt zurück:
- The options map
-
getTypeMapper
Return the preferredTypeMapper
for the given native interface. SeeLibrary.OPTION_TYPE_MAPPER
. -
getStringEncoding
- Parameter:
cls
- The native interface type- Gibt zurück:
- The preferred string encoding for the given native interface.
If there is no setting, defaults to the
getDefaultStringEncoding()
. - Siehe auch:
-
getDefaultStringEncoding
- Gibt zurück:
- The default string encoding. Returns the value of the system
property
jna.encoding
orDEFAULT_ENCODING
.
-
getStructureAlignment
- Parameter:
cls
- The native interface type- Gibt zurück:
- The preferred structure alignment for the given native interface.
- Siehe auch:
-
getBytes
- Parameter:
s
- The input string- Gibt zurück:
- A byte array corresponding to the given String. The encoding
used is obtained from
getDefaultStringEncoding()
.
-
getBytes
- Parameter:
s
- The string. Must not benull
.encoding
- The encoding - ifnull
then the default platform encoding is used- Gibt zurück:
- A byte array corresponding to the given String, using the given encoding. If the encoding is not found default to the platform native encoding.
-
getBytes
- Parameter:
s
- The string. Must not benull
.charset
- The charset used to encodes
. Must not benull
.- Gibt zurück:
- A byte array corresponding to the given String, using the given charset.
-
toByteArray
- Parameter:
s
- The string- Gibt zurück:
- A NUL-terminated byte buffer equivalent to the given String,
using the encoding returned by
getDefaultStringEncoding()
. - Siehe auch:
-
toByteArray
- Parameter:
s
- The string. Must not benull
.encoding
- The encoding - ifnull
then the default platform encoding is used- Gibt zurück:
- A NUL-terminated byte buffer equivalent to the given String, using the given encoding.
- Siehe auch:
-
toByteArray
- Parameter:
s
- The string. Must not benull
.charset
- The charset used to encodes
. Must not benull
.- Gibt zurück:
- A NUL-terminated byte buffer equivalent to the given String, using the given charset.
- Siehe auch:
-
toCharArray
- Parameter:
s
- The string- Gibt zurück:
- A NUL-terminated wide character buffer equivalent to the given string.
-
isUnpacked
Identify temporary files unpacked from classpath jar files. -
extractFromResourcePath
Attempt to extract a native library from the current resource path, using the current thread context class loader.- Parameter:
name
- Base 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 withoutPlatform.RESOURCE_PREFIX
, after mapping the library name viaNativeLibrary.mapSharedLibraryName(String)
.- Gibt zurück:
- File indicating extracted resource on disk
- Löst aus:
IOException
- if resource not found
-
extractFromResourcePath
Attempt to extract a native library from the resource path using the given class loader.- Parameter:
name
- Base 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 withoutPlatform.RESOURCE_PREFIX
, after mapping the library name viaNativeLibrary.mapSharedLibraryName(String)
.loader
- Class loader to use to load resources- Gibt zurück:
- File indicating extracted resource on disk
- Löst aus:
IOException
- if resource not found
-
getLastError
public static int getLastError()Retrieve last error set by the OS. This corresponds toGetLastError()
on Windows, anderrno
on most other platforms. The value is preserved per-thread, but whether the original value is per-thread depends on the underlying OS.An alternative method of obtaining the last error result is to declare your mapped method to throw
LastErrorException
instead. If a method's signature includes a throw ofLastErrorException
, the last error will be set to zero before the native call and aLastErrorException
will be raised if the last error value is non-zero after the call, regardless of the actual returned value from the native function. -
setLastError
public static void setLastError(int code) Set the OS last error code. The value will be saved on a per-thread basis. -
synchronizedLibrary
Returns a synchronized (thread-safe) library backed by the specified library. This wrapping will prevent simultaneous invocations of any functions mapped to a givenNativeLibrary
. Note that the native library may still be sensitive to being called from different threads.- Parameter:
library
- the library to be "wrapped" in a synchronized library.- Gibt zurück:
- a synchronized view of the specified library.
-
getWebStartLibraryPath
If running web start, determine the location of a given native library. This value may be used to properly setjna.library.path
so that JNA can load libraries identified by the <nativelib> tag in the JNLP configuration file. Returnsnull
if the Web Start native library cache location can not be determined. Note that the path returned may be different for any given library name.Use
System.getProperty("javawebstart.version")
to detect whether your code is running under Web Start.- Gibt zurück:
- null if unable to query the web start loader.
- Löst aus:
UnsatisfiedLinkError
- if the library can't be found by the Web Start class loader, which usually means it wasn't included as a<nativelib>
resource in the JNLP file.
-
markTemporaryFile
Perform cleanup of automatically unpacked native shared library. -
getTempDir
Obtain a directory suitable for writing JNA-specific temporary files. Override withjna.tmpdir
- Löst aus:
IOException
-
removeTemporaryFiles
Remove all marked temporary files in the given directory.- Löst aus:
IOException
-
getNativeSize
- Parameter:
type
- The Java class for which the native size is to be determinedvalue
- an instance of said class (if available)- Gibt zurück:
- the native size of the given class, in bytes. For use with arrays.
-
getNativeSize
Returns the native size for a given Java class. Structures are assumed to bestruct
pointers unless they implementStructure.ByValue
.- Parameter:
cls
- The Java class- Gibt zurück:
- The native size for the class
-
isSupportedNativeType
- Parameter:
cls
- The Java class- Gibt zurück:
true
whether the given class is supported as a native argument type.
-
setCallbackExceptionHandler
Set the default handler invoked when a callback throws an uncaught exception. If the given handler isnull
, the default handler will be reinstated.- Parameter:
eh
- The default handler
-
getCallbackExceptionHandler
- Gibt zurück:
- the current handler for callback uncaught exceptions.
-
register
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.- Parameter:
libName
- library name to which functions should be bound
-
register
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.- Parameter:
lib
- native library to which functions should be bound
-
findDirectMappedClass
Find the nearest enclosing class with native methods. -
getCallingClass
Try to determine the class context in which aregister(String)
call was made. -
setCallbackThreadInitializer
Set a thread initializer for the given callback.- Parameter:
cb
- The callback to invokeinitializer
- The thread initializer indicates desired thread configuration when the given Callback is invoked on a native thread not yet attached to the VM.
-
unregister
public static void unregister()Remove all native mappings for the calling class. Should only be called if the class is no longer referenced and about to be garbage collected. -
unregister
Remove all native mappings for the given class. Should only be called if the class is no longer referenced and about to be garbage collected. -
registered
- Parameter:
cls
- The typeClass
- Gibt zurück:
- whether the given class's native components are registered.
-
getSignature
-
replace
-
register
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface. Uses the class loader of the given class to search for the native library in the resource path if it is not found in the system library load path orjna.library.path
.- Parameter:
cls
- Class with native methods to registerlibName
- name of or path to native library to which functions should be bound
-
register
When called from a class static initializer, maps all native methods found within that class to native libraries via the JNA raw calling interface.- Parameter:
cls
- Class with native methods to registerlib
- library to which functions should be bound
-
getNativeLibrary
Get theNativeLibrary
instance that is wrapped by the givenLibrary
interface instance.- Parameter:
library
- theLibrary
interface instance, which was created by theNative.load()
method- Gibt zurück:
- the wrapped
NativeLibrary
instance
-
getNativeLibrary
Get theNativeLibrary
instance to which the given "registered" class is bound.- Parameter:
cls
- the "registered" class, which was previously registered via theregister()
method- Gibt zurück:
- the
NativeLibrary
instance to which the "registered" class is bound
-
ffi_prep_cif
public static long ffi_prep_cif(int abi, int nargs, long ffi_return_type, long ffi_types) Create a new cif structure. -
ffi_call
public static void ffi_call(long cif, long fptr, long resp, long args) Make an FFI function call. -
ffi_prep_closure
-
ffi_free_closure
public static void ffi_free_closure(long closure) -
initialize_ffi_type
static int initialize_ffi_type(long type_info) Returns the size (calculated by libffi) of the given type. -
main
Prints JNA library details to the console. -
freeNativeCallback
static void freeNativeCallback(long ptr) Free the given callback trampoline. -
createNativeCallback
static long createNativeCallback(Callback callback, Method method, Class<?>[] parameterTypes, Class<?> returnType, int callingConvention, int flags, String encoding) Create a native trampoline to delegate execution to the Java callback. -
invokeInt
Call the native function.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- The value returned by the target native function
-
invokeLong
Call the native function.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- The value returned by the target native function
-
invokeVoid
Call the native function.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function
-
invokeFloat
Call the native function.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- The value returned by the target native function
-
invokeDouble
Call the native function.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- The value returned by the target native function
-
invokePointer
Call the native function.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- The value returned by the target native function
-
invokeStructure
static Structure invokeStructure(Function function, long fp, int callFlags, Object[] args, Structure s) Call the native function, returning a struct by value.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- the passed-in Structure
-
invokeObject
Call the native function, returning a JavaObject
.- Parameter:
function
- Present to prevent the GC to collect the Function object prematurelyfp
- function pointercallFlags
- calling convention to be usedargs
- Arguments to pass to the native function- Gibt zurück:
- The returned Java
Object
-
open
Open the requested native library with default options. -
open
Open the requested native library with the specified platform-specific otions. -
close
static void close(long handle) Close the given native library. -
findSymbol
-
indexOf
-
read
-
read
-
read
-
read
-
read
-
read
-
read
-
write
-
write
-
write
-
write
-
write
-
write
-
write
-
getByte
-
getChar
-
getShort
-
getInt
-
getLong
-
getFloat
-
getDouble
-
getPointer
-
getWideString
-
getString
-
getString
-
getStringBytes
-
setMemory
-
setByte
-
setShort
-
setChar
-
setInt
-
setLong
-
setFloat
-
setDouble
-
setPointer
-
setWideString
-
getDirectByteBuffer
-
malloc
public static long malloc(long size) Call the real native malloc- Parameter:
size
- size of the memory to be allocated- Gibt zurück:
- native address of the allocated memory block; zero if the allocation failed.
-
free
public static void free(long ptr) Call the real native free- Parameter:
ptr
- native address to be freed; a value of zero has no effect, passing an already-freed pointer will cause pain.
-
detach
public static void detach(boolean detach) Indicate whether the JVM should detach the current native thread when the current Java code finishes execution. Generally this is used to avoid detaching native threads when it is known that a given thread will be relatively long-lived and call back to Java code frequently.
This call is lightweight; it only results in an additional JNI crossing if the desired state changes from its last setting.- Löst aus:
IllegalStateException
- ifdetach(true)
is called on a thread created by the JVM.
-
getTerminationFlag
-