Class JarLibraryLoader

java.lang.Object
com.lambdaworks.jni.JarLibraryLoader
All Implemented Interfaces:
LibraryLoader

public class JarLibraryLoader extends Object implements LibraryLoader
A native library loader that will extract and load a shared library contained in a jar. This loader will attempt to detect the platform (CPU architecture and OS) it is running on and load the appropriate shared library. Given a library path and name this loader looks for a native library with path [libraryPath]/[arch]/[os]/lib[name].[ext]
  • Field Details

    • codeSource

      private final CodeSource codeSource
    • libraryPath

      private final String libraryPath
  • Constructor Details

    • JarLibraryLoader

      public JarLibraryLoader()
      Initialize a new instance that looks for shared libraries located in the same jar as this class and with a path starting with lib.
    • JarLibraryLoader

      public JarLibraryLoader(CodeSource codeSource, String libraryPath)
      Initialize a new instance that looks for shared libraries located in the specified directory of the supplied code source.
      Parameters:
      codeSource - Code source containing shared libraries.
      libraryPath - Path prefix of shared libraries.
  • Method Details

    • load

      public boolean load(String name, boolean verify)
      Load a shared library, and optionally verify the jar signatures.
      Specified by:
      load in interface LibraryLoader
      Parameters:
      name - Name of the library to load.
      verify - Verify the jar file if signed.
      Returns:
      true if the library was successfully loaded.
    • extract

      private static File extract(String name, InputStream is) throws IOException
      Extract a jar entry to a temp file.
      Parameters:
      name - Name prefix for temp file.
      is - Jar entry input stream.
      Returns:
      A temporary file.
      Throws:
      IOException - when an IO error occurs.
    • libCandidates

      private List<String> libCandidates(Platform platform, String name)
      Generate a list of candidate libraries for the supplied library name and suitable for the current platform.
      Parameters:
      platform - Current platform.
      name - Library name.
      Returns:
      List of potential library names.