Class LibraryLoader


  • public final class LibraryLoader
    extends Object
    This class provides more generic means for loading dynamical libraries.

    The library loader may be enabled or not. When library loader is enable, it is able to retreive and load native libraries. When it is disable, it ignore all the loading queries.

    Version:
    17.0 2020-01-04 14:41:35
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    vmutils
    • Method Detail

      • isEnable

        @Pure
        public static boolean isEnable()
        Replies if this library loader is enable.

        The library loader is able to load native libraries when it is enable. Otherwise it ignore all the loading queries.

        Returns:
        true if the library loader is enable, otherwise false
        Since:
        5.0
      • setEnable

        public static void setEnable​(boolean enable)
        Replies if this library loader is enable.

        The library loader is able to load native libraries when it is enable. Otherwise it ignore all the loading queries.

        Parameters:
        enable - is true to allow this loader to retreive native libraries, or false to ignore all the loading queries.
        Since:
        5.0
      • load

        public static void load​(String filename)
        Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.

        The call LibraryLoader.load(name) is effectively equivalent to the call:

         System.load(name)
         
        Parameters:
        filename - is the file to load.
        Throws:
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the file does not exist.
        NullPointerException - if filename is null
        See Also:
        System.load(java.lang.String)
      • load

        public static void load​(URL filename)
                         throws IOException
        Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.
        Parameters:
        filename - is the file to load.
        Throws:
        IOException - when reading error occurs.
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the file does not exist.
        NullPointerException - if filename is null
        See Also:
        System.load(java.lang.String)
      • load

        public static void load​(File filename)
        Loads a code file with the specified filename from the local file system as a dynamic library. The filename argument must be a complete path name.

        The call LibraryLoader.load(name) is effectively equivalent to the call:

         System.load(name.getAbsolutePath())
         
        Parameters:
        filename - is the file to load.
        Throws:
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the file does not exist.
        NullPointerException - if filename is null
        See Also:
        System.load(java.lang.String)
      • loadLibrary

        public static void loadLibrary​(String libname)
        Loads the system library specified by the libname argument. The manner in which a library name is mapped to the actual system library is system dependent.

        The call LibraryLoader.loadLibrary(name) is effectively equivalent to the call

         System.loadLibrary(name)
         
        Parameters:
        libname - the name of the library.
        Throws:
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the library does not exist.
        NullPointerException - if libname is null
        See Also:
        System.loadLibrary(java.lang.String)
      • findLibraryURL

        @Pure
        public static URL findLibraryURL​(String libName)
        Replies the URL for the specified library.
        Parameters:
        libName - is the name of the library
        Returns:
        the URL where the specified library was located.
      • findLibraryURL

        @Pure
        public static URL findLibraryURL​(String path,
                                         String libName)
        Replies the URL for the specified library.

        The call LibraryLoader.findLibraryURL(path,name) is effectively equivalent to the call:

         getClassLoader().getResource(path+System.mapLibraryName(name))
         
        Parameters:
        path - is the resource's path where the library was located.
        libName - is the name of the library
        Returns:
        the URL where the specified library was located.
      • getOperatingSystemArchitectureDataModel

        @Pure
        static int getOperatingSystemArchitectureDataModel()
        Replies the data model of the current operating system: 32 or 64 bits.
        Returns:
        the integer which is corresponding to the data model, or 0 if it could not be determined.
      • loadPlatformDependentLibrary

        public static void loadPlatformDependentLibrary​(String libname)
                                                 throws IOException
        Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...). A 64 bits library is assumed to be named libname64.dll on Windows® and liblibname64.so on Unix. A 32 bits library is assumed to be named libname32.dll on Windows® and liblibname32.so on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be named libname.dll on Windows® and liblibname.so on Unix.
        Parameters:
        libname - is the name of the library.
        Throws:
        IOException - when reading error occurs.
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the file does not exist.
        NullPointerException - if filename is null
        See Also:
        System.load(java.lang.String)
      • loadPlatformDependentLibrary

        public static void loadPlatformDependentLibrary​(String path,
                                                        String libname)
                                                 throws IOException
        Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...). A 64 bits library is assumed to be named libname64.dll on Windows® and liblibname64.so on Unix. A 32 bits library is assumed to be named libname32.dll on Windows® and liblibname32.so on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be named libname.dll on Windows® and liblibname.so on Unix.
        Parameters:
        path - is the resource's path where the library was located.
        libname - is the name of the library.
        Throws:
        IOException - when reading error occurs.
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the file does not exist.
        NullPointerException - if filename is null
        See Also:
        System.load(java.lang.String)
      • loadPlatformDependentLibrary

        static void loadPlatformDependentLibrary​(String libname,
                                                 String platform,
                                                 String... paths)
                                          throws IOException
        Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...). A 64 bits library is assumed to be named libname64.dll on Windows® and liblibname64.so on Unix. A 32 bits library is assumed to be named libname32.dll on Windows® and liblibname32.so on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be named libname.dll on Windows® and liblibname.so on Unix.
        Parameters:
        libname - is the name of the library.
        platform - is the name of the current OS platform.
        paths - are the resource's paths where the library was located.
        Throws:
        IOException - when reading error occurs.
        SecurityException - if a security manager exists and its checkLink method doesn't allow loading of the specified dynamic library
        UnsatisfiedLinkError - if the file does not exist.
        NullPointerException - if filename is null
        See Also:
        System.load(java.lang.String)