com.mindbright.util
public final class InputStreamPipe extends java.io.InputStream
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.
OutputStreamPipe
,
PipedInputStream
,
PipedOutputStream
Constructor and Description |
---|
InputStreamPipe()
Create an unconnected InputStreamPipe with the default circular
buffer size (8192 bytes).
|
InputStreamPipe(int bufferSize)
Create an unconnected InputStreamPipe with the given circular
buffer size.
|
InputStreamPipe(OutputStreamPipe source)
Create an InputStreamPipe with the default circular
buffer size (8192 bytes) which is connected to the given output
stream.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of bytes that can be read without blocking.
|
void |
close()
Close this stream and abort any ongoing write operation in the
corresponding OutputStreamPipe.
|
void |
connect(OutputStreamPipe source)
Causes this InputStreamPipe to be connected to the given
OutputStreamPipe.
|
protected void |
eof()
Signal that this stream is closing.
|
void |
flush()
Notify all instances waiting on this stream.
|
protected void |
put(byte[] buf,
int off,
int len)
Put data into this input stream pipe.
|
protected void |
put(int b)
Put a byte of data into this input stream pipe.
|
int |
read()
Read a byte of data from the pipe.
|
int |
read(byte[] buf,
int off,
int len)
Read data from the pipe.
|
public InputStreamPipe(int bufferSize)
bufferSize
- size of circular bufferpublic InputStreamPipe()
public InputStreamPipe(OutputStreamPipe source) throws java.io.IOException
source
- the output stream to connect tojava.io.IOException
public void connect(OutputStreamPipe source) throws java.io.IOException
source
- the stream to connect tojava.io.IOException
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] buf, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
buf
- buffer to store read data intooff
- where in the buffer the first byte should be storedlen
- how many bytes of data to readjava.io.IOException
public int available()
available
in class java.io.InputStream
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.InputStream
java.io.IOException
public void flush()
protected void put(int b) throws java.io.IOException
b
- the byte of data to putjava.io.IOException
protected void put(byte[] buf, int off, int len) throws java.io.IOException
buf
- array holding data to putoff
- offset of first byte to putlen
- number of bytes to putjava.io.IOException
protected void eof()