public class PipedOutputStream extends OutputStream
PipedInputStream| Constructor and Description |
|---|
PipedOutputStream()
Constructs a new unconnected
PipedOutputStream. |
PipedOutputStream(PipedInputStream target)
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this stream.
|
void |
connect(PipedInputStream stream)
Connects this stream to a
PipedInputStream. |
void |
flush()
Notifies the readers of this
PipedInputStream that bytes can be
read. |
void |
write(byte[] buffer,
int offset,
int count)
Writes
count bytes from the byte array buffer starting at
offset to this stream. |
void |
write(int oneByte)
Writes a single byte to this stream.
|
nullOutputStream, writepublic PipedOutputStream()
PipedOutputStream. The resulting
stream must be connected to a PipedInputStream before data can be
written to it.public PipedOutputStream(PipedInputStream target) throws IOException
PipedOutputStream connected to the
PipedInputStream target. Any data written to this stream
can be read from the target stream.target - the piped input stream to connect to.IOException - if this stream or target are already connected.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOException - if an error occurs while closing this stream.public void connect(PipedInputStream stream) throws IOException
PipedInputStream. Any data written to
this output stream becomes readable in the input stream.stream - the piped input stream to connect to.IOException - if either stream is already connected.public void flush()
throws IOException
PipedInputStream that bytes can be
read. This method does nothing if this stream is not connected.flush in interface Flushableflush in class OutputStreamIOException - if an I/O error occurs while flushing this stream.public void write(byte[] buffer,
int offset,
int count)
throws IOException
count bytes from the byte array buffer starting at
offset to this stream. The written data can then be read from the
connected input stream.
Separate threads should be used to write to a PipedOutputStream
and to read from the connected PipedInputStream. If the same
thread is used, a deadlock may occur.
write in class OutputStreambuffer - the buffer to write.offset - the index of the first byte in buffer to write.count - the number of bytes from buffer to write to this
stream.IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.InterruptedIOException - if the pipe is full and the current thread is interrupted
waiting for space to write data. This case is not currently
handled correctly.IOException - if this stream is not connected, if the target stream is
closed or if the thread reading from the target stream is no
longer alive.public void write(int oneByte)
throws IOException
oneByte is written. The written byte can then be read
from the connected input stream.
Separate threads should be used to write to a PipedOutputStream
and to read from the connected PipedInputStream. If the same
thread is used, a deadlock may occur.
write in class OutputStreamoneByte - the byte to write.InterruptedIOException - if the pipe is full and the current thread is interrupted
waiting for space to write data. This case is not currently
handled correctly.IOException - if this stream is not connected, if the target stream is
closed or if the thread reading from the target stream is no
longer alive. This case is currently not handled correctly.