private static void readAndAddDocumentsFromStream ( final SolrClient client , final String lang , final InputStream is , final List < SolrInputDocument > documents , final boolean closeStream ) { final BufferedReader br = new BufferedReader ( new InputStreamReader ( is ) ) ; try { String line = br . readLine ( ) ; while ( null != line ) { final SolrInputDocument document = new SolrInputDocument ( ) ; // Each field is named after the schema "entry_xx" where xx denotes // the two digit language code. See the file spellcheck/conf/schema.xml. document . addField ( "entry_" + lang , line ) ; documents . add ( document ) ; // Prevent OutOfMemoryExceptions ... if ( documents . size ( ) >= MAX_LIST_SIZE ) { addDocuments ( client , documents , false ) ; documents . clear ( ) ; } line = br . readLine ( ) ; } } catch ( IOException e ) { LOG . error ( "Could not read spellcheck dictionary from input stream." ) ; } catch ( SolrServerException e ) { LOG . error ( "Error while adding documents to Solr server. " ) ; } finally { try { if ( closeStream ) { br . close ( ) ; } } catch ( Exception e ) { // Nothing to do here anymore .... } } }
Parses the dictionary from an InputStream .