Package arc.util
Class SharedLibraryLoader
java.lang.Object
arc.util.SharedLibraryLoader
Loads shared libraries from a natives jar file (desktop) or arm folders (Android). For desktop projects, have the natives jar
in the classpath, for Android projects put the shared libraries in the libs/armeabi and libs/armeabi-v7a folders.
-
Constructor Summary
ConstructorDescriptionSharedLibraryLoader
(String nativesJar) Fetches the natives from the given natives jar file. -
Method Summary
Modifier and TypeMethodDescriptioncrc
(InputStream input) Returns a CRC of the remaining bytes in the stream.extractFile
(String sourcePath, String dirName) Extracts the specified file to the specified directory if it does not already exist or the CRC does not match.protected File
extractFile
(String sourcePath, String sourceCrc, File extractedFile) void
extractFileTo
(String sourcePath, File dir) Extracts the specified file into the temp directory if it does not already exist or the CRC does not match.static boolean
void
Loads a shared library for the platform the application is running on.protected Throwable
mapLibraryName
(String libraryName) Maps a platform independent library name to a platform dependent name.protected InputStream
static void
Sets the library as loaded, for when application code wants to handle libary loading itself.
-
Constructor Details
-
SharedLibraryLoader
public SharedLibraryLoader() -
SharedLibraryLoader
Fetches the natives from the given natives jar file. Used for testing a shared lib on the fly.
-
-
Method Details
-
setLoaded
Sets the library as loaded, for when application code wants to handle libary loading itself. -
isLoaded
-
crc
Returns a CRC of the remaining bytes in the stream. -
mapLibraryName
Maps a platform independent library name to a platform dependent name. -
load
Loads a shared library for the platform the application is running on.- Parameters:
libraryName
- The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll).
-
readFile
-
extractFile
Extracts the specified file to the specified directory if it does not already exist or the CRC does not match. If file extraction fails and the file exists at java.library.path, that file is returned.- Parameters:
sourcePath
- The file to extract from the classpath or JAR.dirName
- The name of the subdirectory where the file will be extracted. If null, the file's CRC will be used.- Returns:
- The extracted file.
- Throws:
IOException
-
extractFileTo
Extracts the specified file into the temp directory if it does not already exist or the CRC does not match. If file extraction fails and the file exists at java.library.path, that file is returned.- Parameters:
sourcePath
- The file to extract from the classpath or JAR.dir
- The location where the extracted file will be written.- Throws:
IOException
-
extractFile
protected File extractFile(String sourcePath, String sourceCrc, File extractedFile) throws IOException - Throws:
IOException
-
loadFile
- Returns:
- null if the file was extracted and loaded.
-