Class NativeResourceLoader

java.lang.Object
be.yildizgames.common.libloader.NativeResourceLoader

public final class NativeResourceLoader
extends Object
Utility class to load the native library from the classpath or a jar.
Author:
Grégory Van den Borre
  • Field Details

    • directory

      public final String directory
      Directory containing the native libraries, win34, linux64 depending on the operating system and the underlying architecture.
    • libDirectory

      public final Path libDirectory
      Will contains the native libraries to be loaded.
    • libraryExtension

      public final String libraryExtension
      Library file extension, can be .dll on windows, .so on linux.
  • Method Details

    • inJar

      public static NativeResourceLoader inJar​(be.yildizgames.common.os.OperatingSystem... systemToSupport)
      Retrieve the libraries in the class pass, decompress them and register them.
      Parameters:
      systemToSupport - The list of system to support, cannot be null.
      Returns:
      The created loader, never null.
    • inJar

      public static NativeResourceLoader inJar()
      Retrieve the libraries in the class pass, decompress them and register them, support all systems.
      Returns:
      The created loader, never null.
    • inJar

      public static NativeResourceLoader inJar​(String path, be.yildizgames.common.os.OperatingSystem... systemToSupport)
      Retrieve the libraries in the class pass, decompress them in the provided path and register them.
      Parameters:
      path - Directory where the libs will be copied, cannot be null.
      systemToSupport - The list of system to support, cannot be null.
      Returns:
      The created loader, never null.
    • inJar

      public static NativeResourceLoader inJar​(String path)
    • inPath

      public static NativeResourceLoader inPath​(String path, be.yildizgames.common.os.OperatingSystem... systemToSupport)
    • inTestPath

      public static NativeResourceLoader inTestPath​(be.yildizgames.common.os.OperatingSystem... systemToSupport)
    • external

      public static NativeResourceLoader external​(be.yildizgames.common.os.OperatingSystem... systemToSupport)
      Use libraries from a given path and register them.
      Parameters:
      systemToSupport - The list of system to support.
      Returns:
      The created loader.
    • getLibPath

      public String getLibPath​(String lib)
      Give the full path of a registered native library.
      Parameters:
      lib - Library to check.
      Returns:
      The absolute path of the given library.
    • loadLibrary

      public void loadLibrary​(String... libs)
      Load a native library, it will check if it is contained in a jar, if so, the library will be extracted in a temporary place and loaded from there.
      Parameters:
      libs - Native library name to load, cannot be null.
    • loadBaseLibrary

      public void loadBaseLibrary​(String... libs)
      To load the shared libraries, only used for windows, on linux, will not load anything.
      Parameters:
      libs - Libraries to be loaded only on windows.
    • getLoadedLibraries

      public List<String> getLoadedLibraries()