1 18 19 package org.apache.tools.ant.taskdefs.optional.perforce; 20 21 import java.io.OutputStream ; 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 25 29 public class P4OutputStream extends OutputStream { 30 private P4Handler handler; 31 private ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 32 private boolean skip = false; 33 34 38 public P4OutputStream(P4Handler handler) { 39 this.handler = handler; 40 } 41 42 51 public void write(int cc) throws IOException { 52 final byte c = (byte) cc; 53 if ((c == '\n') || (c == '\r')) { 54 if (!skip) { 55 processBuffer(); 56 } 57 } else { 58 buffer.write(cc); 59 } 60 skip = (c == '\r'); 61 } 62 63 64 67 protected void processBuffer() { 68 handler.process(buffer.toString()); 69 buffer.reset(); 70 } 71 72 76 public void close() throws IOException { 77 if (buffer.size() > 0) { 78 processBuffer(); 79 } 80 super.close(); 81 } 82 83 } 84 85 86 | Popular Tags |