public class StringReader extends Reader
Reader
that reads characters from a String
in a sequential manner.StringWriter
Constructor and Description |
---|
StringReader(java.lang.String str)
Construct a new
StringReader with str as source. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this reader.
|
int |
read()
Reads a single character from the source string and returns it as an integer with the two higher-order bytes set
to 0.
|
int |
read(char[] buf,
int offset,
int length)
Reads at most
len characters from the source string and stores them at offset in the character
array buf . |
public StringReader(java.lang.String str)
StringReader
with str
as source. The size of the reader is set to the length()
of the string.str
- the source string for this reader.public void close()
IOException
. Only the
first invocation of this method has any effect.close
in interface java.lang.AutoCloseable
close
in class AutoCloseable
public int read()
read
in class Reader
IOException
- if this reader is closedpublic int read(char[] buf, int offset, int length)
len
characters from the source string and stores them at offset
in the character
array buf
. Returns the number of characters actually read or -1 if the end of the source string has been
reached.read
in class Reader
buf
- the character array to store the characters readoffset
- the initial position in buffer
to store the characters read from this readerlength
- the maximum number of characters to readjava.lang.IndexOutOfBoundsException
- if offset < 0
or len < 0
, or if offset + len
is greater
than the size of buf
.IOException
- if this reader is closed