|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--java.io.InputStream
|
+--one.util.RubberPipedInputStream
RubberPipedInputStream and RubberPipedOutputStream allow data
to be piped between two or more threads, similar to PipedInputStream and PipedOutputStream.
However, RubberPipedInputStream grows its
internal buffer rather than blocking when the buffer is full. It also
supports mark(int) and reset().
A RubberPipedInputStream is useful when data must be written to a
stream in response to one event and read from a stream in response to
another event, for instance, when reassembling the contents of Chunks into a byte stream.
RubberPipedOutputStream| Field Summary | |
protected byte[] |
buffer
The circular buffer into which incoming data is placed. |
protected boolean |
closed
Is this rubber piped input stream closed? |
protected boolean |
connected
Is this rubber piped input stream connected? |
protected int |
in
The index of the position in the circular buffer at which the next byte of data will be stored when received from the connected piped output stream. |
protected static int |
INITIAL_SIZE
The initial buffer size. |
protected int |
mark
The mark position. |
protected int |
out
The index of the position in the circular buffer at which the next byte of data will be read by this piped input stream. |
| Constructor Summary | |
RubberPipedInputStream()
Constructs a new rubber piped input stream. |
|
RubberPipedInputStream(RubberPipedOutputStream out)
Constructs a new rubber piped input stream connected to the specified rubber piped output stream. |
|
| Method Summary | |
int |
available()
Returns the number of bytes that can be read from this input stream without blocking. |
protected void |
checkConnected()
Check to see if the pipe is connected. |
void |
close()
Closes this rubber piped input stream. |
void |
connect(RubberPipedOutputStream out)
Connects this rubber piped input stream to the specified rubber piped output stream. |
protected int |
freespace()
Computes the amount of free space in the buffer. |
protected void |
grow()
Doubles the size of the internal buffer. |
static void |
main(String[] args)
A simple test program. |
void |
mark(int readlimit)
Marks the current position in this input stream. |
boolean |
markSupported()
Tests if this input stream supports the mark and reset methods. |
int |
read()
Reads one byte of data from this rubber piped input stream. |
int |
read(byte[] b,
int off,
int len)
Reads up to len bytes of data from this rubber piped input
stream into an array of bytes. |
protected void |
receive1(byte[] b,
int off,
int len)
Receives data from an array of bytes. |
protected void |
receive1(int b)
Receives a single byte. |
void |
reset()
Repositions this stream to the position at the time the mark method was last called on this input stream. |
| Methods inherited from class java.io.InputStream |
read, skip |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected static final int INITIAL_SIZE
protected byte[] buffer
protected int in
in<0 implies the buffer is empty,
in==out implies the buffer is full.protected int out
protected int mark
protected boolean connected
protected boolean closed
| Constructor Detail |
public RubberPipedInputStream()
connect(RubberPipedOutputStream) or RubberPipedOutputStream.RubberPipedOutputStream(RubberPipedInputStream)
before it can be used; otherwise, an IOException will result.
public RubberPipedInputStream(RubberPipedOutputStream out)
throws IOException
out - The output stream to connect to.IOException - if out is already connected.| Method Detail |
public void connect(RubberPipedOutputStream out)
throws IOException
out.connect(this)
out - The output stream to connect to.IOException - if either endpoint is already connected.
protected void checkConnected()
throws IOException
IOException - if the pipe is closed or is not connected.protected void grow()
protected int freespace()
public int available()
available in class InputStream
protected void receive1(int b)
throws IOException
b - The byte to receive.IOException - if the pipe is closed or is not connected.
protected void receive1(byte[] b,
int off,
int len)
throws IOException
b - The buffer from which the data is received.off - The start offset of the data.len - The number of bytes to receive.IOException - if the pipe is closed or is not connected.
public int read()
throws IOException
read in class InputStreamIOException - if the pipe is closed or is not connected.
public int read(byte[] b,
int off,
int len)
throws IOException
len bytes of data from this rubber piped input
stream into an array of bytes. Less than len bytes
will be read if the end of the data stream is reached. This method
blocks until at least one byte of input is available.read in class InputStreamb - the buffer into which the data is read.off - the start offset of the data.len - the maximum number of bytes read.-1 if there is no more data because the end of
the stream has been reached.IOException - if an I/O error occurs.public void mark(int readlimit)
mark in class InputStreamreadlimit - The maximum limit of bytes that can be read before the mark position
becomes invalid.
public void reset()
throws IOException
reset in class InputStreamIOException - if no mark has been set.public boolean markSupported()
true.markSupported in class InputStreampublic void close()
close in class InputStream
public static void main(String[] args)
throws IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||