FileDocCategorySizeDatePackage
LeadPipeInputStream.javaAPI DocApache Ant 1.705217Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util

LeadPipeInputStream

public class LeadPipeInputStream extends PipedInputStream
Special PipedInputStream that will not die when the writing Thread is no longer alive.
since
Ant 1.6.2

Fields Summary
private org.apache.tools.ant.ProjectComponent
managingPc
Constructors Summary
public LeadPipeInputStream()
Construct a new LeadPipeInputStream.

        super();
    
public LeadPipeInputStream(int size)
Construct a new LeadPipeInputStream with the specified buffer size.

param
size the size of the circular buffer.

        super();
        setBufferSize(size);
    
public LeadPipeInputStream(PipedOutputStream src)
Construct a new LeadPipeInputStream to pull from the specified PipedOutputStream.

param
src the PipedOutputStream source.
throws
IOException if unable to construct the stream.

        super(src);
    
public LeadPipeInputStream(PipedOutputStream src, int size)
Construct a new LeadPipeInputStream to pull from the specified PipedOutputStream, using a circular buffer of the specified size.

param
src the PipedOutputStream source.
param
size the size of the circular buffer.
throws
IOException if there is an error.

        super(src);
        setBufferSize(size);
    
Methods Summary
public voidlog(java.lang.String message, int loglevel)
Log a message with the specified logging level.

param
message the String message.
param
loglevel the int logging level.

        if (managingPc != null) {
            managingPc.log(message, loglevel);
        } else {
            if (loglevel > Project.MSG_WARN) {
                System.out.println(message);
            } else {
                System.err.println(message);
            }
        }
    
public synchronized intread()
Read a byte from the stream.

return
the byte (0 to 255) or -1 if there are no more.
throws
IOException if there is an error.

        int result = -1;
        try {
            result = super.read();
        } catch (IOException eyeOhEx) {
            if ("write end dead".equalsIgnoreCase(eyeOhEx.getMessage())) {
                if (super.in > 0 && super.out < super.buffer.length
                    && super.out > super.in) {
                    result = super.buffer[super.out++] & 0xFF;
                }
            } else {
                log("error at LeadPipeInputStream.read():  "
                    + eyeOhEx.getMessage(), Project.MSG_INFO);
            }
        }
        return result;
    
public synchronized voidsetBufferSize(int size)
Set the size of the buffer.

param
size the new buffer size. Ignored if <= current size.

        if (size > buffer.length) {
            byte[] newBuffer = new byte[size];
            if (in >= 0) {
                if (in > out) {
                    System.arraycopy(buffer, out, newBuffer, out, in - out);
                } else {
                    int outlen = buffer.length - out;
                    System.arraycopy(buffer, out, newBuffer, 0, outlen);
                    System.arraycopy(buffer, 0, newBuffer, outlen, in);
                    in += outlen;
                    out = 0;
                }
            }
            buffer = newBuffer;
        }
    
public voidsetManagingComponent(org.apache.tools.ant.ProjectComponent pc)
Set a managing ProjectComponent for this LeadPipeInputStream.

param
pc the managing ProjectComponent.

        this.managingPc = pc;
    
public voidsetManagingTask(org.apache.tools.ant.Task task)
Set a managing Task for this LeadPipeInputStream.

param
task the managing Task.

        setManagingComponent(task);