Package org.apache.commons.crypto
Class NativeCodeLoader
java.lang.Object
org.apache.commons.crypto.NativeCodeLoader
A helper to load the native code i.e. libcommons-crypto.so. This handles the
fallback to either the bundled libcommons-crypto-Linux-i386-32.so or the
default java implementations where appropriate.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static BufferedInputStream
buffer
(InputStream inputStream) Returns the given InputStream if it is already aBufferedInputStream
, otherwise creates a BufferedInputStream from the given InputStream.private static boolean
contentsEquals
(InputStream input1, InputStream input2) Checks whether in1 and in2 is equal.private static void
Logs debug messages.private static File
extractLibraryFile
(String libFolderForCurrentOS, String libraryFileName, String targetFolder) Extracts the specified library file to the target folder.private static File
Finds the native library.(package private) static Throwable
Gets the error cause if loading failed.private static boolean
hasResource
(String path) Checks whether the given path has resource.private static boolean
isDebug()
(package private) static boolean
Checks whether native code is loaded for this platform.(package private) static Throwable
Loads the library if possible.
-
Field Details
-
SIMPLE_NAME
-
NATIVE_LIBNAME
- See Also:
-
NATIVE_LIBNAME_ALT
- See Also:
-
EOF
private static final int EOFEnd of file pseudo-character.- See Also:
-
libraryLoadingError
-
libraryLoaded
private static final boolean libraryLoaded
-
-
Constructor Details
-
NativeCodeLoader
private NativeCodeLoader()The private constructor ofNativeCodeLoader
.
-
-
Method Details
-
buffer
Returns the given InputStream if it is already aBufferedInputStream
, otherwise creates a BufferedInputStream from the given InputStream.Copied from Apache Commons IO 2.5.
- Parameters:
inputStream
- the InputStream to wrap or return (not null)- Returns:
- the given InputStream or a new
BufferedInputStream
for the given InputStream - Throws:
NullPointerException
- if the input parameter is null
-
contentsEquals
Checks whether in1 and in2 is equal.Copied from Apache Commons IO 2.5.
- Parameters:
input1
- the input1.input2
- the input2.- Returns:
- true if in1 and in2 is equal, else false.
- Throws:
IOException
- if an I/O error occurs.
-
debug
Logs debug messages.- Parameters:
format
- SeeString.format(String, Object...)
.args
- SeeString.format(String, Object...)
.
-
extractLibraryFile
private static File extractLibraryFile(String libFolderForCurrentOS, String libraryFileName, String targetFolder) Extracts the specified library file to the target folder.- Parameters:
libFolderForCurrentOS
- the library in commons-crypto.lib.path.libraryFileName
- the library name.targetFolder
- Target folder for the native lib. Use the value of commons-crypto.tempdir or java.io.tmpdir.- Returns:
- the library file.
-
findNativeLibrary
Finds the native library.- Returns:
- the jar file.
-
getLoadingError
Gets the error cause if loading failed.- Returns:
- null, unless loading failed
-
hasResource
Checks whether the given path has resource.- Parameters:
path
- the path.- Returns:
- the boolean.
-
isDebug
private static boolean isDebug() -
isNativeCodeLoaded
static boolean isNativeCodeLoaded()Checks whether native code is loaded for this platform.- Returns:
true
if native is loaded, elsefalse
.
-
loadLibrary
Loads the library if possible.- Returns:
- null if successful, otherwise the Throwable that was caught
-