|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.rice.cs.plt.io.ExpandingBuffer<byte[]>
edu.rice.cs.plt.io.ExpandingByteBuffer
public class ExpandingByteBuffer
A byte buffer of arbitrary size to be used with InputStreams and OutputStreams. The
buffer is a FIFO queue of bytes. It provides a DirectOutputStream
for adding
bytes to the end and a DirectInputStream
for pulling bytes from the front.
This allows behavior similar to that of a PipedWriter
and PipedReader
,
but without any assumptions about access from different threads, without any restrictions on
the size of the buffer (so writing will never block), and with support for multiple
readers or writers connected to the same source. (If access is restricted to a single thread,
care must be taken to never read when the buffer is empty.)
While an attempt at thread safety has been made, at least one exception is evident:
if the result of outputStream()
attempts to write from the result of inputStream()
,
and the inputStream blocks, a write from another thread will be necessary to unblock the inputStream.
At that point, the original write()
will have already instructed the inputStream to copy
its data into an incorrect location. In general, connecting a inputStream and a outputStream from the same
buffer is not recommended.
Field Summary |
---|
Fields inherited from class edu.rice.cs.plt.io.ExpandingBuffer |
---|
BUFFER_SIZE |
Constructor Summary | |
---|---|
ExpandingByteBuffer()
|
Method Summary | |
---|---|
protected byte[] |
allocateBuffer(int size)
Create a fixed-size sub-buffer |
void |
end()
Place an "end of file" at the end of the buffer. |
DirectInputStream |
inputStream()
Create an input stream providing read access to the buffer. |
boolean |
isEnded()
|
DirectOutputStream |
outputStream()
Create an output stream providing write access to the buffer. |
Methods inherited from class edu.rice.cs.plt.io.ExpandingBuffer |
---|
allocate, deallocate, elementsInFirstBuffer, firstBuffer, firstIndex, isEmpty, lastBuffer, lastIndex, recordRead, recordWrite, size |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ExpandingByteBuffer()
Method Detail |
---|
public void end()
public boolean isEnded()
protected byte[] allocateBuffer(int size)
ExpandingBuffer
allocateBuffer
in class ExpandingBuffer<byte[]>
public DirectOutputStream outputStream()
write
will
atomically add bytes directly to the buffer. OutputStream.close()
will have no effect.
public DirectInputStream inputStream()
read
will
atomically remove bytes from the buffer. InputStream.close()
will have no effect.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |