Class LibraryLoader

java.lang.Object
org.jblas.util.LibraryLoader

public class LibraryLoader extends Object
Class which allows to load a dynamic file as resource (for example, from a jar-file)
  • Field Details

    • logger

      private Logger logger
    • libpath

      private String libpath
    • tempDir

      private static File tempDir
  • Constructor Details

    • LibraryLoader

      public LibraryLoader()
  • Method Details

    • loadLibrary

      public void loadLibrary(String libname, boolean withFlavor)

      Find the library libname as a resource, copy it to a tempfile and load it using System.load(). The name of the library has to be the base name, it is mapped to the corresponding system name using System.mapLibraryName(). For example, the library "foo" is called "libfoo.so" under Linux and "foo.dll" under Windows, but you just have to pass "foo" the loadLibrary().

      I'm not quite sure if this doesn't open all kinds of security holes. Any ideas?

      This function reports some more information to the "org.jblas" logger at the FINE level.

      Parameters:
      libname - basename of the library
      Throws:
      UnsatisfiedLinkError - if library cannot be founds
    • findLibrary

      private InputStream findLibrary(String[] paths, String libname)
    • unifyOSName

      private static String unifyOSName(String osname)
      Translate all those Windows to "Windows". ("Windows XP", "Windows Vista", "Windows 7", etc.)
    • getUnifiedOSName

      private static String getUnifiedOSName()
    • fatJarLibraryPath

      private String fatJarLibraryPath(String linkage, String flavor)
      Compute the path to the library. The path is basically "/" + os.name + "/" + os.arch + "/" + libname.
    • tryPath

      private InputStream tryPath(String path)
      Try to open a file at the given position.
    • createTempFile

      private File createTempFile(String name) throws IOException
      Throws:
      IOException
    • loadLibraryFromStream

      private void loadLibraryFromStream(String libname, InputStream is)
      Load a system library from a stream. Copies the library to a temp file and loads from there.
      Parameters:
      libname - name of the library (just used in constructing the library name)
      is - InputStream pointing to the library