View Javadoc

1   package zeus.actors.outtrays;
2   
3   import java.net.*;
4   import java.io.*;
5   import java.util.Date;
6   
7   public class ReplyListener implements Runnable {
8       
9       BufferedInputStream is;
10      PrintWriter os;
11      File file;
12      
13      public ReplyListener(BufferedInputStream is, PrintWriter os, File file) {
14          this.os = os;
15          this.is = is;
16          this.file = file;
17      }
18      
19      
20      public void run() {
21          BufferedReader r=new BufferedReader(new InputStreamReader(is));
22          
23          // now reading response
24          
25          String ln;
26          Date today = new Date();
27          int month = today.getMonth() + 1;
28          int year = today.getYear();
29          
30          try {
31              String all = new String("Response received " + + today.getDate() +"/" + String.valueOf(month) +"/" + String.valueOf(year) + " at " + today.getHours() +":" +today.getMinutes() +":" + today.getSeconds()+"\n");
32              while( (ln=r.readLine()) != null ) {
33                  debug(ln);
34                  all+=ln;}
35              FileWriter log = new FileWriter(file,true);
36              log.write(all);
37              log.write("\n\n");
38              log.close();
39              os.close();
40              is.close();
41          } catch (Exception e ) {
42              e.printStackTrace();
43          }
44      }
45      
46      
47      private void debug(String str) {
48          //  System.out.println("reply:" + str);
49          
50      }
51  }