Class ZstdNativesLoader

java.lang.Object
dev.freya02.discord.zstd.api.ZstdNativesLoader

@NullMarked public class ZstdNativesLoader extends Object
Utility class to load Zstd natives.

An alternative to load natives is to set the zstd.lib system property to the absolute path of the native library.

  • Constructor Details

    • ZstdNativesLoader

      public ZstdNativesLoader()
  • Method Details

    • isLoaded

      public static boolean isLoaded()
      Whether natives were already loaded. This only considers natives loaded by this class.
      Returns:
      true if natives are loaded
    • load

      public static boolean load(Path path)
      Loads the natives from the provided path's file.
      Parameters:
      path - The path to the native library
      Returns:
      true if the natives were loaded, false if they already were
      Throws:
      IllegalArgumentException - If path is null
    • loadFromJar

      public static boolean loadFromJar() throws IOException
      Loads the natives from this library's JAR.
      Returns:
      true if the natives were loaded, false if they already were
      Throws:
      UnsupportedOperationException - If the current platform (OS + architecture) is not supported by default
      IOException - When the native extraction fails
    • loadFromJar

      public static boolean loadFromJar(String resourcePath, Class<?> clazz) throws IOException
      Loads the natives using the provided path from the provided class.

      Remember the resource path is relative to the provided class, unless prefixed with /.

      Parameters:
      resourcePath - The path to the native library in the provided class
      clazz - The class from which to relatively load the resource from
      Returns:
      true if the natives were loaded, false if they already were
      Throws:
      IllegalArgumentException - If resourcePath or clazz is null
      IOException - If the resource does not exist or when extracting it fails