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) {
    e.printStackTrace();
  }
 finally {
    if (out != null) {
      out.flush();
      out.close();
    }
  }
}

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 ) { e . printStackTrace ( ) ; } finally { if ( out != null ) { out . flush ( ) ; out . close ( ) ; } } }
publish generated events to a file .
