private static Charset getCharset ( File dictionaryFile ) throws UnsupportedCharsetException , FileNotFoundException { Charset cs = charsets . get ( dictionaryFile ) ; if ( cs == null ) { BufferedReader reader = null ; try { reader = new BufferedReader ( new FileReader ( dictionaryFile ) ) ; String charsetName = reader . readLine ( ) ; charsetName = charsetName . replaceAll ( "\\s+" , "" ) ; cs = Charset . forName ( charsetName ) ; charsets . put ( dictionaryFile , cs ) ; } catch ( IOException e ) { throw new RuntimeException ( "Could not read first line of file" ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } } return cs ; }
Reads the first line of the dictionary file which is the encoding