diff --git a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java index 9bb9c0d45..32ea92538 100644 --- a/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java +++ b/src/main/java/org/apache/commons/crypto/NativeCodeLoader.java @@ -37,6 +37,9 @@ */ final class NativeCodeLoader { + /** The separator to be used in constructing a resource path */ + private static final String RESOURCE_PATH_SEPARATOR = "/"; + private static final String SIMPLE_NAME = NativeCodeLoader.class.getSimpleName(); private static final String NATIVE_LIBNAME = "commons-crypto"; @@ -82,7 +85,7 @@ private static void debug(final String format, final Object... args) { */ private static File extractLibraryFile(final String libFolderForCurrentOS, final String libraryFileName, final String targetFolder) { - final String nativeLibraryFilePath = libFolderForCurrentOS + File.separator + libraryFileName; + final String nativeLibraryFilePath = libFolderForCurrentOS + RESOURCE_PATH_SEPARATOR + libraryFileName; // Attach UUID to the native library file to ensure multiple class loaders // can read the libcommons-crypto multiple times. @@ -171,12 +174,12 @@ private static File findNativeLibrary() { // 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 + File.separator + nativeLibraryName; + 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 + File.separator + altName)) { + if (OsInfo.getOSName().equals("Mac") && hasResource(nativeLibraryPath + RESOURCE_PATH_SEPARATOR + altName)) { // Fix for openjdk7 for Mac nativeLibraryName = altName; hasNativeLib = true; diff --git a/src/main/java/org/apache/commons/crypto/OsInfo.java b/src/main/java/org/apache/commons/crypto/OsInfo.java index a3dc80936..3fcd31901 100644 --- a/src/main/java/org/apache/commons/crypto/OsInfo.java +++ b/src/main/java/org/apache/commons/crypto/OsInfo.java @@ -17,7 +17,6 @@ */ package org.apache.commons.crypto; -import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Locale; @@ -28,6 +27,9 @@ */ final class OsInfo { + /** The separator to be used in constructing a resource path */ + private static final String RESOURCE_PATH_SEPARATOR = "/"; + private final static HashMap archMapping = new HashMap<>(); /** @@ -140,7 +142,7 @@ static String getArchName() { * @return the current OS's native lib folder. */ static String getNativeLibFolderPathForCurrentOS() { - return getOSName() + File.separator + getArchName(); + return getOSName() + RESOURCE_PATH_SEPARATOR + getArchName(); } /**