public class StringBuilderReader extends Reader
Reader over a StringBuilder instance. Although
one can use StringReader by passing it
StringBuilder.toString(), it is better to use this class, as it
doesn't mark the passed-in StringBuilder as shared (which will cause
inner char[] allocations at the next append() attempt).StringBuilder is not
changed during the use of this Reader implementation.
StringReader (for
the right reasons).
StringBuilder sb = new StringBuilder("some text");
Reader reader = new StringBuilderReader(sb);
... read from reader - don't close it ! ...
sb.setLength(0);
sb.append("some new text");
reader.reset();
... read the new string from the reader ...
| Constructor and Description |
|---|
StringBuilderReader(StringBuilder sb) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
mark(int readAheadLimit)
Mark the present position in the stream.
|
boolean |
markSupported() |
int |
read() |
int |
read(char[] cbuf,
int off,
int len) |
boolean |
ready() |
void |
reset() |
void |
set(StringBuilder sb) |
long |
skip(long ns) |
public StringBuilderReader(StringBuilder sb)
public void close()
public void mark(int readAheadLimit)
throws IOException
mark in class ReaderreadAheadLimit - Limit on the number of characters that may be read
while still preserving the mark. Because the stream's input comes
from a StringBuilder, there is no actual limit, so this argument
must not be negative, but is otherwise ignored.IllegalArgumentException - If readAheadLimit is < 0IOException - If an I/O error occurspublic boolean markSupported()
markSupported in class Readerpublic int read()
throws IOException
read in class ReaderIOExceptionpublic int read(char[] cbuf,
int off,
int len)
throws IOException
read in class ReaderIOExceptionpublic boolean ready()
throws IOException
ready in class ReaderIOExceptionpublic void reset()
throws IOException
reset in class ReaderIOExceptionpublic void set(StringBuilder sb)
public long skip(long ns)
throws IOException
skip in class ReaderIOException