FileDocCategorySizeDatePackage
P4OutputStream.javaAPI DocApache Ant 1.702616Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.perforce

P4OutputStream

public class P4OutputStream extends OutputStream
heavily inspired from LogOutputStream this stream class calls back the P4Handler on each line of stdout or stderr read

Fields Summary
private P4Handler
handler
private ByteArrayOutputStream
buffer
private boolean
skip
Constructors Summary
public P4OutputStream(P4Handler handler)
creates a new P4OutputStream for a P4Handler

param
handler the handler which will process the streams


                           
       
        this.handler = handler;
    
Methods Summary
public voidclose()
Writes all remaining

throws
IOException if an I/O error occurs.

        if (buffer.size() > 0) {
            processBuffer();
        }
        super.close();
    
protected voidprocessBuffer()
Converts the buffer to a string and sends it to processLine

        handler.process(buffer.toString());
        buffer.reset();
    
public voidwrite(int cc)
Write the data to the buffer and flush the buffer, if a line separator is detected.

param
cc data to log (byte).
throws
IOException IOException if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

        final byte c = (byte) cc;
        if ((c == '\n") || (c == '\r")) {
            if (!skip) {
                processBuffer();
            }
        } else {
            buffer.write(cc);
        }
        skip = (c == '\r");