java.lang.System.load()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(367)

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

System.load介绍

[英]Loads and links the dynamic library that is identified through the specified path. This method is similar to #loadLibrary(String), but it accepts a full path specification whereas loadLibrary just accepts the name of the library to load.
[中]加载并链接通过指定路径标识的动态库。此方法类似于#loadLibrary(String),但它接受完整路径规范,而loadLibrary只接受要加载的库的名称。

代码示例

代码示例来源:origin: netty/netty

  1. /**
  2. * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
  3. * @param libName - The native library path or name
  4. * @param absolute - Whether the native library will be loaded by path or by name
  5. */
  6. public static void loadLibrary(String libName, boolean absolute) {
  7. if (absolute) {
  8. System.load(libName);
  9. } else {
  10. System.loadLibrary(libName);
  11. }
  12. }

代码示例来源:origin: fengjiachun/Jupiter

  1. public static void load(String filename) {
  2. System.load(filename);
  3. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
  3. * @param libName - The native library path or name
  4. * @param absolute - Whether the native library will be loaded by path or by name
  5. */
  6. public static void loadLibrary(String libName, boolean absolute) {
  7. if (absolute) {
  8. System.load(libName);
  9. } else {
  10. System.loadLibrary(libName);
  11. }
  12. }

代码示例来源:origin: fengjiachun/Jupiter

  1. public static void load(String filename) {
  2. System.load(filename);
  3. }

代码示例来源:origin: wildfly/wildfly

  1. /**
  2. * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
  3. * @param libName - The native library path or name
  4. * @param absolute - Whether the native library will be loaded by path or by name
  5. */
  6. public static void loadLibrary(String libName, boolean absolute) {
  7. if (absolute) {
  8. System.load(libName);
  9. } else {
  10. System.loadLibrary(libName);
  11. }
  12. }

代码示例来源:origin: libgdx/libgdx

  1. /** @return null if the file was extracted and loaded. */
  2. private Throwable loadFile (String sourcePath, String sourceCrc, File extractedFile) {
  3. try {
  4. System.load(extractFile(sourcePath, sourceCrc, extractedFile).getAbsolutePath());
  5. return null;
  6. } catch (Throwable ex) {
  7. return ex;
  8. }
  9. }

代码示例来源:origin: redisson/redisson

  1. /**
  2. * Load a native library of snappy-java
  3. */
  4. private synchronized static void loadNativeLibrary()
  5. {
  6. if (!isLoaded) {
  7. try {
  8. nativeLibFile = findNativeLibrary();
  9. if (nativeLibFile != null) {
  10. // Load extracted or specified snappyjava native library.
  11. System.load(nativeLibFile.getAbsolutePath());
  12. } else {
  13. // Load preinstalled snappyjava (in the path -Djava.library.path)
  14. System.loadLibrary("snappyjava");
  15. }
  16. }
  17. catch (Exception e) {
  18. e.printStackTrace();
  19. throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
  20. }
  21. isLoaded = true;
  22. }
  23. }

代码示例来源:origin: libgdx/libgdx

  1. private boolean loadLibrary (String sharedLibName) {
  2. if (sharedLibName == null) return false;
  3. String path = extractLibrary(sharedLibName);
  4. if (path != null) System.load(path);
  5. return path != null;
  6. }

代码示例来源:origin: eclipsesource/J2V8

  1. static boolean load(final String libName, final StringBuffer message) {
  2. try {
  3. if (libName.indexOf(SEPARATOR) != -1) {
  4. System.load(libName);
  5. } else {
  6. System.loadLibrary(libName);
  7. }
  8. return true;
  9. } catch (UnsatisfiedLinkError e) {
  10. if (message.length() == 0) {
  11. message.append(DELIMITER);
  12. }
  13. message.append('\t');
  14. message.append(e.getMessage());
  15. message.append(DELIMITER);
  16. }
  17. return false;
  18. }

代码示例来源:origin: libgdx/libgdx

  1. /** @return null if the file was extracted and loaded. */
  2. private Throwable loadFile (String sourcePath, String sourceCrc, File extractedFile) {
  3. try {
  4. System.load(extractFile(sourcePath, sourceCrc, extractedFile).getAbsolutePath());
  5. return null;
  6. } catch (Throwable ex) {
  7. return ex;
  8. }
  9. }

代码示例来源:origin: libgdx/libgdx

  1. private boolean loadLibrary (String sharedLibName) {
  2. if (sharedLibName == null) return false;
  3. String path = extractLibrary(sharedLibName);
  4. if (path != null) System.load(path);
  5. return path != null;
  6. }

代码示例来源:origin: koral--/android-gif-drawable

  1. /**
  2. * Utilizes the regular system call to attempt to load a native library. If a failure occurs,
  3. * then the function extracts native .so library out of the app's APK and attempts to load it.
  4. * <p/>
  5. * <strong>Note: This is a synchronous operation</strong>
  6. */
  7. @SuppressLint("UnsafeDynamicallyLoadedCode") //intended fallback of System#loadLibrary()
  8. static void loadLibrary(Context context) {
  9. synchronized (ReLinker.class) {
  10. final File workaroundFile = unpackLibrary(context);
  11. System.load(workaroundFile.getAbsolutePath());
  12. }
  13. }

代码示例来源:origin: iBotPeaches/Apktool

  1. public static void load(String libPath) {
  2. if (mLoaded.contains(libPath)) {
  3. return;
  4. }
  5. File libFile;
  6. try {
  7. libFile = getResourceAsFile(libPath);
  8. } catch (BrutException ex) {
  9. throw new UnsatisfiedLinkError(ex.getMessage());
  10. }
  11. System.load(libFile.getAbsolutePath());
  12. }

代码示例来源:origin: stackoverflow.com

  1. private static void loadLib(String path, String name) {
  2. name = System.mapLibraryName(name); // extends name with .dll, .so or .dylib
  3. try {
  4. InputStream in = ACWrapper.class.getResourceAsStream("/"+path + name);
  5. File fileOut = new File("your lib path");
  6. OutputStream out = FileUtils.openOutputStream(fileOut);
  7. IOUtils.copy(in, out);
  8. in.close();
  9. out.close();
  10. System.load(fileOut.toString());//loading goes here
  11. } catch (Exception e) {
  12. //handle
  13. }
  14. }

代码示例来源:origin: stackoverflow.com

  1. public static void loadJarDll(String name) throws IOException {
  2. InputStream in = MyClass.class.getResourceAsStream(name);
  3. byte[] buffer = new byte[1024];
  4. int read = -1;
  5. File temp = File.createTempFile(name, "");
  6. FileOutputStream fos = new FileOutputStream(temp);
  7. while((read = in.read(buffer)) != -1) {
  8. fos.write(buffer, 0, read);
  9. }
  10. fos.close();
  11. in.close();
  12. System.load(temp.getAbsolutePath());
  13. }

代码示例来源:origin: aragozin/jvm-tools

  1. private static void load(File tmp, String arch) throws IOException {
  2. InputStream is = SjkWinHelper.class.getClassLoader().getResourceAsStream("sjkwinh.prop");
  3. Properties prop = new Properties();
  4. prop.load(is);
  5. String dllName = "sjkwinh" + arch + "." + prop.getProperty("dll" + arch + ".hash") + ".dll";
  6. int len = Integer.valueOf(prop.getProperty("dll" + arch + ".len"));
  7. File tgt = new File(tmp, dllName);
  8. if (tgt.isFile() && tgt.length() == len) {
  9. // dll is present
  10. }
  11. else {
  12. tgt.delete();
  13. InputStream dllis = SjkWinHelper.class.getClassLoader().getResourceAsStream("sjkwinh" + arch + ".dll");
  14. byte[] buf = new byte[len];
  15. int n = dllis.read(buf);
  16. if (n != buf.length) {
  17. throw new RuntimeException("Failed extract dll, size mismatch");
  18. }
  19. FileOutputStream fos = new FileOutputStream(tgt);
  20. fos.write(buf);
  21. fos.close();
  22. }
  23. System.load(tgt.getPath());
  24. }

代码示例来源:origin: libgdx/libgdx

  1. /** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime
  2. * exception if all fail. */
  3. private void loadFile (String sourcePath) {
  4. String sourceCrc = crc(readFile(sourcePath));
  5. String fileName = new File(sourcePath).getName();
  6. // Temp directory with username in path.
  7. File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc,
  8. fileName);
  9. Throwable ex = loadFile(sourcePath, sourceCrc, file);
  10. if (ex == null) return;
  11. // System provided temp directory.
  12. try {
  13. file = File.createTempFile(sourceCrc, null);
  14. if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return;
  15. } catch (Throwable ignored) {
  16. }
  17. // User home.
  18. file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName);
  19. if (loadFile(sourcePath, sourceCrc, file) == null) return;
  20. // Relative directory.
  21. file = new File(".temp/" + sourceCrc, fileName);
  22. if (loadFile(sourcePath, sourceCrc, file) == null) return;
  23. // Fallback to java.library.path location, eg for applets.
  24. file = new File(System.getProperty("java.library.path"), sourcePath);
  25. if (file.exists()) {
  26. System.load(file.getAbsolutePath());
  27. return;
  28. }
  29. throw new GdxRuntimeException(ex);
  30. }

代码示例来源:origin: libgdx/libgdx

  1. /** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime
  2. * exception if all fail. */
  3. private void loadFile (String sourcePath) {
  4. String sourceCrc = crc(readFile(sourcePath));
  5. String fileName = new File(sourcePath).getName();
  6. // Temp directory with username in path.
  7. File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc,
  8. fileName);
  9. Throwable ex = loadFile(sourcePath, sourceCrc, file);
  10. if (ex == null) return;
  11. // System provided temp directory.
  12. try {
  13. file = File.createTempFile(sourceCrc, null);
  14. if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return;
  15. } catch (Throwable ignored) {
  16. }
  17. // User home.
  18. file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName);
  19. if (loadFile(sourcePath, sourceCrc, file) == null) return;
  20. // Relative directory.
  21. file = new File(".temp/" + sourceCrc, fileName);
  22. if (loadFile(sourcePath, sourceCrc, file) == null) return;
  23. // Fallback to java.library.path location, eg for applets.
  24. file = new File(System.getProperty("java.library.path"), sourcePath);
  25. if (file.exists()) {
  26. System.load(file.getAbsolutePath());
  27. return;
  28. }
  29. throw new GdxRuntimeException(ex);
  30. }

代码示例来源:origin: libgdx/libgdx

  1. public static void init () {
  2. if (initialized) return;
  3. // Need to initialize bullet before using it.
  4. if (Gdx.app.getType() == ApplicationType.Desktop && customDesktopLib != null) {
  5. System.load(customDesktopLib);
  6. } else
  7. Bullet.init();
  8. Gdx.app.log("Bullet", "Version = " + LinearMath.btGetVersion());
  9. initialized = true;
  10. }

代码示例来源:origin: Tencent/tinker

  1. tinker.getLoadReporter().onLoadFileMd5Mismatch(library, ShareConstants.TYPE_LIBRARY);
  2. } else {
  3. System.load(patchLibraryPath);
  4. TinkerLog.i(TAG, "loadLibraryFromTinker success:" + patchLibraryPath);
  5. return true;

相关文章