Class Hunspell


  • public class Hunspell
    extends java.lang.Object
    The simple hunspell library frontend which takes care of creating and singleton'ing the library instance (no need to load it more than once per process). The Hunspell java bindings are licensed under the same terms as Hunspell itself (GPL/LGPL/MPL tri-license), see the file COPYING.txt in the root of the distribution for the exact terms.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  Hunspell.Dictionary
      Class representing a single dictionary.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private HunspellLibrary hsl
      The native library instance, created by JNA.
      private static Hunspell hunspell
      The Singleton instance of Hunspell
      private java.lang.String libFile
      The library file that was loaded.
      private java.util.HashMap<java.lang.String,​Hunspell.Dictionary> map
      This is the cache where we keep the already loaded dictionaries around
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Hunspell​(java.lang.String libDir)
      Constructor for the library, loads the native lib.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroyDictionary​(java.lang.String baseFileName)
      Removes a dictionary from the internal cache
      private static java.nio.CharBuffer ensureCapacity​(java.nio.CharBuffer buffer, int capacity)  
      Hunspell.Dictionary getDictionary​(java.lang.String baseFileName)
      Gets an instance of the dictionary.
      static Hunspell getInstance()
      The instance of the HunspellManager, looks for the native lib in the default directories
      static Hunspell getInstance​(java.lang.String libDir)
      The instance of the HunspellManager, looks for the native lib in the directory specified.
      java.lang.String getLibFile()  
      static java.lang.String libName()
      Calculate the filename of the native hunspell lib.
      static java.lang.String libNameBare()  
      protected void tryLoad​(java.lang.String libFile)  
      • Methods inherited from class java.lang.Object

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

      • hunspell

        private static Hunspell hunspell
        The Singleton instance of Hunspell
      • hsl

        private HunspellLibrary hsl
        The native library instance, created by JNA.
      • libFile

        private java.lang.String libFile
        The library file that was loaded.
      • map

        private java.util.HashMap<java.lang.String,​Hunspell.Dictionary> map
        This is the cache where we keep the already loaded dictionaries around
    • Constructor Detail

      • Hunspell

        protected Hunspell​(java.lang.String libDir)
                    throws java.lang.UnsatisfiedLinkError,
                           java.lang.UnsupportedOperationException
        Constructor for the library, loads the native lib. Loading is done in the first of the following three ways that works: 1) Unmodified load in the provided directory. 2) libFile stripped back to the base name (^lib(.*)\.so on unix) 3) The library is searched for in the classpath, extracted to disk and loaded.
        Parameters:
        libDir - Optional absolute directory where the native lib can be found.
        Throws:
        java.lang.UnsupportedOperationException - if the OS or architecture is simply not supported.
        java.lang.UnsatisfiedLinkError
    • Method Detail

      • getInstance

        public static Hunspell getInstance()
                                    throws java.lang.UnsatisfiedLinkError,
                                           java.lang.UnsupportedOperationException
        The instance of the HunspellManager, looks for the native lib in the default directories
        Throws:
        java.lang.UnsatisfiedLinkError
        java.lang.UnsupportedOperationException
      • getInstance

        public static Hunspell getInstance​(java.lang.String libDir)
                                    throws java.lang.UnsatisfiedLinkError,
                                           java.lang.UnsupportedOperationException
        The instance of the HunspellManager, looks for the native lib in the directory specified.
        Parameters:
        libDir - Optional absolute directory where the native lib can be found.
        Throws:
        java.lang.UnsatisfiedLinkError
        java.lang.UnsupportedOperationException
      • tryLoad

        protected void tryLoad​(java.lang.String libFile)
                        throws java.lang.UnsupportedOperationException
        Throws:
        java.lang.UnsupportedOperationException
      • getLibFile

        public java.lang.String getLibFile()
      • libName

        public static java.lang.String libName()
                                        throws java.lang.UnsupportedOperationException
        Calculate the filename of the native hunspell lib. The files have completely different names to allow them to live in the same directory and avoid confusion.
        Throws:
        java.lang.UnsupportedOperationException
      • libNameBare

        public static java.lang.String libNameBare()
                                            throws java.lang.UnsupportedOperationException
        Throws:
        java.lang.UnsupportedOperationException
      • ensureCapacity

        private static java.nio.CharBuffer ensureCapacity​(java.nio.CharBuffer buffer,
                                                          int capacity)
      • getDictionary

        public Hunspell.Dictionary getDictionary​(java.lang.String baseFileName)
                                          throws java.io.IOException
        Gets an instance of the dictionary.
        Parameters:
        baseFileName - the base name of the dictionary, passing /dict/da_DK means that the files /dict/da_DK.dic and /dict/da_DK.aff get loaded
        Throws:
        java.io.IOException
      • destroyDictionary

        public void destroyDictionary​(java.lang.String baseFileName)
        Removes a dictionary from the internal cache
        Parameters:
        baseFileName - the base name of the dictionary, as passed to getDictionary()