public class StringBufferReader
extends java.io.Reader
Reader over a StringBuffer instance. Although
one can use StringReader by passing it
StringBuffer.toString(), it is better to use this class, as it
doesn't mark the passed-in StringBuffer as shared (which will cause
inner char[] allocations at the next append() attempt).StringBuffer is not
changed during the use of this Reader implementation.
StringReader (for
the right reasons).
StringBuffer sb = new StringBuffer("some text");
Reader reader = new StringBufferReader(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 |
|---|
StringBufferReader(java.lang.StringBuffer 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(java.lang.StringBuffer sb) |
long |
skip(long ns) |
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.Readerpublic void mark(int readAheadLimit)
throws java.io.IOException
mark in class java.io.ReaderreadAheadLimit - Limit on the number of characters that may be read
while still preserving the mark. Because the stream's input comes
from a StringBuffer, there is no actual limit, so this argument
must not be negative, but is otherwise ignored.java.lang.IllegalArgumentException - If readAheadLimit is < 0java.io.IOException - If an I/O error occurspublic boolean markSupported()
markSupported in class java.io.Readerpublic int read()
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic int read(char[] cbuf,
int off,
int len)
throws java.io.IOException
read in class java.io.Readerjava.io.IOExceptionpublic boolean ready()
throws java.io.IOException
ready in class java.io.Readerjava.io.IOExceptionpublic void reset()
throws java.io.IOException
reset in class java.io.Readerjava.io.IOExceptionpublic void set(java.lang.StringBuffer sb)
public long skip(long ns)
throws java.io.IOException
skip in class java.io.Readerjava.io.IOExceptionCopyright © 2000-2016 Apache Software Foundation. All Rights Reserved.