@Properties(inherit=javacpp.class) public class Loader extends java.lang.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 | Class and Description |
|---|---|
static class |
Loader.Detector |
| Constructor and Description |
|---|
Loader() |
| Modifier and Type | Method and Description |
|---|---|
static Pointer |
addressof(java.lang.String symbol)
Returns the address found under the given name in the "dynamic symbol tables" (Linux, Mac OS X, etc)
or the "export tables" (Windows) of all libraries loaded, or null if not found.
|
static java.io.File |
cacheResource(java.lang.Class cls,
java.lang.String name)
Extracts a resource using the
ClassLoader of the specified Class,
and returns the cached File. |
static java.io.File |
cacheResource(java.lang.String name)
Extracts a resource using the
ClassLoader of the caller class,
and returns the cached File. |
static java.io.File |
cacheResource(java.net.URL resourceURL)
Returns
cacheResource(resourceUrl, null) |
static java.io.File |
cacheResource(java.net.URL resourceURL,
java.lang.String target)
Extracts a resource, if the size or last modified timestamp differs from what is in cache,
and returns the cached
File. |
static java.io.File[] |
cacheResources(java.lang.Class cls,
java.lang.String name)
Extracts resources using the
ClassLoader of the specified Class,
and returns the cached File objects. |
static java.io.File[] |
cacheResources(java.lang.String name)
Extracts resources using the
ClassLoader of the caller class,
and returns the cached File objects. |
static boolean |
checkPlatform(java.lang.Class<?> cls,
java.util.Properties properties) |
static boolean |
checkPlatform(Platform platform,
java.util.Properties properties,
java.lang.String... defaultNames) |
static boolean |
checkVersion(java.lang.String groupId,
java.lang.String artifactId)
Returns
checkVersion(groupId, artifactId, "-", true, getCallerClass(2)). |
static boolean |
checkVersion(java.lang.String groupId,
java.lang.String artifactId,
java.lang.String separator,
boolean logWarnings,
java.lang.Class cls)
Returns
getVersion(groupId, artifactId, cls).split(separator)[n].equals(getVersion().split(separator)[0])
where n = versions.length - (versions[versions.length - 1].equals("SNAPSHOT") ? 2 : 1) or false on error. |
static java.lang.String |
createLibraryLink(java.lang.String filename,
ClassProperties properties,
java.lang.String libnameversion,
java.lang.String... paths)
Creates a version-less symbolic link to a library file, if needed.
|
static java.io.File |
extractResource(java.lang.Class cls,
java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
Extracts by name a resource using the
ClassLoader of the specified Class. |
static java.io.File |
extractResource(java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
Extracts by name a resource using the
ClassLoader of the caller. |
static java.io.File |
extractResource(java.net.URL resourceURL,
java.io.File directoryOrFile,
java.lang.String prefix,
java.lang.String suffix)
Returns
extractResource(resourceURL, directoryOrFile, prefix, suffix, false). |
static java.io.File |
extractResource(java.net.URL resourceURL,
java.io.File directoryOrFile,
java.lang.String prefix,
java.lang.String suffix,
boolean cacheDirectory)
Extracts a resource into the specified directory and with the specified
prefix and suffix for the filename.
|
static java.io.File[] |
extractResources(java.lang.Class cls,
java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
Extracts by name resources using the
ClassLoader of the specified Class. |
static java.io.File[] |
extractResources(java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
Extracts by name resources using the
ClassLoader of the caller. |
static java.net.URL[] |
findLibrary(java.lang.Class cls,
ClassProperties properties,
java.lang.String libnameversion)
Returns
findLibrary(cls, properties, libnameversion, Loader.pathsFirst). |
static java.net.URL[] |
findLibrary(java.lang.Class cls,
ClassProperties properties,
java.lang.String libnameversion,
boolean pathsFirst)
Finds from where the library may be extracted and loaded among the
Class
resources. |
static java.net.URL |
findResource(java.lang.Class cls,
java.lang.String name)
Returns
findResources(cls, name, 1)[0] or null if none. |
static java.net.URL[] |
findResources(java.lang.Class cls,
java.lang.String name)
Returns
findResources(cls, name, -1). |
static java.net.URL[] |
findResources(java.lang.Class cls,
java.lang.String name,
int maxLength)
Finds by name resources using the
Class and its ClassLoader. |
static java.io.File |
getCacheDir()
Creates and returns
System.getProperty("org.bytedeco.javacpp.cachedir") or ~/.javacpp/cache/ when not set. |
static java.lang.Class |
getCallerClass(int i)
Returns the
Class object that contains a caller's method. |
static java.lang.Class |
getEnclosingClass(java.lang.Class cls)
If annotated with properties, returns the argument as "enclosing Class".
|
static Pointer |
getJavaVM()
Returns the JavaVM JNI object, as required by some APIs for initialization.
|
static java.util.Map<java.lang.String,java.lang.String> |
getLoadedLibraries()
Returns a Map that relates each library name to the path of the loaded file.
|
static java.lang.String |
getPlatform()
Returns either the value of the "org.bytedeco.javacpp.platform"
system property, or
PLATFORM when the former is not set. |
static java.io.File |
getTempDir()
Creates a unique name for
tempDir out of
System.getProperty("java.io.tmpdir") and System.nanoTime(). |
static java.lang.String |
getVersion()
Returns
getVersion("org.bytedeco", "javacpp"). |
static java.lang.String |
getVersion(java.lang.String groupId,
java.lang.String artifactId)
Returns
getVersion(groupId, artifactId, getCallerClass(2)). |
static java.lang.String |
getVersion(java.lang.String groupId,
java.lang.String artifactId,
java.lang.Class cls)
Returns version property from
cls.getResource("META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties"). |
static boolean |
isLoadLibraries()
Returns
System.getProperty("org.bytedeco.javacpp.loadlibraries"). |
static java.lang.String |
load()
Returns
load(getCallerClass(2), loadProperties(), Loader.pathsFirst). |
static java.lang.String |
load(boolean pathsFirst)
Loads native libraries associated with the
Class of the caller and initializes it. |
static java.lang.String[] |
load(java.lang.Class... classes)
Returns
load(classes, true). |
static java.lang.String |
load(java.lang.Class cls)
Returns
load(cls, loadProperties(), Loader.pathsFirst). |
static java.lang.String[] |
load(java.lang.Class[] classes,
boolean logMessages)
Calls
load(Class) on all top-level enclosing classes found in the array. |
static java.lang.String |
load(java.lang.Class cls,
java.util.Properties properties,
boolean pathsFirst)
Loads native libraries associated with the given
Class and initializes it. |
static void |
loadGlobal(java.lang.String filename)
Loads all symbols from a library globally, that is
dlopen(filename, RTLD_LAZY | RTLD_GLOBAL),
or simply by default with LoadLibrary(filename) on Windows. |
static java.lang.String |
loadLibrary(java.lang.Class<?> cls,
java.lang.String libnameversion,
java.lang.String... preloaded)
Returns
loadLibrary(findResources(cls, libnameversion), libnameversion, preloaded). |
static java.lang.String |
loadLibrary(java.lang.Class<?> cls,
java.net.URL[] urls,
java.lang.String libnameversion,
java.lang.String... preloaded)
Tries to load the library from the URLs in order, extracting resources as necessary.
|
static java.lang.String |
loadLibrary(java.lang.String libnameversion,
java.lang.String... preloaded)
Returns
loadLibrary(getCallerClass(2), libnameversion, preloaded). |
static java.lang.String |
loadLibrary(java.net.URL[] urls,
java.lang.String libnameversion,
java.lang.String... preloaded)
Returns
loadLibrary(null, urls, libnameversion, preloaded). |
static java.util.Properties |
loadProperties()
Loads the
Properties associated with the default getPlatform(). |
static ClassProperties |
loadProperties(java.lang.Class[] cls,
java.util.Properties properties,
boolean inherit)
For all the classes, loads all properties from each Class annotations for the given platform.
|
static ClassProperties |
loadProperties(java.lang.Class cls,
java.util.Properties properties,
boolean inherit)
Loads all properties from Class annotations for the given platform.
|
static java.util.Properties |
loadProperties(java.lang.String name,
java.lang.String defaults)
Loads from resources the default
Properties of the specified platform name. |
static int |
offsetof(java.lang.Class<? extends Pointer> type,
java.lang.String member)
Gets
offsetof() values from memberOffsets filled by native libraries. |
static int |
sizeof(java.lang.Class<? extends Pointer> type)
Gets
sizeof() values from memberOffsets filled by native libraries. |
static int |
totalChips()
Returns the number of CPU chips installed according to the operating system, or 0 if unknown.
|
static int |
totalCores()
Returns the number of CPU cores usable according to the operating system, or 0 if unknown.
|
static int |
totalProcessors()
Returns the number of processors configured according to the operating system, or 0 if unknown.
|
public static java.lang.String getPlatform()
PLATFORM when the former is not set.System.getProperty("org.bytedeco.javacpp.platform", platform)PLATFORMpublic static java.util.Properties loadProperties()
Properties associated with the default getPlatform().loadProperties(getPlatform(), null)loadProperties(String, String)public static java.util.Properties loadProperties(java.lang.String name,
java.lang.String defaults)
Properties of the specified platform name.
The resource must be at "org/bytedeco/javacpp/properties/" + name + ".properties".name - the platform namedefaults - the fallback platform name (null == "generic")public static boolean checkVersion(java.lang.String groupId,
java.lang.String artifactId)
checkVersion(groupId, artifactId, "-", true, getCallerClass(2)).public static boolean checkVersion(java.lang.String groupId,
java.lang.String artifactId,
java.lang.String separator,
boolean logWarnings,
java.lang.Class cls)
getVersion(groupId, artifactId, cls).split(separator)[n].equals(getVersion().split(separator)[0])
where n = versions.length - (versions[versions.length - 1].equals("SNAPSHOT") ? 2 : 1) or false on error.
Also calls Logger.warn(String) on error when logWarnings && isLoadLibraries().public static java.lang.String getVersion()
throws java.io.IOException
getVersion("org.bytedeco", "javacpp").java.io.IOExceptionpublic static java.lang.String getVersion(java.lang.String groupId,
java.lang.String artifactId)
throws java.io.IOException
getVersion(groupId, artifactId, getCallerClass(2)).java.io.IOExceptionpublic static java.lang.String getVersion(java.lang.String groupId,
java.lang.String artifactId,
java.lang.Class cls)
throws java.io.IOException
cls.getResource("META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties").java.io.IOExceptionpublic static java.lang.Class getEnclosingClass(java.lang.Class cls)
cls - the Class to start the search fromPlatform,
Propertiespublic static ClassProperties loadProperties(java.lang.Class[] cls, java.util.Properties properties, boolean inherit)
public static ClassProperties loadProperties(java.lang.Class cls, java.util.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 java.lang.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 java.io.File cacheResource(java.lang.String name)
throws java.io.IOException
ClassLoader of the caller class,
and returns the cached File.name - the name of the resource passed to Class.getResource(String)java.io.IOExceptioncacheResource(Class, String)public static java.io.File cacheResource(java.lang.Class cls,
java.lang.String name)
throws java.io.IOException
ClassLoader of the specified Class,
and returns the cached File.cls - the Class from which to load resourcesname - the name of the resource passed to Class.getResource(String)java.io.IOExceptioncacheResource(URL)public static java.io.File[] cacheResources(java.lang.String name)
throws java.io.IOException
ClassLoader of the caller class,
and returns the cached File objects.name - of the resources passed to findResources(Class, String)java.io.IOExceptioncacheResources(Class, String)public static java.io.File[] cacheResources(java.lang.Class cls,
java.lang.String name)
throws java.io.IOException
ClassLoader of the specified Class,
and returns the cached File objects.cls - the Class from which to load resourcesname - of the resources passed to findResources(Class, String)java.io.IOExceptioncacheResource(URL)public static java.io.File cacheResource(java.net.URL resourceURL)
throws java.io.IOException
cacheResource(resourceUrl, null)java.io.IOExceptionpublic static java.io.File cacheResource(java.net.URL resourceURL,
java.lang.String target)
throws java.io.IOException
File. If target is not null, creates instead a symbolic link
where the resource would have been extracted.resourceURL - the URL of the resource to extract and cachetarget - of the symbolic link to create (must be null to have the resource actually extracted)java.io.IOException - if fails to extract resource properlyextractResource(URL, File, String, String),
cacheDirpublic static java.io.File extractResource(java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
ClassLoader of the caller.name - the name of the resource passed to Class.getResource(String)java.io.IOExceptionextractResource(URL, File, String, String)public static java.io.File extractResource(java.lang.Class cls,
java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
ClassLoader of the specified Class.cls - the Class from which to load resourcesname - the name of the resource passed to Class.getResource(String)java.io.IOExceptionextractResource(URL, File, String, String)public static java.io.File[] extractResources(java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
ClassLoader of the caller.name - of the resources passed to findResources(Class, String)java.io.IOExceptionextractResources(Class, String, File, String, String)public static java.io.File[] extractResources(java.lang.Class cls,
java.lang.String name,
java.io.File directory,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
ClassLoader of the specified Class.cls - the Class from which to load resourcesname - of the resources passed to findResources(Class, String)java.io.IOExceptionextractResource(URL, File, String, String)public static java.io.File extractResource(java.net.URL resourceURL,
java.io.File directoryOrFile,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
extractResource(resourceURL, directoryOrFile, prefix, suffix, false).java.io.IOExceptionpublic static java.io.File extractResource(java.net.URL resourceURL,
java.io.File directoryOrFile,
java.lang.String prefix,
java.lang.String suffix,
boolean cacheDirectory)
throws java.io.IOException
null,
the original filename is used, so directoryOrFile must not be null.resourceURL - the URL of the resource to extractdirectoryOrFile - the output directory or file (null == System.getProperty("java.io.tmpdir"))prefix - the prefix of the temporary filename to usesuffix - the suffix of the temporary filename to usecacheDirectory - to extract files from directories only when size or last modified timestamp differsjava.io.IOException - if fails to extract resource properlypublic static java.net.URL findResource(java.lang.Class cls,
java.lang.String name)
throws java.io.IOException
findResources(cls, name, 1)[0] or null if none.java.io.IOExceptionpublic static java.net.URL[] findResources(java.lang.Class cls,
java.lang.String name)
throws java.io.IOException
findResources(cls, name, -1).java.io.IOExceptionpublic static java.net.URL[] findResources(java.lang.Class cls,
java.lang.String name,
int maxLength)
throws java.io.IOException
Class and its ClassLoader.
Names not prefixed with '/' are considered in priority relative to the Class,
but parent packages, including the default one, also get searched.cls - the Class from whose ClassLoader to load resourcesname - of the resources passed to Class.getResource(String) and ClassLoader.getResources(String)maxLength - of the array to return, or -1 for no limitjava.io.IOExceptionpublic static java.io.File getCacheDir()
throws java.io.IOException
System.getProperty("org.bytedeco.javacpp.cachedir") or ~/.javacpp/cache/ when not set.java.io.IOExceptionpublic static java.io.File getTempDir()
tempDir out of
System.getProperty("java.io.tmpdir") and System.nanoTime().tempDirpublic static java.util.Map<java.lang.String,java.lang.String> getLoadedLibraries()
public static boolean isLoadLibraries()
System.getProperty("org.bytedeco.javacpp.loadlibraries").
Flag set by the Builder to tell us not to try to load anything.public static boolean checkPlatform(java.lang.Class<?> cls,
java.util.Properties properties)
public static boolean checkPlatform(Platform platform, java.util.Properties properties, java.lang.String... defaultNames)
public static java.lang.String[] load(java.lang.Class... classes)
load(classes, true).public static java.lang.String[] load(java.lang.Class[] classes,
boolean logMessages)
load(Class) on all top-level enclosing classes found in the array.classes - to try to loadlogMessages - on load or fail silentlyload(Class) or null otherwisepublic static java.lang.String load()
load(getCallerClass(2), loadProperties(), Loader.pathsFirst).public static java.lang.String load(boolean pathsFirst)
Class of the caller and initializes it.pathsFirst - search the paths first before bundled resourcesload(getCallerClass(2), loadProperties(), pathsFirst) getCallerClass(int),
load(Class, Properties, boolean)public static java.lang.String load(java.lang.Class cls)
load(cls, loadProperties(), Loader.pathsFirst).public static java.lang.String load(java.lang.Class cls,
java.util.Properties properties,
boolean pathsFirst)
Class and initializes it.cls - the Class to get native library information from and to initializeproperties - the platform Properties to inheritpathsFirst - search the paths first before bundled resourcesif (!isLoadLibraries() || cls == null) { return null; })java.lang.NoClassDefFoundError - on Class initialization failurejava.lang.UnsatisfiedLinkError - on native library loading failure or when interruptedfindLibrary(Class, ClassProperties, String, boolean),
loadLibrary(URL[], String, String...)public static java.net.URL[] findLibrary(java.lang.Class cls,
ClassProperties properties,
java.lang.String libnameversion)
findLibrary(cls, properties, libnameversion, Loader.pathsFirst).public static java.net.URL[] findLibrary(java.lang.Class cls,
ClassProperties properties,
java.lang.String libnameversion,
boolean pathsFirst)
Class
resources. But in case that fails, and depending on the value of pathsFirst,
either as a fallback or in priority over bundled resources, also searches the paths
found in the "platform.preloadpath" and "platform.linkpath" class properties (as well as
the "java.library.path" system property if pathsFirst || !loadLibraries), in that order.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 exact path to library + "@" + optional version tag
+ "#" + a second optional name used at extraction (or empty to prevent it, unless it is a second "#")
+ "!" to load all symbols globallypathsFirst - search the paths first before bundled resourcespublic static java.lang.String loadLibrary(java.lang.String libnameversion,
java.lang.String... preloaded)
loadLibrary(getCallerClass(2), libnameversion, preloaded).public static java.lang.String loadLibrary(java.lang.Class<?> cls,
java.lang.String libnameversion,
java.lang.String... preloaded)
loadLibrary(findResources(cls, libnameversion), libnameversion, preloaded).public static java.lang.String loadLibrary(java.net.URL[] urls,
java.lang.String libnameversion,
java.lang.String... preloaded)
loadLibrary(null, urls, libnameversion, preloaded).public static java.lang.String loadLibrary(java.lang.Class<?> cls,
java.net.URL[] urls,
java.lang.String libnameversion,
java.lang.String... preloaded)
System.loadLibrary(String).cls - the Class whose ClassLoader is used to load the library, may be nullurls - the URLs to try loading the library fromlibnameversion - the name of the library + ":" + optional exact path to library + "@" + optional version tag
+ "#" + a second optional name used at extraction (or empty to prevent it, unless it is a second "#")
+ "!" to load all symbols globallypreloaded - libraries for which to create symbolic links in same cache directoryif (!isLoadLibraries) { return null; })java.lang.UnsatisfiedLinkError - on failure or when interruptedpublic static java.lang.String createLibraryLink(java.lang.String filename,
ClassProperties properties,
java.lang.String libnameversion,
java.lang.String... paths)
filename - of the probably versioned libraryproperties - of the class associated with the librarylibnameversion - the library name and version as with loadLibrary(URL[], String, String...) (can be null)paths - where to create links, in addition to the parent directory of filenamepublic static int offsetof(java.lang.Class<? extends Pointer> type, java.lang.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(java.lang.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")@Name(value="JavaCPP_totalProcessors") public static int totalProcessors()
Runtime.availableProcessors() and totalCores().@Name(value="JavaCPP_totalCores") public static int totalCores()
totalProcessors().@Name(value="JavaCPP_totalChips") public static int totalChips()
totalCores().@Name(value="JavaCPP_addressof") public static Pointer addressof(java.lang.String symbol)
@Name(value="JavaCPP_loadGlobal") @Raw(withEnv=true) public static void loadGlobal(java.lang.String filename)
dlopen(filename, RTLD_LAZY | RTLD_GLOBAL),
or simply by default with LoadLibrary(filename) on Windows. If the library name passed to
one of the other load functions in this class ends with "!", this function will get called on them.