question: private boolean matchAndwriteOneAuditLog ( BufferedWriter writer , AuditLog auditlog , String keyword ) throws MarshallingExcetion { try { AuditLogUtils . resetDesc ( auditlog , resb ) ; if ( AuditLogUtils . isKeywordContained ( auditlog , keyword ) ) { if ( _count . getAndIncrement ( ) > 0 ) { while ( ! _firstWritten . get ( ) ) { try { Thread . sleep ( 1 ) ; } catch ( InterruptedException e ) { _logger . warn ( "Sleep interrupted" ) ; } } writer . write ( "," + _mapper . writeValueAsString ( auditlog ) ) ; } else { writer . write ( _mapper . writeValueAsString ( auditlog ) ) ; _firstWritten . set ( true ) ; } return true ; } _logger . debug ( "{} filter out by description keyword {}" , auditlog . getDescription ( ) , keyword ) ; return false ; } catch ( JsonGenerationException e ) { throw new MarshallingExcetion ( "JSON Generation Error" , e ) ; } catch ( JsonMappingException e ) { throw new MarshallingExcetion ( "JSON Mapping Error" , e ) ; } catch ( IOException e ) { throw new MarshallingExcetion ( "JSON streaming failed: " , e ) ; } }
target:  Match if auditlog description contains expected keyword ,Stream out the auditlog if matched,Otherwise ignore this one piece of auditlog. Since the streaming format for the first auditlog is slightly different from all the rest of auditlogs, this method uses a boolean to block auditlog being streamed until the first auditlog is streamed by a thread.