java.io.StringReader
java.io.Reader
None
None
New as of JDK 1.1
The StringReader class represents a character stream whose data source is a String. This class is similar to the CharArrayReader class, which uses a char array as its data source.
StringReader is meant to replace the StringBufferInputStream class as of JDK 1.1. Unlike StringBufferInputStream, StringReader handles Unicode characters and supports mark() and reset().
public class java.io.StringReader extends java.io.Reader { // Constructors public StringReader(String s); // Instance Methods public void close(); public void mark(int readAheadLimit); public boolean markSupported(); public int read(); public int read(char[] cbuf, int off, int len); public boolean ready(); public void reset(); public long skip(long ns); }
The String to use.
This constructor creates a StringReader that uses the given String as its data source. The data is not copied, so changes made to the String affect the data that the StringReader returns.
Reader.close()
This method closes the reader by removing the link between this StringReader and the String it was created with.
The maximum number of characters that can be read before the saved position becomes invalid.
If the stream is closed or any other kind of I/O error occurs.
Reader.mark()
This method causes the StringReader to remember its current position. A subsequent call to reset() causes the object to return to that saved position, and thus re-read a portion of the string. Because the data for this stream comes from a String, there is no limit on reading ahead, so readAheadLimit is ignored.
The boolean value true.
Reader.markSupported()
This method returns true to indicate that this class supports mark() and reset().
The next character or -1 if the end of the string is encountered.
If the stream is closed or any other kind of I/O error occurs.
Reader.read()
This method returns the next character from the string. The method cannot block.
An array of characters to be filled from the stream.
An offset into the character array.
The number of characters to read.
The actual number of characters read or -1 if the end of the string is encountered immediately.
If the stream is closed or any other kind of I/O error occurs.
Reader.read(char[], int, int)
This method copies up to len characters from the internal buffer into the given array cbuf, starting at index off.
A boolean value that indicates whether the stream is ready to be read.
If the stream is closed or any other kind of I/O error occurs.
Reader.ready()
If there is any data left to be read from the string, this method returns true.
If the stream is closed or any other kind of I/O error occurs.
Reader.reset()
This method resets the position of the StringReader to the position that was saved by calling the mark() method. If mark() has not been called, the StringReader is reset to read from the beginning of the string.
The number of bytes to skip.
The actual number of bytes skipped.
If the stream is closed or any other kind of I/O error occurs.
Reader.skip()
This method skips ns characters of input. If you try to skip past the end of the string, the stream is positioned at the end of the string.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals (Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
read(char[]) |
Reader |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
CharArrayReader, IOException, Reader, String, StringBufferInputStream