Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.mindbright.util
Class OutputStreamPipe

    java.lang.Object
      java.io.OutputStream
          com.mindbright.util.OutputStreamPipe

public final class OutputStreamPipe
extends java.io.OutputStream

An output stream pipe should be connected to an input stream pipe; the input stream pipe then provides whatever data bytes are written to the output stream pipe. This is very close to the `PipedInputStream` and `PipedOutputStream`. The main difference is that there is a timeout in the write code so that any waiting write will be aborted if the pipe is closed.

The input and output pipes are connected via a circular buffer which decouples write and read operations.

See Also:
  `InputStreamPipe`, `PipedInputStream`, `PipedOutputStream`

Constructor Summary
`OutputStreamPipe()` Create an OutputStreamPipe which is not connected to any InputStreamPipe.
`OutputStreamPipe(InputStreamPipe sink)` Create an OutputStreamPipe which is connected to the given InputStreamPipe.

Method Summary
`void` | `close()` Close this output stream pipe.
`void` | `connect(InputStreamPipe sink)` Connect this pipe to an InputStreamPipe
`void` | `flush()` Notify all instances waiting on this stream.
`void` | `write(byte[] buf, int off, int len)` Put data into this output stream pipe.
`void` | `write(int b)` Writes a byte of data into this output stream pipe.

Methods inherited from class java.io.OutputStream
`write`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### OutputStreamPipe

    public OutputStreamPipe(InputStreamPipe sink)
                     throws java.io.IOException

  Create an OutputStreamPipe which is connected to the given InputStreamPipe.

Parameters:
  `sink` - pipe to connect to

### OutputStreamPipe

    public OutputStreamPipe()

  Create an OutputStreamPipe which is not connected to any InputStreamPipe.

Method Detail

### connect

    public void connect(InputStreamPipe sink)
                 throws java.io.IOException

  Connect this pipe to an InputStreamPipe

  Parameters:
    `sink` - pipe to connect to
  Throws:
    `java.io.IOException`

### write

    public void write(int b)
               throws java.io.IOException

  Writes a byte of data into this output stream pipe. If the buffer is full then this call will wait until room becomes available or the stream is closed.

  Parameters:
    `b` - the byte of data to write
  Throws:
    `java.io.IOException`

### write

    public void write(byte[] buf,
                      int off,
                      int len)
               throws java.io.IOException

  Put data into this output stream pipe. If the buffer is full then this call will wait until room becomes available or the stream is closed. The function handles the case where the amount of data to write is larger than the circular buffer.

  Parameters:
    `buf` - array holding data to put
    `off` - offset of first byte to put
    `len` - number of bytes to put
  Throws:
    `java.io.IOException`

### flush

    public void flush()

  Notify all instances waiting on this stream.

### close

    public void close()
               throws java.io.IOException

  Close this output stream pipe.

  Throws:
    `java.io.IOException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD