public static void publishDataToFile ( String fileName , int numMessages , int delayInMillis ) throws IOException { PrintWriter out = new PrintWriter ( new OutputStreamWriter ( new BufferedOutputStream ( new FileOutputStream ( fileName , true ) ) , "UTF-8" ) ) ; try { for ( int i = 0 ; i < Math . max ( 1 , numMessages ) ; i ++ ) { Long currTime = System . currentTimeMillis ( ) ; String message = generateEvent ( currTime , delayInMillis ) ; out . println ( message ) ; } } catch ( Exception e ) { System . err . print ( "Error in writing generated events to file" ) ; e . printStackTrace ( ) ; } finally { out . flush ( ) ; out . close ( ) ; } }
Publish generated events to a file .