KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > util > StreamTaskListener


1 package hudson.util;
2
3 import hudson.model.TaskListener;
4 import hudson.remoting.RemoteOutputStream;
5 import hudson.CloseProofOutputStream;
6
7 import java.io.OutputStream JavaDoc;
8 import java.io.OutputStreamWriter JavaDoc;
9 import java.io.PrintStream JavaDoc;
10 import java.io.PrintWriter JavaDoc;
11 import java.io.Writer JavaDoc;
12 import java.io.Serializable JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.ObjectOutputStream JavaDoc;
15 import java.io.ObjectInputStream JavaDoc;
16
17 /**
18  * {@link TaskListener} that generates output into a single stream.
19  *
20  * <p>
21  * This object is remotable.
22  *
23  * @author Kohsuke Kawaguchi
24  */

25 public final class StreamTaskListener implements TaskListener, Serializable JavaDoc {
26     private PrintStream JavaDoc out;
27
28     public StreamTaskListener(PrintStream JavaDoc out) {
29         this.out = out;
30     }
31
32     public StreamTaskListener(OutputStream out) {
33         this(new PrintStream JavaDoc(out));
34     }
35
36     public StreamTaskListener(Writer JavaDoc w) {
37         this(new WriterOutputStream(w));
38     }
39
40     public PrintStream JavaDoc getLogger() {
41         return out;
42     }
43
44     public PrintWriter JavaDoc error(String JavaDoc msg) {
45         out.println(msg);
46         return new PrintWriter JavaDoc(new OutputStreamWriter JavaDoc(out),true);
47     }
48
49     public PrintWriter JavaDoc fatalError(String JavaDoc msg) {
50         return error(msg);
51     }
52
53     private void writeObject(ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
54         out.writeObject(new RemoteOutputStream(new CloseProofOutputStream(this.out)));
55     }
56
57     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
58         out = (PrintStream JavaDoc) in.readObject();
59     }
60
61     private static final long serialVersionUID = 1L;
62 }
63
Popular Tags