Class NativeUtils

java.lang.Object
ca.weblite.nativeutils.NativeUtils

public class NativeUtils extends Object
Simple library class for working with JNI (Java Native Interface)
See Also:
  • Method Details

    • loadLibraryFromJar

      public static void loadLibraryFromJar(String path) throws IOException
      Loads a library from current JAR archive, using the class loader of the NativeUtils class to find the resource in the JAR.
      Parameters:
      path - a String object.
      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 - a String object.
      source - Class whose 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

      public static Path extractFromJar(String path, Class<?> source) throws IOException
      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 '/', see Class.getResourceAsStream(String)
      source - Class whose 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.