|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream org.jgroups.util.BlockingInputStream
public class BlockingInputStream
Bounded input stream. A consumer reads bytes until the end of the stream is reached, or the input stream is closed. The producer writes bytes to the tail and blocks if the capacity has been reached (until the consumer reads more bytes).
This class is for only 1 producer and 1 consumer; multiple producers/consumers will most likely yield incorrect results ! Note that the implementation of this class is optimized for reading and adding a few K at a time; performance will be suboptimal if single bytes are added and read.
Field Summary | |
---|---|
protected byte[] |
buf
The transfer buffer |
protected boolean |
closed
Set to true when close() is called |
protected java.util.concurrent.locks.Lock |
lock
|
protected java.util.concurrent.locks.Condition |
not_empty
Signalled when the buf becomes 'readable'; ie. |
protected java.util.concurrent.locks.Condition |
not_full
Signalled when the buf becomes 'writeable'; ie. |
protected int |
read_pos
Index into buf at which the next bytes will be read. |
protected int |
write_pos
Index into buf at which bytes will be written. |
Constructor Summary | |
---|---|
BlockingInputStream()
|
|
BlockingInputStream(int capacity)
|
Method Summary | |
---|---|
int |
available()
|
int |
capacity()
|
void |
close()
Closes the stream. |
protected void |
compact()
Moves the bytes between [read_pos and write_pos] read_pos bytes to the left, such that the new read_pos is 0 and the write_pos is write_pos - read_pos. |
boolean |
isClosed()
|
int |
read()
|
int |
read(byte[] b)
|
int |
read(byte[] b,
int off,
int len)
|
protected int |
remaining()
|
protected static void |
sanityCheck(byte[] buf,
int offset,
int length)
Verifies that length doesn't exceed a buffer's length |
protected int |
size()
|
long |
skip(long n)
|
java.lang.String |
toString()
|
void |
write(byte[] buf)
Appends bytes to the end of the stream |
void |
write(byte[] buf,
int offset,
int length)
Appends bytes to the end of the stream. |
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean closed
close()
is called
protected final byte[] buf
protected int read_pos
protected int write_pos
protected final java.util.concurrent.locks.Lock lock
protected final java.util.concurrent.locks.Condition not_full
protected final java.util.concurrent.locks.Condition not_empty
Constructor Detail |
---|
public BlockingInputStream()
public BlockingInputStream(int capacity)
Method Detail |
---|
public int read() throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public void write(byte[] buf) throws java.io.IOException
buf
-
java.io.IOException
write(byte[],int,int)
public void write(byte[] buf, int offset, int length) throws java.io.IOException
buf
- The buffer to be added to the end of the streamoffset
- The offset within buf at which bytes are readlength
- The number of bytes to be added
java.io.IOException
public long skip(long n) throws java.io.IOException
skip
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public int capacity()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.InputStream
java.io.IOException
public boolean isClosed()
public java.lang.String toString()
toString
in class java.lang.Object
protected int size()
protected int remaining()
protected void compact()
protected static void sanityCheck(byte[] buf, int offset, int length)
buf
- offset
- length
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |