public void interceptStream(int index, OutputStream stream)
            throws GuacamoleException {

        // Log beginning of intercepted stream
        logger.debug("Intercepting output stream #{} of tunnel \"{}\".",
                index, getUUID());

        try {
            outputStreamFilter.interceptStream(index, new BufferedOutputStream(stream));
        }

        // Log end of intercepted stream
        finally {
            logger.debug("Intercepted output stream #{} of tunnel \"{}\" ended.",
                    index, getUUID());
        }

    }
Intercept all data received along the stream having the given index,
writing that data to the given OutputStream. The OutputStream will
automatically be closed when the stream ends. If there is no such
stream, then the OutputStream will be closed immediately. This function
will block until all received data has been written to the OutputStream
and the OutputStream has been closed.

@param index
    The index of the stream to intercept.

@param stream
    The OutputStream to write all intercepted data to.

@throws GuacamoleException
    If an error occurs while intercepting the stream, or if the stream
    itself reports an error.
guacamole/src/main/java/org/apache/guacamole/tunnel/StreamInterceptingTunnel.java