Skip to content

Most visited

Recently visited

navigation
Added in API level 1

StringReader

public class StringReader
extends Reader

java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.StringReader


A specialized Reader that reads characters from a String in a sequential manner.

See also:

Summary

Inherited fields

From class java.io.Reader

Public constructors

StringReader(String str)

Construct a new StringReader with str as source.

Public methods

void close()

Closes this reader.

void mark(int readLimit)

Sets a mark position in this reader.

boolean markSupported()

Indicates whether this reader supports the mark() and reset() methods.

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[] buffer, int offset, int count)

Reads up to count characters from the source string and stores them at offset in the character array buffer.

boolean ready()

Indicates whether this reader is ready to be read without blocking.

void reset()

Resets this reader's position to the last mark() location.

long skip(long charCount)

Moves charCount characters in the source string.

Inherited methods

From class java.io.Reader
From class java.lang.Object
From interface java.lang.Readable
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public constructors

StringReader

Added in API level 1
StringReader (String str)

Construct a new StringReader with str as source. The size of the reader is set to the length() of the string and the Object to synchronize access through is set to str.

Parameters
str String: the source string for this reader.

Public methods

close

Added in API level 1
void close ()

Closes this reader. Once it is closed, read operations on this reader will throw an IOException. Only the first invocation of this method has any effect.

mark

Added in API level 1
void mark (int readLimit)

Sets a mark position in this reader. The parameter readLimit is ignored for this class. Calling reset() will reposition the reader back to the marked position.

Parameters
readLimit int: ignored for StringReader instances.
Throws
IllegalArgumentException if readLimit < 0.
IOException if this reader is closed.

See also:

markSupported

Added in API level 1
boolean markSupported ()

Indicates whether this reader supports the mark() and reset() methods. This implementation returns true.

Returns
boolean always true.

read

Added in API level 1
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. Returns -1 if the end of the source string has been reached.

Returns
int the character read or -1 if the end of the source string has been reached.
Throws
IOException if this reader is closed.

read

Added in API level 1
int read (char[] buffer, 
                int offset, 
                int count)

Reads up to count characters from the source string and stores them at offset in the character array buffer. Returns the number of characters actually read or -1 if the end of the source string has been reached.

Parameters
buffer char
offset int
count int
Returns
int
Throws
IndexOutOfBoundsException if offset < 0 || count < 0 || offset + count > buffer.length.
IOException if this reader is closed.

ready

Added in API level 1
boolean ready ()

Indicates whether this reader is ready to be read without blocking. This implementation always returns true.

Returns
boolean always true.
Throws
IOException if this reader is closed.

See also:

reset

Added in API level 1
void reset ()

Resets this reader's position to the last mark() location. Invocations of read() and skip() will occur from this new location. If this reader has not been marked, it is reset to the beginning of the source string.

Throws
IOException if this reader is closed.

See also:

skip

Added in API level 1
long skip (long charCount)

Moves charCount characters in the source string. Unlike the overridden method, this method may skip negative skip distances: this rewinds the input so that characters may be read again. When the end of the source string has been reached, the input cannot be rewound.

Parameters
charCount long: the maximum number of characters to skip. Positive values skip forward; negative values skip backward.
Returns
long the number of characters actually skipped. This is bounded below by the number of characters already read and above by the number of characters remaining:
-(num chars already read) <= distance skipped <= num chars remaining.
Throws
IOException if this reader is closed.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.