Class 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.
    • 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 a BufferedInputStream, 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • SIMPLE_NAME

        private static final java.lang.String SIMPLE_NAME
      • NATIVE_LIBNAME_ALT

        private static final java.lang.String NATIVE_LIBNAME_ALT
        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 of NativeCodeLoader.
    • Method Detail

      • buffer

        private static java.io.BufferedInputStream buffer​(java.io.InputStream inputStream)
        Returns the given InputStream if it is already a BufferedInputStream, 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 - See String.format(String, Object...).
        args - See String.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, else false.
      • loadLibrary

        static java.lang.Throwable loadLibrary()
        Loads the library if possible.
        Returns:
        null if successful, otherwise the Throwable that was caught