|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.Reader
uk.ac.gla.dcs.renaissance.ir.StringBufferReader
public class StringBufferReader
A non-blocking Reader
for reading the text that appears in a shared
StringBuffer
.
This class in intended to be thread-safe, and to be used both from inside and
outside a vat. When used in conjunction with StringWriter
or
our own StringBufferWriter
, the pair is like a non-blocking variant
of PipedReader
/PipedWriter
. The sharing must
be set up at creation time, as a StringBufferReader encapsulates its
StringBuffer.
In order to be non-blocking, we make the following change to the Reader contract: If a read(..) is attempted on a non-ready StringBufferReader, it will throw an IOException, rather than blocking or returning zero.
In order to be thread-safe, it uses the StringBuffer as its
Reader.lock
.
This class does no newline conversion. This should normally be done by the object that writes into the shared StringBuffer.
Field Summary |
---|
Fields inherited from class java.io.Reader |
---|
lock |
Constructor Summary | |
---|---|
StringBufferReader(StringBuffer buf)
Makes a Reader for reading from 'buf' |
Method Summary | |
---|---|
int |
available()
How many characters are immediately available? If the buffer is empty, then give the filler one chance and try again. |
void |
close()
|
boolean |
isDone()
Are we at end-of-stream? |
void |
mark(int readAheadLimit)
readAheadLimit is ignored |
int |
read(char[] cbuf,
int off,
int len)
Reads up to len chars, as many as it can without blocking. |
Character |
readChar()
Returns the next available character, or null at end of file. |
String |
readReady()
Returns as much as is available, or null at end-of-stream. |
String |
readString(int size)
Reads no more than 'size' characters from the file, and return them as a String. |
String |
readText()
Reads everything else and returns it. |
boolean |
ready()
True if either at least one character is available, or we're at the end-of-stream. |
void |
reset()
|
Methods inherited from class java.io.Reader |
---|
markSupported, read, read, read, skip |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringBufferReader(StringBuffer buf)
Method Detail |
---|
public void close() throws IOException
close
in interface Closeable
close
in class Reader
IOException
public int available() throws IOException
Currently, this entire operation is performed with 'lock' held. XXX Should we release 'lock' around the call to myOptFiller?
IOException
public boolean ready() throws IOException
ready
in class Reader
IOException
public boolean isDone() throws IOException
IOException
public int read(char[] cbuf, int off, int len) throws IOException
If it can't read even a single char without blocking, throw an IOException rather than blocking or returning 0.
read
in class Reader
IOException
public void mark(int readAheadLimit) throws IOException
mark
in class Reader
IOException
public void reset() throws IOException
reset
in class Reader
IOException
public Character readChar() throws IOException
If nothing is currently available, throws rather than blocking or returning -1.
IOException
public String readString(int size) throws IOException
IOException
public String readReady() throws IOException
If nothing is currently available, return "" rather than throwing.
IOException
public String readText() throws IOException
If everything else isn't yet available, then throws rather than blocking or returning something funny, but characters have still been consumed anyway. If this doesn't suit you, use mark() and reset() to protect yourself.
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |