com.sun.jna.Native.load()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(1626)

本文整理了Java中com.sun.jna.Native.load()方法的一些代码示例,展示了Native.load()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Native.load()方法的具体详情如下:
包路径:com.sun.jna.Native
类名称:Native
方法名:load

Native.load介绍

[英]Map a library interface to the current process, providing the explicit interface class. Native libraries loaded via this method may be found in several locations.
[中]将库接口映射到当前进程,提供显式接口类。通过此方法加载的本机库可以在several locations中找到。

代码示例

代码示例来源:origin: net.java.dev.jna/jna

/** Map a library interface to the current process, providing
 * the explicit interface class.
 * Native libraries loaded via this method may be found in
 * <a href="NativeLibrary.html#library_search_paths">several locations</a>.
 * @param <T> Type of expected wrapper
 * @param interfaceClass The implementation wrapper interface
 * @return an instance of the requested interface, mapped to the current
 * process.
 * @throws UnsatisfiedLinkError if the library cannot be found or
 * dependent libraries are missing.
 */
public static <T extends Library> T load(Class<T> interfaceClass) {
  return load(null, interfaceClass);
}

代码示例来源:origin: net.java.dev.jna/jna

/** Map a library interface to the current process, providing
 * the explicit interface class.  Any options provided for the library are
 * cached and associated with the library and any of its defined
 * structures and/or functions.
 * Native libraries loaded via this method may be found in
 * <a href="NativeLibrary.html#library_search_paths">several locations</a>.
 * @param <T> Type of expected wrapper
 * @param interfaceClass The implementation wrapper interface
 * @param options Map of library options
 * @return an instance of the requested interface, mapped to the current
 * process.
 * @throws UnsatisfiedLinkError if the library cannot be found or
 * dependent libraries are missing.
 * @see #load(String, Class, Map)
 */
public static <T extends Library> T load(Class<T> interfaceClass, Map<String, ?> options) {
  return load(null, interfaceClass, options);
}

代码示例来源:origin: net.java.dev.jna/jna

/** Map a library interface to the given shared library, providing
 * the explicit interface class.
 * If <code>name</code> is null, attempts to map onto the current process.
 * Native libraries loaded via this method may be found in
 * <a href="NativeLibrary.html#library_search_paths">several locations</a>.
 * @param <T> Type of expected wrapper
 * @param name Library base name
 * @param interfaceClass The implementation wrapper interface
 * @return an instance of the requested interface, mapped to the indicated
 * native library.
 * @throws UnsatisfiedLinkError if the library cannot be found or
 * dependent libraries are missing.
 * @see #load(String, Class, Map)
 */
public static <T extends Library> T load(String name, Class<T> interfaceClass) {
  return load(name, interfaceClass, Collections.<String, Object>emptyMap());
}

代码示例来源:origin: uk.co.caprica/vlcj

/**
 * Run native discovery, if set, and attempt to load the native library.
 *
 * @param discovery native discovery used to find the native library, may be <code>null</code>
 * @return native library
 */
private LibVlc discoverNativeLibrary(NativeDiscovery discovery) {
  if (discovery != null) {
    // The discover method return value is not currently used, since we try and load the native library whether
    // discovery worked or not
    discovery.discover();
  }
  LibVlc nativeLibrary = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
  checkVersion(nativeLibrary);
  // A synchronised library is required since there are multiple asynchronous task queues in use that could
  // potentially call into LibVLC concurrently
  return (LibVlc) Native.synchronizedLibrary(nativeLibrary);
}

代码示例来源:origin: uk.co.caprica/vlcj

/**
 * Attempt to load the native library.
 * <p>
 * This is done immediately after discovery so that any error condition can be handled as early as possible.
 */
private boolean tryLoadingLibrary() {
  try {
    LibVlc libvlc = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
    libvlc_instance_t instance = libvlc.libvlc_new(0, new String[0]);
    if (instance != null) {
      libvlc.libvlc_release(instance);
      LibVlcVersion version = new LibVlcVersion(libvlc);
      if (version.isSupported()) {
        return true;
      }
    }
  }
  catch (UnsatisfiedLinkError e) {
  }
  return false;
}

代码示例来源:origin: uk.co.caprica/vlcj

/**
 * Execute the test.
 * <p>
 * This will throw a RuntimeException if the libvlc native library version is too old.
 *
 * @param args command-line arguments
 */
public static void main(String[] args) {
  LibVlc libvlc = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
  String version = libvlc.libvlc_get_version();
  test("2.1.0", version);
}

代码示例来源:origin: uk.co.caprica/vlcj

public static void main(String[] args) throws Exception {
    LibVlc libvlc = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

    libvlc_instance_t instance = libvlc.libvlc_new(0, new String[] {});

    libvlc_media_t media = libvlc.libvlc_media_new_path(instance, args[0]);

    libvlc.libvlc_media_parse_with_options(media, 0, 0); // <--- FATAL VM CRASH IF RUNNING on 32-bit Ubuntu and Java7

    Thread.sleep(1000);

    libvlc.libvlc_media_release(media);

    libvlc.libvlc_release(instance);

    System.exit(0);
  }
}

代码示例来源:origin: uk.co.caprica/vlcj

public static void main(String[] args) {
  NativeDiscovery discovery = new NativeDiscovery() {
    @Override
    protected void onFound(String path, NativeDiscoveryStrategy strategy) {
      System.out.println("Found");
      System.out.println(path);
      System.out.println(strategy);
    }
    @Override
    protected void onNotFound() {
      System.out.println("Not found");
    }
  };
  boolean found = discovery.discover();
  System.out.println(found);
  LibVlc nativeLibrary = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
  System.out.println("Loaded library " + nativeLibrary);
  libvlc_instance_t instance = nativeLibrary.libvlc_new(0, new String[0]);
  System.out.println("instance " + instance);
  if (instance != null) {
    nativeLibrary.libvlc_release(instance);
  }
  System.out.println(new LibVlcVersion(nativeLibrary).getVersion());
}

代码示例来源:origin: uk.co.caprica/vlcj

public static void main(String[] args) throws Exception {
    LibVlc libvlc = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

    libvlc_instance_t instance = libvlc.libvlc_new(0, new String[] {});

    libvlc_media_player_t mediaPlayer = libvlc.libvlc_media_player_new(instance);
    libvlc_media_t media = libvlc.libvlc_media_new_path(instance, args[0]);
    libvlc.libvlc_media_player_set_media(mediaPlayer, media);
    libvlc.libvlc_media_player_play(mediaPlayer);

    Thread.sleep(10000);

    libvlc.libvlc_media_player_stop(mediaPlayer);
    libvlc.libvlc_media_release(media);
    libvlc.libvlc_media_player_release(mediaPlayer);

    libvlc.libvlc_release(instance);

    System.exit(0);
  }
}

代码示例来源:origin: uk.co.caprica/vlcj

public BareBonesEmbeddedTest() {
  libvlc = Native.load(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);

相关文章

Native类方法