Package com.formdev.flatlaf.util
Class NativeLibrary
- java.lang.Object
-
- com.formdev.flatlaf.util.NativeLibrary
-
public class NativeLibrary extends java.lang.Object
Helper class to load native library (.dll, .so or .dylib) stored in Jar.Copies native library to users temporary folder before loading it.
- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
DELETE_SUFFIX
private static boolean
deletedTemporary
private boolean
loaded
-
Constructor Summary
Constructors Constructor Description NativeLibrary(java.io.File libraryFile, boolean supported)
Load native library from given file.NativeLibrary(java.lang.String libraryName, boolean supported)
Load native library usingSystem.loadLibrary(String)
.NativeLibrary(java.lang.String libraryName, java.lang.ClassLoader classLoader, boolean supported)
Load native library from given classloader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.nio.file.Path
createTempFile(java.lang.String libraryName)
private static java.lang.String
decorateLibraryName(java.lang.String libraryName)
Add prefix and suffix to library name.private static void
deleteOrMarkForDeletion(java.io.File file)
private static void
deleteTemporaryFiles(java.nio.file.Path tempDir)
private static java.nio.file.Path
getTempDir()
boolean
isLoaded()
Returns whether the native library is loaded.private boolean
loadLibraryFromFile(java.io.File libraryFile)
private static boolean
loadLibraryFromJar(java.lang.String libraryName, java.lang.ClassLoader classLoader)
private boolean
loadLibraryFromSystem(java.lang.String libraryName)
-
-
-
Field Detail
-
DELETE_SUFFIX
private static final java.lang.String DELETE_SUFFIX
- See Also:
- Constant Field Values
-
deletedTemporary
private static boolean deletedTemporary
-
loaded
private final boolean loaded
-
-
Constructor Detail
-
NativeLibrary
public NativeLibrary(java.lang.String libraryName, java.lang.ClassLoader classLoader, boolean supported)
Load native library from given classloader.Note regarding Java Platform Module System (JPMS): If classloader is
null
, the library can be only loaded from the module that contains this class. If classloader is notnull
, then the package that contains the library must be specified as "open" in module-info.java of the module that contains the library.- Parameters:
libraryName
- resource name of the native library (without "lib" prefix and without extension)classLoader
- the classloader used to locate the library, ornull
supported
- whether the native library is supported on the current platform
-
NativeLibrary
public NativeLibrary(java.io.File libraryFile, boolean supported)
Load native library from given file.- Parameters:
libraryFile
- the file of the native librarysupported
- whether the native library is supported on the current platform- Since:
- 2
-
NativeLibrary
public NativeLibrary(java.lang.String libraryName, boolean supported)
Load native library usingSystem.loadLibrary(String)
. Searches for the library in classloader of caller (usingClassLoader.findLibrary(String)
) and in paths specified in system propertiessun.boot.library.path
andjava.library.path
.- Parameters:
libraryName
- name of the native library (without "lib" prefix and without extension)supported
- whether the native library is supported on the current platform- Since:
- 2.6
-
-
Method Detail
-
isLoaded
public boolean isLoaded()
Returns whether the native library is loaded.Returns
false
if not supported on current platform as specified in constructor or if loading failed.
-
loadLibraryFromJar
private static boolean loadLibraryFromJar(java.lang.String libraryName, java.lang.ClassLoader classLoader)
-
loadLibraryFromFile
private boolean loadLibraryFromFile(java.io.File libraryFile)
-
loadLibraryFromSystem
private boolean loadLibraryFromSystem(java.lang.String libraryName)
-
decorateLibraryName
private static java.lang.String decorateLibraryName(java.lang.String libraryName)
Add prefix and suffix to library name.- Windows: libraryName + ".dll"
- macOS: "lib" + libraryName + ".dylib"
- Linux: "lib" + libraryName + ".so"
-
createTempFile
private static java.nio.file.Path createTempFile(java.lang.String libraryName) throws java.io.IOException
- Throws:
java.io.IOException
-
getTempDir
private static java.nio.file.Path getTempDir() throws java.io.IOException
- Throws:
java.io.IOException
-
deleteTemporaryFiles
private static void deleteTemporaryFiles(java.nio.file.Path tempDir)
-
deleteOrMarkForDeletion
private static void deleteOrMarkForDeletion(java.io.File file)
-
-