Package arc.util

Class SharedLibraryLoader

java.lang.Object
arc.util.SharedLibraryLoader

public class SharedLibraryLoader extends Object
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 Details

    • SharedLibraryLoader

      public SharedLibraryLoader()
    • SharedLibraryLoader

      public SharedLibraryLoader(String nativesJar)
      Fetches the natives from the given natives jar file. Used for testing a shared lib on the fly.
  • Method Details

    • setLoaded

      public static void setLoaded(String libraryName)
      Sets the library as loaded, for when application code wants to handle libary loading itself.
    • isLoaded

      public static boolean isLoaded(String libraryName)
    • crc

      public String crc(InputStream input)
      Returns a CRC of the remaining bytes in the stream.
    • mapLibraryName

      public String mapLibraryName(String libraryName)
      Maps a platform independent library name to a platform dependent name.
    • load

      public void load(String libraryName)
      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

      protected InputStream readFile(String path)
    • extractFile

      public File extractFile(String sourcePath, String dirName) throws IOException
      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

      public void extractFileTo(String sourcePath, File dir) throws IOException
      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

      protected Throwable loadFile(String sourcePath, String sourceCrc, File extractedFile)
      Returns:
      null if the file was extracted and loaded.