Package org.apache.commons.crypto
Class NativeCodeLoader
- java.lang.Object
-
- org.apache.commons.crypto.NativeCodeLoader
-
final class NativeCodeLoader extends java.lang.Object
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 Modifier and Type Field Description private static int
EOF
End of file pseudo-character.private static boolean
libraryLoaded
private static java.lang.Throwable
libraryLoadingError
private static java.lang.String
NATIVE_LIBNAME
private static java.lang.String
NATIVE_LIBNAME_ALT
private static java.lang.String
SIMPLE_NAME
-
Constructor Summary
Constructors Modifier Constructor Description private
NativeCodeLoader()
The private constructor ofNativeCodeLoader
.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.io.BufferedInputStream
buffer(java.io.InputStream inputStream)
Returns the given InputStream if it is already aBufferedInputStream
, otherwise creates a BufferedInputStream from the given InputStream.private static boolean
contentsEquals(java.io.InputStream input1, java.io.InputStream input2)
Checks whether in1 and in2 is equal.private static void
debug(java.lang.String format, java.lang.Object... args)
Logs debug messages.private static java.io.File
extractLibraryFile(java.lang.String libFolderForCurrentOS, java.lang.String libraryFileName, java.lang.String targetFolder)
Extracts the specified library file to the target folder.private static java.io.File
findNativeLibrary()
Finds the native library.(package private) static java.lang.Throwable
getLoadingError()
Gets the error cause if loading failed.private static boolean
hasResource(java.lang.String path)
Checks whether the given path has resource.private static boolean
isDebug()
(package private) static boolean
isNativeCodeLoaded()
Checks whether native code is loaded for this platform.(package private) static java.lang.Throwable
loadLibrary()
Loads the library if possible.
-
-
-
Field Detail
-
SIMPLE_NAME
private static final java.lang.String SIMPLE_NAME
-
NATIVE_LIBNAME
private static final java.lang.String NATIVE_LIBNAME
- See Also:
- Constant Field Values
-
NATIVE_LIBNAME_ALT
private static final java.lang.String NATIVE_LIBNAME_ALT
- See Also:
- Constant Field Values
-
EOF
private static final int EOF
End of file pseudo-character.- See Also:
- Constant Field Values
-
libraryLoadingError
private static final java.lang.Throwable libraryLoadingError
-
libraryLoaded
private static final boolean libraryLoaded
-
-
Constructor Detail
-
NativeCodeLoader
private NativeCodeLoader()
The private constructor ofNativeCodeLoader
.
-
-
Method Detail
-
buffer
private static java.io.BufferedInputStream buffer(java.io.InputStream inputStream)
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:
java.lang.NullPointerException
- if the input parameter is null
-
contentsEquals
private static boolean contentsEquals(java.io.InputStream input1, java.io.InputStream input2) throws java.io.IOException
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:
java.io.IOException
- if an I/O error occurs.
-
debug
private static void debug(java.lang.String format, java.lang.Object... args)
Logs debug messages.- Parameters:
format
- SeeString.format(String, Object...)
.args
- SeeString.format(String, Object...)
.
-
extractLibraryFile
private static java.io.File extractLibraryFile(java.lang.String libFolderForCurrentOS, java.lang.String libraryFileName, java.lang.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
private static java.io.File findNativeLibrary()
Finds the native library.- Returns:
- the jar file.
-
getLoadingError
static java.lang.Throwable getLoadingError()
Gets the error cause if loading failed.- Returns:
- null, unless loading failed
-
hasResource
private static boolean hasResource(java.lang.String path)
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
static java.lang.Throwable loadLibrary()
Loads the library if possible.- Returns:
- null if successful, otherwise the Throwable that was caught
-
-