public class Loader extends Object
offsetof() or sizeof() a native
struct, class, or union with its Pointer peer class
and a HashMap initialized by the native libraries inside JNI_OnLoad().| Modifier and Type | Field and Description |
|---|---|
(package private) static Map<String,String> |
loadedLibraries
Contains all the native libraries that we have loaded to avoid reloading them.
|
(package private) static boolean |
loadLibraries
Flag set by the
Builder to tell us not to try to load anything. |
(package private) static WeakHashMap<Class<? extends Pointer>,HashMap<String,Integer>> |
memberOffsets
Contains
offsetof() and sizeof() values of native types
of struct, class, and union. |
private static String |
platform
Value created out of "java.vm.name", "os.name", and "os.arch" system properties.
|
private static Properties |
platformProperties
Default platform properties loaded and returned by
loadProperties(). |
(package private) static File |
tempDir
Temporary directory set and returned by
getTempDir(). |
| Constructor and Description |
|---|
Loader() |
| Modifier and Type | Method and Description |
|---|---|
static File |
extractResource(Class cls,
String name,
File directory,
String prefix,
String suffix)
Extracts by name a resource using the
ClassLoader of the specified Class. |
static File |
extractResource(String name,
File directory,
String prefix,
String suffix)
Extracts by name a resource using the
ClassLoader of the caller. |
static File |
extractResource(URL resourceURL,
File directory,
String prefix,
String suffix)
Extracts a resource into the specified directory and with the specified
prefix and suffix for the filename.
|
static URL[] |
findLibrary(Class cls,
ClassProperties properties,
String libnameversion)
Finds where the library may be extracted and loaded among the
Class
resources. |
static Class |
getCallerClass(int i)
Returns the
Class object that contains a caller's method. |
static Class |
getEnclosingClass(Class cls)
If annotated with properties, returns the argument as "enclosing Class".
|
static String |
getPlatform()
Returns either the value of the "org.bytedeco.javacpp.platform"
system property, or
platform when the former is not set. |
static File |
getTempDir()
Creates a unique name for
tempDir out of
System.getProperty("java.io.tmpdir") and System.nanoTime(). |
static boolean |
isLoadLibraries() |
static String |
load()
Loads native libraries associated with the
Class of the caller. |
static String |
load(Class cls)
Loads native libraries associated with the given
Class. |
static String |
loadLibrary(URL[] urls,
String libnameversion)
Tries to load the library from the URLs in order, extracting resources as necessary.
|
static Properties |
loadProperties()
Loads the
Properties associated with the default getPlatform(). |
static ClassProperties |
loadProperties(Class[] cls,
Properties properties,
boolean inherit)
For all the classes, loads all properties from each Class annotations for the given platform.
|
static ClassProperties |
loadProperties(Class cls,
Properties properties,
boolean inherit)
Loads all properties from Class annotations for the given platform.
|
static Properties |
loadProperties(String name)
Loads from resources the default
Properties of the specified platform name. |
static void |
main(String[] args) |
static int |
offsetof(Class<? extends Pointer> type,
String member)
Gets
offsetof() values from memberOffsets filled by native libraries. |
(package private) static void |
putMemberOffset(Class<? extends Pointer> type,
String member,
int offset)
|
(package private) static void |
putMemberOffset(String typeName,
String member,
int offset)
|
static int |
sizeof(Class<? extends Pointer> type)
Gets
sizeof() values from memberOffsets filled by native libraries. |
private static final String platform
getPlatform() as default.private static Properties platformProperties
loadProperties().static File tempDir
getTempDir().static boolean loadLibraries
Builder to tell us not to try to load anything.static Map<String,String> loadedLibraries
static WeakHashMap<Class<? extends Pointer>,HashMap<String,Integer>> memberOffsets
offsetof() and sizeof() values of native types
of struct, class, and union. A WeakHashMap
is used to prevent the Loader from hanging onto Class objects the user may
be trying to unload.public static String getPlatform()
platform when the former is not set.System.getProperty("org.bytedeco.javacpp.platform", platform)platformpublic static Properties loadProperties()
Properties associated with the default getPlatform().loadProperties(String)public static Properties loadProperties(String name)
Properties of the specified platform name.name - the platform namepublic static Class getEnclosingClass(Class cls)
cls - the Class to start the search fromPlatform,
Propertiespublic static ClassProperties loadProperties(Class[] cls, Properties properties, boolean inherit)
public static ClassProperties loadProperties(Class cls, Properties properties, boolean inherit)
Properties.inherit()
annotation recursively via the inherit argument.cls - the Class of which to return Propertiesproperties - the platform Properties to inheritinherit - indicates whether or not to inherit properties from other classespublic static Class getCallerClass(int i)
Class object that contains a caller's method.i - the offset on the call stack of the method of interestnull if not foundpublic static File extractResource(String name, File directory, String prefix, String suffix) throws IOException
ClassLoader of the caller.name - the name of the resource passed to Class.getResource(String)IOExceptionextractResource(URL, File, String, String)public static File extractResource(Class cls, String name, File directory, String prefix, String suffix) throws IOException
ClassLoader of the specified Class.cls - the Class from which to load resourcesname - the name of the resource passed to Class.getResource(String)IOExceptionextractResource(URL, File, String, String)public static File extractResource(URL resourceURL, File directory, String prefix, String suffix) throws IOException
null,
the original filename is used, so the directory must not be null.resourceURL - the URL of the resource to extractdirectory - the output directory (null == System.getProperty("java.io.tmpdir"))prefix - the prefix of the temporary filename to usesuffix - the suffix of the temporary filename to useIOException - if fails to extract resource properlypublic static File getTempDir()
tempDir out of
System.getProperty("java.io.tmpdir") and System.nanoTime().tempDirpublic static boolean isLoadLibraries()
loadLibrariespublic static String load()
Class of the caller.load(getCallerClass(2)) getCallerClass(int),
load(Class)public static String load(Class cls)
Class.cls - the Class to get native library information fromif (!loadLibraries || cls == null) { return null; })NoClassDefFoundError - on Class initialization failureUnsatisfiedLinkError - on native library loading failurepublic static URL[] findLibrary(Class cls, ClassProperties properties, String libnameversion)
Class
resources. But in case that fails, also searches the paths found in the
"platform.preloadpath" and "platform.linkpath" properties.cls - the Class whose package name and ClassLoader are used to extract from resourcesproperties - contains the directories to scan for if we fail to extract the library from resourceslibnameversion - the name of the library + "@" + optional version tagpublic static String loadLibrary(URL[] urls, String libnameversion)
System.loadLibrary(String).urls - the URLs to try loading the library fromlibnameversion - the name of the library + "@" + optional version tagif (!loadLibraries) { return null; })UnsatisfiedLinkError - on failurepublic static void main(String[] args)
static void putMemberOffset(String typeName, String member, int offset) throws ClassNotFoundException
offsetof() and sizeof() values in memberOffsets.
Tries to load the Class object for typeName using the ClassLoader of the Loader.typeName - the name of the peer Class acting as interface to the native typemember - the name of the native member variableoffset - the value of offsetof() (or sizeof() when member.equals("sizeof"))ClassNotFoundException - on Class initialization failurestatic void putMemberOffset(Class<? extends Pointer> type, String member, int offset)
type - the peer Class acting as interface to the native typemember - the name of the native member variableoffset - the value of offsetof() (or sizeof() when member.equals("sizeof"))public static int offsetof(Class<? extends Pointer> type, String member)
offsetof() values from memberOffsets filled by native libraries.type - the peer Class acting as interface to the native typemember - the name of the native member variablememberOffsets.get(type).get(member)public static int sizeof(Class<? extends Pointer> type)
sizeof() values from memberOffsets filled by native libraries.type - the peer Class acting as interface to the native typememberOffsets.get(type).get("sizeof")Copyright © 2014. All Rights Reserved.