java.lang.Object
ca.weblite.nativeutils.NativeUtils
Simple library class for working with JNI (Java Native Interface)
-
Method Summary
Modifier and TypeMethodDescriptionstatic PathextractFromJar(String path, Class<?> source) Extracts a resource from the JAR and stores it as temporary file in the file system.static voidloadLibraryFromJar(String path) Loads a library from current JAR archive, using the class loader of theNativeUtilsclass to find the resource in the JAR.static voidloadLibraryFromJar(String path, Class<?> source) Loads a library from current JAR archive.
-
Method Details
-
loadLibraryFromJar
Loads a library from current JAR archive, using the class loader of theNativeUtilsclass to find the resource in the JAR.- Parameters:
path- aStringobject.- Throws:
IOException- if any.UnsatisfiedLinkError- if loading the native library fails.
-
loadLibraryFromJar
public static void loadLibraryFromJar(String path, Class<?> source) throws IOException, UnsatisfiedLinkError Loads a library from current JAR archive. The file from JAR is copied into system temporary directory and then loaded. The temporary file is deleted after exiting. Method uses String as filename because the pathname is "abstract", not system-dependent.- Parameters:
path- aStringobject.source-Classwhose class loader should be used to look up the resource in the JAR file- Throws:
IllegalArgumentException- If the path is not absolute or if the filename is shorter than three characters (restriction of @see File#createTempFile(java.lang.String, java.lang.String)).IOException- if any.UnsatisfiedLinkError- if loading the native library fails.
-
extractFromJar
Extracts a resource from the JAR and stores it as temporary file in the file system.- Parameters:
path- path of the resource, must begin with'/', seeClass.getResourceAsStream(String)source-Classwhose class loader should be used to look up the resource in the JAR file- Returns:
- file path of the temporary file extracted from this JAR
- Throws:
IOException- if any.
-