Class NativeLibrary
java.lang.Object
com.formdev.flatlaf.util.NativeLibrary
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
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate static booleanprivate final boolean -
Constructor Summary
ConstructorsConstructorDescriptionNativeLibrary(File libraryFile, boolean supported) Load native library from given file.NativeLibrary(String libraryName, boolean supported) Load native library usingSystem.loadLibrary(String)RESTRICTED.NativeLibrary(String libraryName, ClassLoader classLoader, boolean supported) Load native library from given classloader. -
Method Summary
Modifier and TypeMethodDescriptionprivate static PathcreateTempFile(String libraryName) private static StringdecorateLibraryName(String libraryName) Add prefix and suffix to library name.private static voiddeleteOrMarkForDeletion(File file) private static voiddeleteTemporaryFiles(Path tempDir) private static PathbooleanisLoaded()Returns whether the native library is loaded.private booleanloadLibraryFromFile(File libraryFile) private static booleanloadLibraryFromJar(String libraryName, ClassLoader classLoader) private booleanloadLibraryFromSystem(String libraryName)
-
Field Details
-
DELETE_SUFFIX
- See Also:
-
deletedTemporary
private static boolean deletedTemporary -
loaded
private final boolean loaded
-
-
Constructor Details
-
NativeLibrary
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, ornullsupported- whether the native library is supported on the current platform
-
NativeLibrary
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
Load native library usingSystem.loadLibrary(String)RESTRICTED. Searches for the library in classloader of caller (usingClassLoader.findLibrary(String)) and in paths specified in system propertiessun.boot.library.pathandjava.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 Details
-
isLoaded
public boolean isLoaded()Returns whether the native library is loaded.Returns
falseif not supported on current platform as specified in constructor or if loading failed. -
loadLibraryFromJar
-
loadLibraryFromFile
-
loadLibraryFromSystem
-
decorateLibraryName
-
createTempFile
- Throws:
IOException
-
getTempDir
- Throws:
IOException
-
deleteTemporaryFiles
-
deleteOrMarkForDeletion
-