Class JansiLoader


  • public class JansiLoader
    extends java.lang.Object
    Set the system properties, org.jansi.lib.path, org.jansi.lib.name, appropriately so that jansi can find *.dll, *.jnilib and *.so files, according to the current OS (win, linux, mac).

    The library files are automatically extracted from this project's package (JAR).

    usage: call initialize() before using Jansi.

    • Constructor Summary

      Constructors 
      Constructor Description
      JansiLoader()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static void cleanup()
      Deleted old native libraries e.g.
      private static java.lang.String contentsEquals​(java.io.InputStream in1, java.io.InputStream in2)  
      private static void copy​(java.io.InputStream in, java.io.OutputStream out)  
      private static boolean extractAndLoadLibraryFile​(java.lang.String libFolderForCurrentOS, java.lang.String libraryFileName, java.lang.String targetFolder)
      Extracts and loads the specified library file to the target folder
      static int getMajorVersion()  
      static int getMinorVersion()  
      static java.lang.String getNativeLibraryPath()  
      static java.lang.String getNativeLibrarySourceUrl()  
      private static java.io.File getTempDir()  
      static java.lang.String getVersion()  
      private static boolean hasResource​(java.lang.String path)  
      static boolean initialize()
      Loads Jansi native library.
      private static java.lang.String join​(java.util.List<java.lang.String> list, java.lang.String separator)  
      private static void loadJansiNativeLibrary()
      Loads jansi library using given path and name of the library.
      private static boolean loadNativeLibrary​(java.io.File libPath)
      Loads native library using the given path and name of the library.
      private static java.lang.String randomUUID()  
      private static int readNBytes​(java.io.InputStream in, byte[] b)  
      • Methods inherited from class java.lang.Object

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

      • extracted

        private static boolean extracted
      • nativeLibraryPath

        private static java.lang.String nativeLibraryPath
      • nativeLibrarySourceUrl

        private static java.lang.String nativeLibrarySourceUrl
    • Constructor Detail

      • JansiLoader

        public JansiLoader()
    • Method Detail

      • initialize

        public static boolean initialize()
        Loads Jansi native library.
        Returns:
        True if jansi native library is successfully loaded; false otherwise.
      • getNativeLibraryPath

        public static java.lang.String getNativeLibraryPath()
      • getNativeLibrarySourceUrl

        public static java.lang.String getNativeLibrarySourceUrl()
      • getTempDir

        private static java.io.File getTempDir()
      • cleanup

        static void cleanup()
        Deleted old native libraries e.g. on Windows the DLL file is not removed on VM-Exit (bug #80)
      • readNBytes

        private static int readNBytes​(java.io.InputStream in,
                                      byte[] b)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • contentsEquals

        private static java.lang.String contentsEquals​(java.io.InputStream in1,
                                                       java.io.InputStream in2)
                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • extractAndLoadLibraryFile

        private static boolean extractAndLoadLibraryFile​(java.lang.String libFolderForCurrentOS,
                                                         java.lang.String libraryFileName,
                                                         java.lang.String targetFolder)
        Extracts and loads the specified library file to the target folder
        Parameters:
        libFolderForCurrentOS - Library path.
        libraryFileName - Library name.
        targetFolder - Target folder.
        Returns:
      • randomUUID

        private static java.lang.String randomUUID()
      • copy

        private static void copy​(java.io.InputStream in,
                                 java.io.OutputStream out)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • loadNativeLibrary

        private static boolean loadNativeLibrary​(java.io.File libPath)
        Loads native library using the given path and name of the library.
        Parameters:
        libPath - Path of the native library.
        Returns:
        True for successfully loading; false otherwise.
      • loadJansiNativeLibrary

        private static void loadJansiNativeLibrary()
                                            throws java.lang.Exception
        Loads jansi library using given path and name of the library.
        Throws:
        java.lang.Exception
      • hasResource

        private static boolean hasResource​(java.lang.String path)
      • getMajorVersion

        public static int getMajorVersion()
        Returns:
        The major version of the jansi library.
      • getMinorVersion

        public static int getMinorVersion()
        Returns:
        The minor version of the jansi library.
      • getVersion

        public static java.lang.String getVersion()
        Returns:
        The version of the jansi library.
      • join

        private static java.lang.String join​(java.util.List<java.lang.String> list,
                                             java.lang.String separator)