1 18 19 package org.apache.tools.ant.taskdefs.optional.perforce; 20 21 import java.io.ByteArrayInputStream ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 26 import org.apache.tools.ant.BuildException; 27 import org.apache.tools.ant.taskdefs.PumpStreamHandler; 28 32 public abstract class P4HandlerAdapter implements P4Handler { 33 String p4input = ""; 35 private PumpStreamHandler myHandler = null; 36 41 public void setOutput(String p4Input) { 42 this.p4input = p4Input; 43 } 44 49 public abstract void process(String line); 50 51 57 public void start() throws BuildException { 58 if (p4input != null && p4input.length() > 0) { 59 myHandler = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this), 60 new ByteArrayInputStream (p4input.getBytes())); 61 } else { 62 myHandler = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this)); 63 } 64 myHandler.setProcessInputStream(os); 65 myHandler.setProcessErrorStream(es); 66 myHandler.setProcessOutputStream(is); 67 myHandler.start(); 68 } 69 70 75 public void stop() { 76 myHandler.stop(); 77 } 78 79 OutputStream os; InputStream is; InputStream es; 85 92 public void setProcessInputStream(OutputStream os) throws IOException { 93 this.os = os; 94 } 95 96 101 public void setProcessErrorStream(InputStream is) throws IOException { 102 this.es = is; 103 } 104 105 110 public void setProcessOutputStream(InputStream is) throws IOException { 111 this.is = is; 112 } 113 } 114 | Popular Tags |