in src/main/java/org/apache/commons/crypto/NativeCodeLoader.java [153:199]
private static File findNativeLibrary() {
// Get the properties once
final Properties props = Utils.getDefaultProperties();
// Try to load the library in commons-crypto.lib.path */
String nativeLibraryPath = props.getProperty(Crypto.LIB_PATH_KEY);
String nativeLibraryName = props.getProperty(Crypto.LIB_NAME_KEY, System.mapLibraryName(NATIVE_LIBNAME));
debug("%s nativeLibraryPath %s = %s", SIMPLE_NAME, Crypto.LIB_PATH_KEY, nativeLibraryPath);
debug("%s nativeLibraryName %s = %s", SIMPLE_NAME, Crypto.LIB_NAME_KEY, nativeLibraryName);
if (nativeLibraryPath != null) {
final File nativeLib = new File(nativeLibraryPath, nativeLibraryName);
final boolean exists = nativeLib.exists();
debug("%s nativeLib %s exists = %s", SIMPLE_NAME, nativeLib, exists);
if (exists) {
return nativeLib;
}
}
// Load an OS-dependent native library inside a jar file
nativeLibraryPath = "/org/apache/commons/crypto/native/" + OsInfo.getNativeLibFolderPathForCurrentOS();
debug("%s nativeLibraryPath = %s", SIMPLE_NAME, nativeLibraryPath);
final String resource = nativeLibraryPath + RESOURCE_PATH_SEPARATOR + nativeLibraryName;
boolean hasNativeLib = hasResource(resource);
debug("%s resource %s exists = %s", SIMPLE_NAME, resource, hasNativeLib);
if (!hasNativeLib) {
final String altName = NATIVE_LIBNAME_ALT;
if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + RESOURCE_PATH_SEPARATOR + altName)) {
// Fix for openjdk7 for Mac
nativeLibraryName = altName;
hasNativeLib = true;
}
}
if (!hasNativeLib) {
final String errorMessage = String.format("No native library is found for os.name=%s and os.arch=%s", OsInfo.getOSName(), OsInfo.getArchName());
throw new IllegalStateException(errorMessage);
}
// Temporary folder for the native lib. Use the value of
// Crypto.LIB_TEMPDIR_KEY or java.io.tmpdir
final String tempFolder = new File(props.getProperty(Crypto.LIB_TEMPDIR_KEY, System.getProperty("java.io.tmpdir"))).getAbsolutePath();
// Extract and load a native library inside the jar file
return extractLibraryFile(nativeLibraryPath, nativeLibraryName, tempFolder);
}