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