FileDocCategorySizeDatePackage
OutputStreamFunneler.javaAPI DocApache Ant 1.705352Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.util

OutputStreamFunneler

public class OutputStreamFunneler extends Object
Manages a set of OutputStreams to write to a single underlying stream, which is closed only when the last "funnel" has been closed.

Fields Summary
public static final long
DEFAULT_TIMEOUT_MILLIS
Default timeout.
private OutputStream
out
private int
count
private boolean
closed
private long
timeoutMillis
Constructors Summary
public OutputStreamFunneler(OutputStream out)
Create a new OutputStreamFunneler for the specified OutputStream.

param
out OutputStream.


                      
       
        this(out, DEFAULT_TIMEOUT_MILLIS);
    
public OutputStreamFunneler(OutputStream out, long timeoutMillis)
Create a new OutputStreamFunneler for the specified OutputStream, with the specified timeout value.

param
out OutputStream.
param
timeoutMillis long.
see
#setTimeout(long)

        if (out == null) {
            throw new IllegalArgumentException(
                "OutputStreamFunneler.<init>:  out == null");
        }
        this.out = out;
        this.closed = false; //as far as we know
        setTimeout(timeoutMillis);
    
Methods Summary
private synchronized voidclose()

        try {
            dieIfClosed();
            out.close();
        } finally {
            closed = true;
        }
    
private synchronized voiddieIfClosed()

        if (closed) {
            throw new IOException("The funneled OutputStream has been closed.");
        }
    
public synchronized java.io.OutputStreamgetFunnelInstance()
Get a "funnel" OutputStream instance to write to this OutputStreamFunneler's underlying OutputStream.

return
OutputStream.
throws
IOException if unable to create the funnel.

        dieIfClosed();
        try {
            return new Funnel();
        } finally {
            notifyAll();
        }
    
private synchronized voidrelease(org.apache.tools.ant.util.OutputStreamFunneler$Funnel funnel)

        //ignore release of an already-closed funnel
        if (!funnel.closed) {
            try {
                if (timeoutMillis > 0) {
                    try {
                        wait(timeoutMillis);
                    } catch (InterruptedException eyeEx) {
                        //ignore
                    }
                }
                if (--count == 0) {
                    close();
                }
            } finally {
                funnel.closed = true;
            }
        }
   
public synchronized voidsetTimeout(long timeoutMillis)
Set the timeout for this OutputStreamFunneler. This is the maximum time that may elapse between the closure of the last "funnel" and the next call to getOutputStream() without closing the underlying stream.

param
timeoutMillis long timeout value.

        this.timeoutMillis = timeoutMillis;