|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.io.ExpandingBuffer<char[]>
edu.rice.cs.plt.io.ExpandingCharBuffer
public class ExpandingCharBuffer
A character buffer of arbitrary size to be used with Readers and Writers. The
buffer is a FIFO queue of characters. It provides a DirectWriter for adding
characters to the end and a DirectReader for pulling characters 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 writer() attempts to write from the result of reader(),
and the reader blocks, a write from another thread will be necessary to unblock the reader.
At that point, the original write() will have already instructed the reader to copy
its data into an incorrect location. In general, connecting a reader and a writer from the same
buffer is not recommended.
| Field Summary |
|---|
| Fields inherited from class edu.rice.cs.plt.io.ExpandingBuffer |
|---|
BUFFER_SIZE |
| Constructor Summary | |
|---|---|
ExpandingCharBuffer()
|
|
| Method Summary | |
|---|---|
protected char[] |
allocateBuffer(int size)
Create a fixed-size sub-buffer |
void |
end()
Place an "end of file" at the end of the buffer. |
boolean |
isEnded()
|
DirectReader |
reader()
Create a reader providing read access to the buffer. |
DirectWriter |
writer()
Create a writer 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 ExpandingCharBuffer()
| Method Detail |
|---|
public void end()
public boolean isEnded()
protected char[] allocateBuffer(int size)
ExpandingBuffer
allocateBuffer in class ExpandingBuffer<char[]>public DirectWriter writer()
write will atomically
add characters directly to the buffer. Writer.close() will have no effect.
public DirectReader reader()
read will atomically
remove characters from the buffer. Reader.close() will have no effect.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||