Class NativeCodeLoader

java.lang.Object
org.apache.commons.crypto.NativeCodeLoader

final class NativeCodeLoader extends 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 Details

    • SIMPLE_NAME

      private static final String SIMPLE_NAME
    • NATIVE_LIBNAME

      private static final String NATIVE_LIBNAME
      See Also:
    • NATIVE_LIBNAME_ALT

      private static final String NATIVE_LIBNAME_ALT
      See Also:
    • EOF

      private static final int EOF
      End of file pseudo-character.
      See Also:
    • libraryLoadingError

      private static final Throwable libraryLoadingError
    • libraryLoaded

      private static final boolean libraryLoaded
  • Constructor Details

    • NativeCodeLoader

      private NativeCodeLoader()
      The private constructor of NativeCodeLoader.
  • Method Details

    • buffer

      private static BufferedInputStream buffer(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:
      NullPointerException - if the input parameter is null
    • contentsEquals

      private static boolean contentsEquals(InputStream input1, InputStream input2) throws 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:
      IOException - if an I/O error occurs.
    • debug

      private static void debug(String format, Object... args)
      Logs debug messages.
      Parameters:
      format - See String.format(String, Object...).
      args - See String.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

      private static File findNativeLibrary()
      Finds the native library.
      Returns:
      the jar file.
    • getLoadingError

      static Throwable getLoadingError()
      Gets the error cause if loading failed.
      Returns:
      null, unless loading failed
    • hasResource

      private static boolean hasResource(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 Throwable loadLibrary()
      Loads the library if possible.
      Returns:
      null if successful, otherwise the Throwable that was caught