1 package hudson.model; 2 3 import hudson.CloseProofOutputStream; 4 import hudson.remoting.RemoteOutputStream; 5 6 import java.io.IOException ; 7 import java.io.ObjectInputStream ; 8 import java.io.ObjectOutputStream ; 9 import java.io.OutputStream ; 10 import java.io.PrintStream ; 11 import java.io.PrintWriter ; 12 import java.io.Serializable ; 13 14 21 public class StreamBuildListener implements BuildListener, Serializable { 22 private PrintWriter w; 23 24 private PrintStream ps; 25 26 public StreamBuildListener(OutputStream w) { 27 this(new PrintStream (w)); 28 } 29 30 public StreamBuildListener(PrintStream w) { 31 this.ps = w; 32 this.w = new PrintWriter (w,true); 35 } 36 37 public void started() { 38 w.println("started"); 39 } 40 41 public PrintStream getLogger() { 42 return ps; 43 } 44 45 public PrintWriter error(String msg) { 46 w.println("ERROR: "+msg); 47 return w; 48 } 49 50 public PrintWriter fatalError(String 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 out) throws IOException { 61 out.writeObject(new RemoteOutputStream(new CloseProofOutputStream(ps))); 62 } 63 64 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException { 65 ps = new PrintStream ((OutputStream)in.readObject(),true); 66 w = new PrintWriter (ps,true); 67 } 68 69 private static final long serialVersionUID = 1L; 70 } 71 | Popular Tags |