private void processDumpFileContentsRecovery ( InputStream inputStream ) throws IOException { JsonDumpFileProcessor . logger . warn ( "Entering recovery mode to parse rest of file. This might be slightly slower." ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( inputStream ) ) ; String line = br . readLine ( ) ; if ( line == null ) { // can happen if iterator already has consumed all // the stream return ; } if ( line . length ( ) >= 100 ) { line = line . substring ( 0 , 100 ) + "[...]" + line . substring ( line . length ( ) - 50 ) ; } JsonDumpFileProcessor . logger . warn ( "Skipping rest of current line: " + line ) ; line = br . readLine ( ) ; while ( line != null && line . length ( ) > 1 ) { try { EntityDocument document ; if ( line . charAt ( line . length ( ) - 1 ) == ' ' ) { document = documentReader . readValue ( line . substring ( 0 , line . length ( ) - 1 ) ) ; } else { document = documentReader . readValue ( line ) ; } handleDocument ( document ) ; } catch ( JsonProcessingException e ) { logJsonProcessingException ( e ) ; JsonDumpFileProcessor . logger . error ( "Problematic line was: " + line . substring ( 0 , Math . min ( 50 , line . length ( ) ) ) + "..." ) ; } line = br . readLine ( ) ; } }
Process dump file data from the given input stream . The method can recover from an errors that occurred while processing an input stream which is assumed to contain the JSON serialization of a list of JSON entities with each entity serialization in one line . To recover from the previous error the first line is skipped .