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

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

本文整理了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

/**
 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
 * @param libName - The native library path or name
 * @param absolute - Whether the native library will be loaded by path or by name
 */
public static void loadLibrary(String libName, boolean absolute) {
  if (absolute) {
    System.load(libName);
  } else {
    System.loadLibrary(libName);
  }
}

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

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

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

/**
 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
 * @param libName - The native library path or name
 * @param absolute - Whether the native library will be loaded by path or by name
 */
public static void loadLibrary(String libName, boolean absolute) {
  if (absolute) {
    System.load(libName);
  } else {
    System.loadLibrary(libName);
  }
}

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

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

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

/**
 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
 * @param libName - The native library path or name
 * @param absolute - Whether the native library will be loaded by path or by name
 */
public static void loadLibrary(String libName, boolean absolute) {
  if (absolute) {
    System.load(libName);
  } else {
    System.loadLibrary(libName);
  }
}

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

/** @return null if the file was extracted and loaded. */
private Throwable loadFile (String sourcePath, String sourceCrc, File extractedFile) {
  try {
    System.load(extractFile(sourcePath, sourceCrc, extractedFile).getAbsolutePath());
    return null;
  } catch (Throwable ex) {
    return ex;
  }
}

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

/**
 * Load a native library of snappy-java
 */
private synchronized static void loadNativeLibrary()
{
  if (!isLoaded) {
    try {
      nativeLibFile = findNativeLibrary();
      if (nativeLibFile != null) {
        // Load extracted or specified snappyjava native library.
        System.load(nativeLibFile.getAbsolutePath());
      } else {
        // Load preinstalled snappyjava (in the path -Djava.library.path)
        System.loadLibrary("snappyjava");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      throw new SnappyError(SnappyErrorCode.FAILED_TO_LOAD_NATIVE_LIBRARY, e.getMessage());
    }
    isLoaded = true;
  }
}

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

private boolean loadLibrary (String sharedLibName) {
  if (sharedLibName == null) return false;
  String path = extractLibrary(sharedLibName);
  if (path != null) System.load(path);
  return path != null;
}

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

static boolean load(final String libName, final StringBuffer message) {
  try {
    if (libName.indexOf(SEPARATOR) != -1) {
      System.load(libName);
    } else {
      System.loadLibrary(libName);
    }
    return true;
  } catch (UnsatisfiedLinkError e) {
    if (message.length() == 0) {
      message.append(DELIMITER);
    }
    message.append('\t');
    message.append(e.getMessage());
    message.append(DELIMITER);
  }
  return false;
}

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

/** @return null if the file was extracted and loaded. */
private Throwable loadFile (String sourcePath, String sourceCrc, File extractedFile) {
  try {
    System.load(extractFile(sourcePath, sourceCrc, extractedFile).getAbsolutePath());
    return null;
  } catch (Throwable ex) {
    return ex;
  }
}

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

private boolean loadLibrary (String sharedLibName) {
  if (sharedLibName == null) return false;
  String path = extractLibrary(sharedLibName);
  if (path != null) System.load(path);
  return path != null;
}

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

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

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

public static void load(String libPath) {
  if (mLoaded.contains(libPath)) {
    return;
  }
  File libFile;
  try {
    libFile = getResourceAsFile(libPath);
  } catch (BrutException ex) {
    throw new UnsatisfiedLinkError(ex.getMessage());
  }
  System.load(libFile.getAbsolutePath());
}

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

private static void loadLib(String path, String name) {
 name = System.mapLibraryName(name); // extends name with .dll, .so or .dylib
 try {
    InputStream in = ACWrapper.class.getResourceAsStream("/"+path + name);
    File fileOut = new File("your lib path");
    OutputStream out = FileUtils.openOutputStream(fileOut);
    IOUtils.copy(in, out);
    in.close();
    out.close();
    System.load(fileOut.toString());//loading goes here
  } catch (Exception e) {
        //handle
  }
}

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

public static void loadJarDll(String name) throws IOException {
  InputStream in = MyClass.class.getResourceAsStream(name);
  byte[] buffer = new byte[1024];
  int read = -1;
  File temp = File.createTempFile(name, "");
  FileOutputStream fos = new FileOutputStream(temp);

  while((read = in.read(buffer)) != -1) {
    fos.write(buffer, 0, read);
  }
  fos.close();
  in.close();

  System.load(temp.getAbsolutePath());
}

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

private static void load(File tmp, String arch) throws IOException {
  InputStream is = SjkWinHelper.class.getClassLoader().getResourceAsStream("sjkwinh.prop");
  Properties prop = new Properties();
  prop.load(is);
  
  String dllName = "sjkwinh" + arch + "." + prop.getProperty("dll" + arch + ".hash") + ".dll";
  int len = Integer.valueOf(prop.getProperty("dll" + arch + ".len"));
  
  File tgt = new File(tmp, dllName);
  if (tgt.isFile() && tgt.length() == len) {
    // dll is present
  }
  else {
    tgt.delete();
    InputStream dllis = SjkWinHelper.class.getClassLoader().getResourceAsStream("sjkwinh" + arch + ".dll");
    byte[] buf = new byte[len];
    int n = dllis.read(buf);
    if (n != buf.length) {
      throw new RuntimeException("Failed extract dll, size mismatch");
    }
    FileOutputStream fos = new FileOutputStream(tgt);
    fos.write(buf);
    fos.close();
  }
  
  System.load(tgt.getPath());
}

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

/** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime
 * exception if all fail. */
private void loadFile (String sourcePath) {
  String sourceCrc = crc(readFile(sourcePath));
  String fileName = new File(sourcePath).getName();
  // Temp directory with username in path.
  File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc,
    fileName);
  Throwable ex = loadFile(sourcePath, sourceCrc, file);
  if (ex == null) return;
  // System provided temp directory.
  try {
    file = File.createTempFile(sourceCrc, null);
    if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return;
  } catch (Throwable ignored) {
  }
  // User home.
  file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName);
  if (loadFile(sourcePath, sourceCrc, file) == null) return;
  // Relative directory.
  file = new File(".temp/" + sourceCrc, fileName);
  if (loadFile(sourcePath, sourceCrc, file) == null) return;
  // Fallback to java.library.path location, eg for applets.
  file = new File(System.getProperty("java.library.path"), sourcePath);
  if (file.exists()) {
    System.load(file.getAbsolutePath());
    return;
  }
  throw new GdxRuntimeException(ex);
}

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

/** Extracts the source file and calls System.load. Attemps to extract and load from multiple locations. Throws runtime
 * exception if all fail. */
private void loadFile (String sourcePath) {
  String sourceCrc = crc(readFile(sourcePath));
  String fileName = new File(sourcePath).getName();
  // Temp directory with username in path.
  File file = new File(System.getProperty("java.io.tmpdir") + "/libgdx" + System.getProperty("user.name") + "/" + sourceCrc,
    fileName);
  Throwable ex = loadFile(sourcePath, sourceCrc, file);
  if (ex == null) return;
  // System provided temp directory.
  try {
    file = File.createTempFile(sourceCrc, null);
    if (file.delete() && loadFile(sourcePath, sourceCrc, file) == null) return;
  } catch (Throwable ignored) {
  }
  // User home.
  file = new File(System.getProperty("user.home") + "/.libgdx/" + sourceCrc, fileName);
  if (loadFile(sourcePath, sourceCrc, file) == null) return;
  // Relative directory.
  file = new File(".temp/" + sourceCrc, fileName);
  if (loadFile(sourcePath, sourceCrc, file) == null) return;
  // Fallback to java.library.path location, eg for applets.
  file = new File(System.getProperty("java.library.path"), sourcePath);
  if (file.exists()) {
    System.load(file.getAbsolutePath());
    return;
  }
  throw new GdxRuntimeException(ex);
}

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

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

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

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

相关文章