Class JarLibraryLoader

  • All Implemented Interfaces:
    LibraryLoader

    public class JarLibraryLoader
    extends java.lang.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 Summary

      Fields 
      Modifier and Type Field Description
      private java.security.CodeSource codeSource  
      private java.lang.String libraryPath  
    • Constructor Summary

      Constructors 
      Constructor Description
      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​(java.security.CodeSource codeSource, java.lang.String libraryPath)
      Initialize a new instance that looks for shared libraries located in the specified directory of the supplied code source.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.io.File extract​(java.lang.String name, java.io.InputStream is)
      Extract a jar entry to a temp file.
      private java.util.List<java.lang.String> libCandidates​(Platform platform, java.lang.String name)
      Generate a list of candidate libraries for the supplied library name and suitable for the current platform.
      boolean load​(java.lang.String name, boolean verify)
      Load a shared library, and optionally verify the jar signatures.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • codeSource

        private final java.security.CodeSource codeSource
      • libraryPath

        private final java.lang.String libraryPath
    • Constructor Detail

      • 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​(java.security.CodeSource codeSource,
                                java.lang.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 Detail

      • load

        public boolean load​(java.lang.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 java.io.File extract​(java.lang.String name,
                                            java.io.InputStream is)
                                     throws java.io.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:
        java.io.IOException - when an IO error occurs.
      • libCandidates

        private java.util.List<java.lang.String> libCandidates​(Platform platform,
                                                               java.lang.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.