Top Description Fields Constructors Methods
org.fusesource.hawtjni.runtime

public Class Library

extends Object
Class Inheritance
Imports
java.io.*, java.lang.reflect.Method, java.net.URL, java.security.MessageDigest, .NoSuchAlgorithmException, java.util.ArrayList, .Arrays, .Set

Used to find and load a JNI library, eventually after having extracted it. It will search for the library in order at the following locations:
  1. in the custom library path: If the "library.${name}.path" System property is set to a directory, subdirectories are searched:
    1. "${platform}/${arch}"
    2. "${platform}"
    3. "${os}"
    for 2 namings of the library:
    1. as "${name}-${version}" library name if the version can be determined.
    2. as "${name}" library name
  2. system library path: This is where the JVM looks for JNI libraries by default.
    1. as "${name}${bit-model}-${version}" library name if the version can be determined.
    2. as "${name}-${version}" library name if the version can be determined.
    3. as "${name}" library name
  3. classpath path: If the JNI library can be found on the classpath, it will get extracted and then loaded. This way you can embed your JNI libraries into your packaged JAR files. They are looked up as resources in this order:
    1. "META-INF/native/${platform}/${arch}/${library[-version]}": Store your library here if you want to embed more than one platform JNI library on different processor archs in the jar.
    2. "META-INF/native/${platform}/${library[-version]}": Store your library here if you want to embed more than one platform JNI library in the jar.
    3. "META-INF/native/${os}/${library[-version]}": Store your library here if you want to embed more than one platform JNI library in the jar but don't want to take bit model into account.
    4. "META-INF/native/${library[-version]}": Store your library here if your JAR is only going to embedding one platform library.
    The file extraction is attempted until it succeeds in the following directories.
    1. The directory pointed to by the "library.${name}.path" System property (if set)
    2. a temporary directory (uses the "java.io.tmpdir" System property)
where:
Author
Hiram Chirino
See Also
System#mapLibraryName(String)

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private boolean
private final String
private String
private URL
pack-priv static final String
pack-priv static final String
public static final String
public static final String
public static final String
private final String

Constructor Summary

AccessConstructor and Description
public
public
Library(String name, Class<?> clazz)

public
Library(String name, String version)

public
Library(String name, String version, ClassLoader classLoader)

Method Summary

Modifier and TypeMethod and Description
private void
chmod755(File file)

private static void
private String
private void
private boolean
extractAndLoad(ArrayList<Throwable> errors, String customPath, String dir, String libName, String targetLibName)

private File
extractSha1(ArrayList<Throwable> errors, URL source, String prefix, String suffix, File directory)

private File
extractTemp(ArrayList<Throwable> errors, URL source, String prefix, String suffix, File directory)

private File
file(String... paths)

public final String
public final String
public static int
public final String
public String

Returns:

the path (should not be null once the library is loaded)
getNativeLibraryPath
()

Get the path to the native library loaded.

public URL

Returns:

the url to the source (in classpath)
getNativeLibrarySourceUrl
()

Get the URL to the native library source that has been extracted (if it was extracted).

public static String
public final String
public final String
public static String
public final String
public final String
public final String
public final String
public final String
getResorucePath()

Deprecated
public final String
public final String[]

Returns:

the list
getSpecificSearchDirs
()

Search directories for library:

  • ${platform}/${arch} to enable platform JNI library for different processor archs
  • ${platform} to enable platform JNI library
  • ${os} to enable OS JNI library
  • no directory
public synchronized void
load()

Load the native library.

private boolean
load(ArrayList<Throwable> errors, File lib)

private boolean
private String
map(String libName)

private static String
version(Class<?> clazz)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classLoaderback to summary
private final ClassLoader classLoader
loadedback to summary
private boolean loaded
nameback to summary
private final String name
nativeLibraryPathback to summary
private String nativeLibraryPath
nativeLibrarySourceUrlback to summary
private URL nativeLibrarySourceUrl
SLASHback to summary
pack-priv static final String SLASH
STRATEGYback to summary
pack-priv static final String STRATEGY
STRATEGY_PROPERTYback to summary
public static final String STRATEGY_PROPERTY
STRATEGY_SHA1back to summary
public static final String STRATEGY_SHA1
STRATEGY_TEMPback to summary
public static final String STRATEGY_TEMP
versionback to summary
private final String version

Constructor Detail

Libraryback to summary
public Library(String name)
Libraryback to summary
public Library(String name, Class<?> clazz)
Libraryback to summary
public Library(String name, String version)
Libraryback to summary
public Library(String name, String version, ClassLoader classLoader)

Method Detail

chmod755back to summary
private void chmod755(File file)
closeback to summary
private static void close(Closeable file)
computeSha1back to summary
private String computeSha1(InputStream is) throws NoSuchAlgorithmException, IOException
doLoadback to summary
private void doLoad()
extractAndLoadback to summary
private boolean extractAndLoad(ArrayList<Throwable> errors, String customPath, String dir, String libName, String targetLibName)
extractSha1back to summary
private File extractSha1(ArrayList<Throwable> errors, URL source, String prefix, String suffix, File directory)
extractTempback to summary
private File extractTemp(ArrayList<Throwable> errors, URL source, String prefix, String suffix, File directory)
fileback to summary
private File file(String... paths)
getArchSpecifcResourcePathback to summary
public final String getArchSpecifcResourcePath()

Deprecated

Annotations
@Deprecated
getArchSpecificResourcePathback to summary
public final String getArchSpecificResourcePath()
getBitModelback to summary
public static int getBitModel()
getLibraryFileNameback to summary
public final String getLibraryFileName()
getNativeLibraryPathback to summary
public String getNativeLibraryPath()

Get the path to the native library loaded.

Returns:String

the path (should not be null once the library is loaded)

Since
1.16
getNativeLibrarySourceUrlback to summary
public URL getNativeLibrarySourceUrl()

Get the URL to the native library source that has been extracted (if it was extracted).

Returns:URL

the url to the source (in classpath)

Since
1.16
getOperatingSystemback to summary
public static String getOperatingSystem()
getOperatingSystemSpecifcResourcePathback to summary
public final String getOperatingSystemSpecifcResourcePath()

Deprecated

Annotations
@Deprecated
getOperatingSystemSpecificResourcePathback to summary
public final String getOperatingSystemSpecificResourcePath()
getPlatformback to summary
public static String getPlatform()
getPlatformSpecifcResourcePathback to summary
public final String getPlatformSpecifcResourcePath()

Deprecated

Annotations
@Deprecated
getPlatformSpecifcResourcePathback to summary
public final String getPlatformSpecifcResourcePath(String platform)

Deprecated

Annotations
@Deprecated
getPlatformSpecificResourcePathback to summary
public final String getPlatformSpecificResourcePath()
getPlatformSpecificResourcePathback to summary
public final String getPlatformSpecificResourcePath(String platform)
getResorucePathback to summary
public final String getResorucePath()

Deprecated

Annotations
@Deprecated
getResourcePathback to summary
public final String getResourcePath()
getSpecificSearchDirsback to summary
public final String[] getSpecificSearchDirs()

Search directories for library:

  • ${platform}/${arch} to enable platform JNI library for different processor archs
  • ${platform} to enable platform JNI library
  • ${os} to enable OS JNI library
  • no directory
Returns:String[]

the list

Since
1.15
loadback to summary
public synchronized void load()

Load the native library.

loadback to summary
private boolean load(ArrayList<Throwable> errors, File lib)
loadLibraryback to summary
private boolean loadLibrary(ArrayList<Throwable> errors, String lib)
mapback to summary
private String map(String libName)
versionback to summary
private static String version(Class<?> clazz)