Package com.lambdaworks.jni
Class JarLibraryLoader
- java.lang.Object
-
- com.lambdaworks.jni.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 theplatform(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.CodeSourcecodeSourceprivate java.lang.StringlibraryPath
-
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 withlib.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.Fileextract(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.booleanload(java.lang.String name, boolean verify)Load a shared library, and optionally verify the jar signatures.
-
-
-
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 withlib.
-
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:
loadin interfaceLibraryLoader- 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.IOExceptionExtract 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.
-
-