Class Loader


  • @Properties(inherit=javacpp.class)
    public class Loader
    extends java.lang.Object
    The Loader contains functionality to load native libraries, but also has a bit of everything that does not fit anywhere else. In addition to its library loading features, it also has utility methods to get the platform name, to load properties from Java resources and from Class annotations, to extract file resources to the temporary directory, and to get the 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().
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) static java.io.File cacheDir
      User-specified cache directory set and returned by getCacheDir().
      (package private) static boolean cacheLibraries
      Whether to extract libraries to cacheDir, set via "org.bytedeco.javacpp.cacheLibraries" system property.
      (package private) static boolean canCreateSymbolicLink
      Will be set to false when symbolic link creation fails, such as on Windows.
      private static java.lang.ThreadLocal<java.util.Deque<java.lang.Class<?>>> classStack
      The stack of classes currently being loaded to support more than one class loader.
      (package private) static boolean findLibraries
      Whether to search libraries in class, module, and library paths, set via "org.bytedeco.javacpp.findLibraries" system property.
      (package private) static java.util.Map<java.lang.String,​java.net.URL[]> foundLibraries
      Contains all the URLs of native libraries that we found to avoid searching for them again.
      (package private) static java.util.Map<java.lang.String,​java.lang.String> loadedLibraries
      Contains all the native libraries that we have loaded to avoid reloading them.
      private static Logger logger  
      (package private) static java.util.WeakHashMap<java.lang.Class<? extends Pointer>,​java.util.HashMap<java.lang.String,​java.lang.Integer>> memberOffsets
      Contains offsetof() and sizeof() values of native types of struct, class, and union.
      (package private) static boolean pathsFirst
      Default value for load(..., pathsFirst) set via "org.bytedeco.javacpp.pathsFirst" system property.
      private static java.lang.String PLATFORM
      Value created out of "java.vm.name", "os.name", and "os.arch" system properties.
      private static java.util.Properties platformProperties
      Default platform properties loaded and returned by loadProperties().
      (package private) static java.io.File tempDir
      Temporary directory set and returned by getTempDir().
      private static boolean WINDOWS  
    • Constructor Summary

      Constructors 
      Constructor Description
      Loader()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Object accessGlobalRef​(Pointer globalRef)
      static Pointer addressof​(java.lang.String symbol)
      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​(java.lang.Class<?> cls, java.util.Properties properties, boolean acceptAllExtensions)  
      static boolean checkPlatform​(Platform platform, java.util.Properties properties)  
      static boolean checkPlatform​(Platform platform, java.util.Properties properties, boolean acceptAllExtensions, 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 void clearCacheDir()
      Calls deleteDirectory(getCacheDir()).
      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 void deleteDirectory​(java.io.File directory)
      Deletes the directory and all the files in it.
      static void deleteGlobalRef​(Pointer globalRef)
      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.io.File getCanonicalFile​(java.io.File file)
      Returns file.getCanonicalFile() or file.toPath().toRealPath().toFile() on Windows.
      static java.lang.String getCanonicalPath​(java.io.File file)
      Returns file.getCanonicalPath() or file.toPath().toRealPath().toString() on Windows.
      static java.lang.Class getEnclosingClass​(java.lang.Class cls)
      If annotated with properties, returns the argument as "enclosing Class".
      static Pointer getJavaVM()
      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 PLATFORM.
      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 cls)
      Returns load(cls, loadProperties(), Loader.pathsFirst).
      static java.lang.String[] load​(java.lang.Class... classes)
      Returns load(classes, true).
      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.lang.String executable)
      Returns load(cls, loadProperties(), Loader.pathsFirst, executable).
      static java.lang.String load​(java.lang.Class cls, java.util.Properties properties, boolean pathsFirst)
      Returns load(cls, properties, pathsFirst, null).
      static java.lang.String load​(java.lang.Class cls, java.util.Properties properties, boolean pathsFirst, java.lang.String executable)
      Loads native libraries or executables associated with the given Class and initializes it.
      static void loadGlobal​(java.lang.String filename)
      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()
      Returns loadProperties(false).
      static java.util.Properties loadProperties​(boolean forceReload)
      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 Pointer newGlobalRef​(java.lang.Object object)
      static int offsetof​(java.lang.Class<? extends Pointer> type, java.lang.String member)
      Gets offsetof() values from memberOffsets filled by native libraries.
      (package private) static void putMemberOffset​(java.lang.Class<? extends Pointer> type, java.lang.String member, int offset)
      Called by native libraries to put offsetof() and sizeof() values in memberOffsets.
      (package private) static java.lang.Class putMemberOffset​(java.lang.String typeName, java.lang.String member, int offset)
      Called by native libraries to put offsetof() and sizeof() values in memberOffsets.
      static int sizeof​(java.lang.Class<? extends Pointer> type)
      Gets sizeof() values from memberOffsets filled by native libraries.
      static int totalChips()
      static int totalCores()
      static int totalProcessors()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        private static final Logger logger
      • PLATFORM

        private static final java.lang.String PLATFORM
        Value created out of "java.vm.name", "os.name", and "os.arch" system properties. Returned by getPlatform() and initialized with Loader.Detector.getPlatform().
      • WINDOWS

        private static final boolean WINDOWS
      • platformProperties

        private static java.util.Properties platformProperties
        Default platform properties loaded and returned by loadProperties().
      • classStack

        private static final java.lang.ThreadLocal<java.util.Deque<java.lang.Class<?>>> classStack
        The stack of classes currently being loaded to support more than one class loader.
      • cacheDir

        static java.io.File cacheDir
        User-specified cache directory set and returned by getCacheDir().
      • tempDir

        static java.io.File tempDir
        Temporary directory set and returned by getTempDir().
      • foundLibraries

        static java.util.Map<java.lang.String,​java.net.URL[]> foundLibraries
        Contains all the URLs of native libraries that we found to avoid searching for them again.
      • loadedLibraries

        static java.util.Map<java.lang.String,​java.lang.String> loadedLibraries
        Contains all the native libraries that we have loaded to avoid reloading them.
      • canCreateSymbolicLink

        static boolean canCreateSymbolicLink
        Will be set to false when symbolic link creation fails, such as on Windows. Set via "org.bytedeco.javacpp.canCreateSymbolicLink" system property, defaults to false on Windows only.
      • pathsFirst

        static boolean pathsFirst
        Default value for load(..., pathsFirst) set via "org.bytedeco.javacpp.pathsFirst" system property.
      • cacheLibraries

        static boolean cacheLibraries
        Whether to extract libraries to cacheDir, set via "org.bytedeco.javacpp.cacheLibraries" system property.
      • findLibraries

        static boolean findLibraries
        Whether to search libraries in class, module, and library paths, set via "org.bytedeco.javacpp.findLibraries" system property.
      • memberOffsets

        static java.util.WeakHashMap<java.lang.Class<? extends Pointer>,​java.util.HashMap<java.lang.String,​java.lang.Integer>> memberOffsets
        Contains 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.
    • Constructor Detail

      • Loader

        public Loader()
    • Method Detail

      • getPlatform

        public static java.lang.String getPlatform()
        Returns PLATFORM.
      • getCanonicalPath

        public static java.lang.String getCanonicalPath​(java.io.File file)
                                                 throws java.io.IOException
        Returns file.getCanonicalPath() or file.toPath().toRealPath().toString() on Windows.
        Returns:
        The canonical pathname string denoting the same file or directory as that abstract pathname.
        Throws:
        java.io.IOException - if an I/O error occurs
        See Also:
        https://bugs.openjdk.java.net/browse/JDK-8003887
      • getCanonicalFile

        public static java.io.File getCanonicalFile​(java.io.File file)
                                             throws java.io.IOException
        Returns file.getCanonicalFile() or file.toPath().toRealPath().toFile() on Windows.
        Returns:
        The canonical file denoting the same file or directory as that abstract pathname.
        Throws:
        java.io.IOException - if an I/O error occurs
        See Also:
        https://bugs.openjdk.java.net/browse/JDK-8003887
      • loadProperties

        public static java.util.Properties loadProperties()
        Returns loadProperties(false).
      • loadProperties

        public static java.util.Properties loadProperties​(boolean forceReload)
        Loads the Properties associated with the default getPlatform().
        Parameters:
        forceReload - to reset cached platformProperties even when not null
        Returns:
        loadProperties(getPlatform(), null)
        See Also:
        loadProperties(String, String)
      • loadProperties

        public static java.util.Properties loadProperties​(java.lang.String name,
                                                          java.lang.String defaults)
        Loads from resources the default Properties of the specified platform name. The resource must be at "org/bytedeco/javacpp/properties/" + name + ".properties". Also picks up system properties starting with "org.bytedeco.javacpp.platform.", which can be used to override default platform properties.
        Parameters:
        name - the platform name
        defaults - the fallback platform name (null == "generic")
        Returns:
        the Properties from resources
      • checkVersion

        public static boolean checkVersion​(java.lang.String groupId,
                                           java.lang.String artifactId)
        Returns checkVersion(groupId, artifactId, "-", true, getCallerClass(2)).
      • checkVersion

        public 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. Also calls Logger.warn(String) on error when logWarnings && isLoadLibraries().
      • getVersion

        public static java.lang.String getVersion()
                                           throws java.io.IOException
        Returns getVersion("org.bytedeco", "javacpp").
        Throws:
        java.io.IOException
      • getVersion

        public static java.lang.String getVersion​(java.lang.String groupId,
                                                  java.lang.String artifactId)
                                           throws java.io.IOException
        Returns getVersion(groupId, artifactId, getCallerClass(2)).
        Throws:
        java.io.IOException
      • getVersion

        public static java.lang.String getVersion​(java.lang.String groupId,
                                                  java.lang.String artifactId,
                                                  java.lang.Class cls)
                                           throws java.io.IOException
        Returns version property from cls.getResource("META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties").
        Throws:
        java.io.IOException
      • getEnclosingClass

        public static java.lang.Class getEnclosingClass​(java.lang.Class cls)
        If annotated with properties, returns the argument as "enclosing Class". If no properties are found on the Class, makes a search for the first Class with properties that we can use, and returns it as the enclosing Class found.
        Parameters:
        cls - the Class to start the search from
        Returns:
        the enclosing Class
        See Also:
        Platform, Properties
      • loadProperties

        public static ClassProperties loadProperties​(java.lang.Class cls,
                                                     java.util.Properties properties,
                                                     boolean inherit)
        Loads all properties from Class annotations for the given platform. The platform of interest needs to be specified as the value of the "platform" key in the properties argument. It is also possible to indicate whether to load all the classes specified in the Properties.inherit() annotation recursively via the inherit argument.
        Parameters:
        cls - the Class of which to return Properties
        properties - the platform Properties to inherit
        inherit - indicates whether or not to inherit properties from other classes
        Returns:
        all the properties associated with the Class for the given platform
      • getCallerClass

        public static java.lang.Class getCallerClass​(int i)
        Returns the Class object that contains a caller's method.
        Parameters:
        i - the offset on the call stack of the method of interest
        Returns:
        the Class found from the calling context, or null if not found
      • cacheResource

        public static java.io.File cacheResource​(java.lang.String name)
                                          throws java.io.IOException
        Extracts a resource using the ClassLoader of the caller class, and returns the cached File.
        Parameters:
        name - the name of the resource passed to Class.getResource(String)
        Throws:
        java.io.IOException
        See Also:
        cacheResource(Class, String)
      • cacheResource

        public static java.io.File cacheResource​(java.lang.Class cls,
                                                 java.lang.String name)
                                          throws java.io.IOException
        Extracts a resource using the ClassLoader of the specified Class, and returns the cached File.
        Parameters:
        cls - the Class from which to load resources
        name - the name of the resource passed to Class.getResource(String)
        Throws:
        java.io.IOException
        See Also:
        cacheResource(URL)
      • cacheResources

        public static java.io.File[] cacheResources​(java.lang.String name)
                                             throws java.io.IOException
        Extracts resources using the ClassLoader of the caller class, and returns the cached File objects.
        Parameters:
        name - of the resources passed to findResources(Class, String)
        Throws:
        java.io.IOException
        See Also:
        cacheResources(Class, String)
      • cacheResources

        public static java.io.File[] cacheResources​(java.lang.Class cls,
                                                    java.lang.String name)
                                             throws java.io.IOException
        Extracts resources using the ClassLoader of the specified Class, and returns the cached File objects.
        Parameters:
        cls - the Class from which to load resources
        name - of the resources passed to findResources(Class, String)
        Throws:
        java.io.IOException
        See Also:
        cacheResource(URL)
      • cacheResource

        public static java.io.File cacheResource​(java.net.URL resourceURL)
                                          throws java.io.IOException
        Returns cacheResource(resourceUrl, null)
        Throws:
        java.io.IOException
      • cacheResource

        public static java.io.File cacheResource​(java.net.URL resourceURL,
                                                 java.lang.String target)
                                          throws java.io.IOException
        Extracts a resource, if the size or last modified timestamp differs from what is in cache, and returns the cached File. If target is not null, creates instead a symbolic link where the resource would have been extracted. Directories from JAR files are extracted recursively.
        Parameters:
        resourceURL - the URL of the resource to extract and cache
        target - of the symbolic link to create (must be null to have the resource actually extracted)
        Returns:
        the File object representing the extracted file from the cache
        Throws:
        java.io.IOException - if fails to extract resource properly
        See Also:
        extractResource(URL, File, String, String), cacheDir
      • extractResource

        public 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
        Extracts by name a resource using the ClassLoader of the caller.
        Parameters:
        name - the name of the resource passed to Class.getResource(String)
        Throws:
        java.io.IOException
        See Also:
        extractResource(URL, File, String, String)
      • extractResource

        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
        Extracts by name a resource using the ClassLoader of the specified Class.
        Parameters:
        cls - the Class from which to load resources
        name - the name of the resource passed to Class.getResource(String)
        Throws:
        java.io.IOException
        See Also:
        extractResource(URL, File, String, String)
      • extractResources

        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
        Extracts by name resources using the ClassLoader of the caller.
        Parameters:
        name - of the resources passed to findResources(Class, String)
        Throws:
        java.io.IOException
        See Also:
        extractResources(Class, String, File, String, String)
      • extractResources

        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
        Extracts by name resources using the ClassLoader of the specified Class.
        Parameters:
        cls - the Class from which to load resources
        name - of the resources passed to findResources(Class, String)
        Throws:
        java.io.IOException
        See Also:
        extractResource(URL, File, String, String)
      • extractResource

        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
        Returns extractResource(resourceURL, directoryOrFile, prefix, suffix, false).
        Throws:
        java.io.IOException
      • extractResource

        public 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
        Extracts a resource into the specified directory and with the specified prefix and suffix for the filename. If both prefix and suffix are null, the original filename is used, so directoryOrFile must not be null. Directories from JAR files are extracted recursively.
        Parameters:
        resourceURL - the URL of the resource to extract
        directoryOrFile - the output directory or file (null == System.getProperty("java.io.tmpdir"))
        prefix - the prefix of the temporary filename to use
        suffix - the suffix of the temporary filename to use
        cacheDirectory - to extract files from directories only when size or last modified timestamp differs
        Returns:
        the File object representing the extracted file
        Throws:
        java.io.IOException - if fails to extract resource properly
      • findResource

        public static java.net.URL findResource​(java.lang.Class cls,
                                                java.lang.String name)
                                         throws java.io.IOException
        Returns findResources(cls, name, 1)[0] or null if none.
        Throws:
        java.io.IOException
      • findResources

        public static java.net.URL[] findResources​(java.lang.Class cls,
                                                   java.lang.String name)
                                            throws java.io.IOException
        Returns findResources(cls, name, -1).
        Throws:
        java.io.IOException
      • findResources

        public static java.net.URL[] findResources​(java.lang.Class cls,
                                                   java.lang.String name,
                                                   int maxLength)
                                            throws java.io.IOException
        Finds by name resources using the 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.
        Parameters:
        cls - the Class from whose ClassLoader to load resources
        name - of the resources passed to Class.getResource(String) and ClassLoader.getResources(String)
        maxLength - of the array to return, or -1 for no limit
        Returns:
        URLs to the resources
        Throws:
        java.io.IOException
      • deleteDirectory

        public static void deleteDirectory​(java.io.File directory)
                                    throws java.io.IOException
        Deletes the directory and all the files in it.
        Throws:
        java.io.IOException
      • clearCacheDir

        public static void clearCacheDir()
                                  throws java.io.IOException
        Calls deleteDirectory(getCacheDir()).
        Throws:
        java.io.IOException
      • getCacheDir

        public static java.io.File getCacheDir()
                                        throws java.io.IOException
        Creates and returns System.getProperty("org.bytedeco.javacpp.cachedir") or ~/.javacpp/cache/ when not set.
        Throws:
        java.io.IOException
      • getTempDir

        public static java.io.File getTempDir()
        Creates a unique name for tempDir out of System.getProperty("java.io.tmpdir") and System.nanoTime().
        Returns:
        tempDir
      • getLoadedLibraries

        public 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.
      • isLoadLibraries

        public static boolean isLoadLibraries()
        Returns System.getProperty("org.bytedeco.javacpp.loadlibraries"). Flag set by the Builder to tell us not to try to load anything.
      • checkPlatform

        public static boolean checkPlatform​(java.lang.Class<?> cls,
                                            java.util.Properties properties)
      • checkPlatform

        public static boolean checkPlatform​(java.lang.Class<?> cls,
                                            java.util.Properties properties,
                                            boolean acceptAllExtensions)
      • checkPlatform

        public static boolean checkPlatform​(Platform platform,
                                            java.util.Properties properties)
      • checkPlatform

        public static boolean checkPlatform​(Platform platform,
                                            java.util.Properties properties,
                                            boolean acceptAllExtensions,
                                            java.lang.String... defaultNames)
      • load

        public static java.lang.String[] load​(java.lang.Class... classes)
        Returns load(classes, true).
      • load

        public static java.lang.String[] load​(java.lang.Class[] classes,
                                              boolean logMessages)
        Calls load(Class) on all top-level enclosing classes found in the array.
        Parameters:
        classes - to try to load
        logMessages - on load or fail silently
        Returns:
        filenames from each successful call to load(Class) or null otherwise
      • load

        public static java.lang.String load()
        Returns load(getCallerClass(2), loadProperties(), Loader.pathsFirst).
      • load

        public static java.lang.String load​(boolean pathsFirst)
        Loads native libraries associated with the Class of the caller and initializes it.
        Parameters:
        pathsFirst - search the library paths first before bundled resources
        Returns:
        load(getCallerClass(2), loadProperties(), pathsFirst)
        See Also:
        getCallerClass(int), load(Class, Properties, boolean)
      • load

        public static java.lang.String load​(java.lang.Class cls)
        Returns load(cls, loadProperties(), Loader.pathsFirst).
      • load

        public static java.lang.String load​(java.lang.Class cls,
                                            java.lang.String executable)
        Returns load(cls, loadProperties(), Loader.pathsFirst, executable).
      • load

        public static java.lang.String load​(java.lang.Class cls,
                                            java.util.Properties properties,
                                            boolean pathsFirst)
        Returns load(cls, properties, pathsFirst, null).
      • load

        public static java.lang.String load​(java.lang.Class cls,
                                            java.util.Properties properties,
                                            boolean pathsFirst,
                                            java.lang.String executable)
        Loads native libraries or executables associated with the given Class and initializes it.
        Parameters:
        cls - the Class to get native library and executable information from and to initialize
        properties - the platform Properties to inherit
        pathsFirst - search the library paths first before bundled resources
        executable - the executable name whose path to return, or the first one found when null
        Returns:
        the full path to the main file loaded, or the library name if unknown (but if (!isLoadLibraries() || cls == null) { return null; }), while in the case of optional libraries or executables, it may return null when not found
        Throws:
        java.lang.NoClassDefFoundError - on Class initialization failure
        java.lang.UnsatisfiedLinkError - on native library loading failure or when interrupted
        java.lang.IllegalArgumentException - when executable is specified for a class without executables
        See Also:
        findLibrary(Class, ClassProperties, String, boolean), loadLibrary(URL[], String, String...)
      • findLibrary

        public static java.net.URL[] findLibrary​(java.lang.Class cls,
                                                 ClassProperties properties,
                                                 java.lang.String libnameversion)
        Returns findLibrary(cls, properties, libnameversion, Loader.pathsFirst).
      • findLibrary

        public 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. 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 "sun.boot.library.path" and "java.library.path" system properties if pathsFirst || !loadLibraries), in that order.
        Parameters:
        cls - the Class whose package name and ClassLoader are used to extract from resources
        properties - contains the directories to scan for if we fail to extract the library from resources
        libnameversion - 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 globally
        pathsFirst - search the library paths first before bundled resources
        Returns:
        URLs that point to potential locations of the library
      • loadLibrary

        public static java.lang.String loadLibrary​(java.lang.String libnameversion,
                                                   java.lang.String... preloaded)
        Returns loadLibrary(getCallerClass(2), libnameversion, preloaded).
      • loadLibrary

        public static java.lang.String loadLibrary​(java.lang.Class<?> cls,
                                                   java.lang.String libnameversion,
                                                   java.lang.String... preloaded)
        Returns loadLibrary(findResources(cls, libnameversion), libnameversion, preloaded).
      • loadLibrary

        public static java.lang.String loadLibrary​(java.net.URL[] urls,
                                                   java.lang.String libnameversion,
                                                   java.lang.String... preloaded)
        Returns loadLibrary(null, urls, libnameversion, preloaded).
      • loadLibrary

        public 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. Finally, if all fails, falls back on System.loadLibrary(String).
        Parameters:
        cls - the Class whose ClassLoader is used to load the library, may be null
        urls - the URLs to try loading the library from
        libnameversion - 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 globally
        preloaded - libraries for which to create symbolic links in same cache directory
        Returns:
        the full path of the file loaded, or the library name if unknown (but if (!isLoadLibraries) { return null; })
        Throws:
        java.lang.UnsatisfiedLinkError - on failure or when interrupted
      • createLibraryLink

        public 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. Also creates symbolic links in given paths, with and without version.
        Parameters:
        filename - of the probably versioned library
        properties - of the class associated with the library
        libnameversion - 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 filename
        Returns:
        the version-less filename (or null on failure), a symbolic link only if needed
      • putMemberOffset

        static java.lang.Class putMemberOffset​(java.lang.String typeName,
                                               java.lang.String member,
                                               int offset)
                                        throws java.lang.ClassNotFoundException
        Called by native libraries to put offsetof() and sizeof() values in memberOffsets. Tries to load the Class object for typeName using the ClassLoader of the Loader.
        Parameters:
        typeName - the name of the peer Class acting as interface to the native type
        member - the name of the native member variable (can be null to retrieve the Class object only)
        offset - the value of offsetof() (or sizeof() when member.equals("sizeof"))
        Returns:
        Class.forName(typeName, false)
        Throws:
        java.lang.ClassNotFoundException - on Class initialization failure
      • putMemberOffset

        static void putMemberOffset​(java.lang.Class<? extends Pointer> type,
                                    java.lang.String member,
                                    int offset)
        Called by native libraries to put offsetof() and sizeof() values in memberOffsets.
        Parameters:
        type - the peer Class acting as interface to the native type
        member - the name of the native member variable
        offset - the value of offsetof() (or sizeof() when member.equals("sizeof"))
      • offsetof

        public static int offsetof​(java.lang.Class<? extends Pointer> type,
                                   java.lang.String member)
        Gets offsetof() values from memberOffsets filled by native libraries.
        Parameters:
        type - the peer Class acting as interface to the native type
        member - the name of the native member variable
        Returns:
        memberOffsets.get(type).get(member)
      • sizeof

        public static int sizeof​(java.lang.Class<? extends Pointer> type)
        Gets sizeof() values from memberOffsets filled by native libraries.
        Parameters:
        type - the peer Class acting as interface to the native type
        Returns:
        memberOffsets.get(type).get("sizeof")