- java.lang.Object
-
- org.arakhne.afc.vmutil.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static URL
findLibraryURL(String libName)
Replies the URL for the specified library.static URL
findLibraryURL(String path, String libName)
Replies the URL for the specified library.(package private) static int
getOperatingSystemArchitectureDataModel()
Replies the data model of the current operating system: 32 or 64 bits.static boolean
isEnable()
Replies if this library loader is enable.static void
load(File filename)
Loads a code file with the specified filename from the local file system as a dynamic library.static void
load(String filename)
Loads a code file with the specified filename from the local file system as a dynamic library.static void
load(URL filename)
Loads a code file with the specified filename from the local file system as a dynamic library.static void
loadLibrary(String libname)
Loads the system library specified by thelibname
argument.static void
loadPlatformDependentLibrary(String libname)
Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...).static void
loadPlatformDependentLibrary(String path, String libname)
Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...).(package private) static void
loadPlatformDependentLibrary(String libname, String platform, String... paths)
Search and load the dynamic library which is fitting the current operating system (32 or 64bits operating system...).static void
setEnable(boolean enable)
Replies if this library loader is enable.
-
-
-
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, otherwisefalse
- 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
- istrue
to allow this loader to retreive native libraries, orfalse
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 itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the file does not exist.NullPointerException
- iffilename
isnull
- 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 itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the file does not exist.NullPointerException
- iffilename
isnull
- 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 itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the file does not exist.NullPointerException
- iffilename
isnull
- See Also:
System.load(java.lang.String)
-
loadLibrary
public static void loadLibrary(String libname)
Loads the system library specified by thelibname
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 callSystem.loadLibrary(name)
- Parameters:
libname
- the name of the library.- Throws:
SecurityException
- if a security manager exists and itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the library does not exist.NullPointerException
- iflibname
isnull
- 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 namedlibname64.dll
on Windows® andliblibname64.so
on Unix. A 32 bits library is assumed to be namedlibname32.dll
on Windows® andliblibname32.so
on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be namedlibname.dll
on Windows® andliblibname.so
on Unix.- Parameters:
libname
- is the name of the library.- Throws:
IOException
- when reading error occurs.SecurityException
- if a security manager exists and itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the file does not exist.NullPointerException
- iffilename
isnull
- 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 namedlibname64.dll
on Windows® andliblibname64.so
on Unix. A 32 bits library is assumed to be namedlibname32.dll
on Windows® andliblibname32.so
on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be namedlibname.dll
on Windows® andliblibname.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 itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the file does not exist.NullPointerException
- iffilename
isnull
- 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 namedlibname64.dll
on Windows® andliblibname64.so
on Unix. A 32 bits library is assumed to be namedlibname32.dll
on Windows® andliblibname32.so
on Unix. A library which could be ran either on 32 and 64 platforms is assumed to be namedlibname.dll
on Windows® andliblibname.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 itscheckLink
method doesn't allow loading of the specified dynamic libraryUnsatisfiedLinkError
- if the file does not exist.NullPointerException
- iffilename
isnull
- See Also:
System.load(java.lang.String)
-
-