KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > model > StreamBuildListener


1 package hudson.model;
2
3 import hudson.CloseProofOutputStream;
4 import hudson.remoting.RemoteOutputStream;
5
6 import java.io.IOException JavaDoc;
7 import java.io.ObjectInputStream JavaDoc;
8 import java.io.ObjectOutputStream JavaDoc;
9 import java.io.OutputStream JavaDoc;
10 import java.io.PrintStream JavaDoc;
11 import java.io.PrintWriter JavaDoc;
12 import java.io.Serializable JavaDoc;
13
14 /**
15  * {@link BuildListener} that writes to an {@link OutputStream}.
16  *
17  * This class is remotable.
18  *
19  * @author Kohsuke Kawaguchi
20  */

21 public class StreamBuildListener implements BuildListener, Serializable JavaDoc {
22     private PrintWriter JavaDoc w;
23
24     private PrintStream JavaDoc ps;
25
26     public StreamBuildListener(OutputStream w) {
27         this(new PrintStream JavaDoc(w));
28     }
29
30     public StreamBuildListener(PrintStream JavaDoc w) {
31         this.ps = w;
32         // unless we auto-flash, PrintStream will use BufferedOutputStream internally,
33
// and break ordering
34
this.w = new PrintWriter JavaDoc(w,true);
35     }
36
37     public void started() {
38         w.println("started");
39     }
40
41     public PrintStream JavaDoc getLogger() {
42         return ps;
43     }
44
45     public PrintWriter JavaDoc error(String JavaDoc msg) {
46         w.println("ERROR: "+msg);
47         return w;
48     }
49
50     public PrintWriter JavaDoc fatalError(String JavaDoc msg) {
51         w.println("FATAL: "+msg);
52         return w;
53     }
54
55     public void finished(Result result) {
56         w.println("finished: "+result);
57     }
58
59
60     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
61         out.writeObject(new RemoteOutputStream(new CloseProofOutputStream(ps)));
62     }
63
64     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
65         ps = new PrintStream JavaDoc((OutputStream)in.readObject(),true);
66         w = new PrintWriter JavaDoc(ps,true);
67     }
68
69     private static final long serialVersionUID = 1L;
70 }
71
Popular Tags