StringReader
open class StringReader : Reader
kotlin.Any | ||
↳ | java.io.Reader | |
↳ | java.io.StringReader |
A character stream whose source is a string.
Summary
Public constructors | |
---|---|
StringReader(s: String!) Creates a new string reader. |
Public methods | |
---|---|
open Unit |
close() Closes the stream and releases any system resources associated with it. |
open Unit |
Marks the present position in the stream. |
open Boolean |
Tells whether this stream supports the mark() operation, which it does. |
open Int |
read() Reads a single character. |
open Int |
Reads characters into a portion of an array. |
open Boolean |
ready() Tells whether this stream is ready to be read. |
open Unit |
reset() Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked. |
open Long |
Skips the specified number of characters in the stream. |
Inherited functions | |
---|---|
Inherited properties | |
---|---|
Public constructors
StringReader
StringReader(s: String!)
Creates a new string reader.
Parameters | |
---|---|
s |
String!: String providing the character stream. |
Public methods
close
open fun close(): Unit
Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously closed stream has no effect. This method will block while there is another thread blocking on the reader.
Exceptions | |
---|---|
java.lang.Exception |
if this resource cannot be closed |
java.io.IOException |
if an I/O error occurs |
mark
open fun mark(readAheadLimit: Int): Unit
Marks the present position in the stream. Subsequent calls to reset() will reposition the stream to this point.
Parameters | |
---|---|
readAheadLimit |
Int: Limit on the number of characters that may be read while still preserving the mark. Because the stream's input comes from a string, there is no actual limit, so this argument must not be negative, but is otherwise ignored. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If readAheadLimit < 0 |
java.io.IOException |
If an I/O error occurs |
markSupported
open fun markSupported(): Boolean
Tells whether this stream supports the mark() operation, which it does.
Return | |
---|---|
Boolean |
true if and only if this stream supports the mark operation. |
read
open fun read(): Int
Reads a single character.
Return | |
---|---|
Int |
The character read, or -1 if the end of the stream has been reached |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
read
open fun read(
cbuf: CharArray!,
off: Int,
len: Int
): Int
Reads characters into a portion of an array.
Parameters | |
---|---|
cbuf |
CharArray!: Destination buffer |
off |
Int: Offset at which to start writing characters |
len |
Int: Maximum number of characters to read |
Return | |
---|---|
Int |
The number of characters read, or -1 if the end of the stream has been reached |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
java.lang.IndexOutOfBoundsException |
If off is negative, or len is negative, or len is greater than cbuf.length - off |
ready
open fun ready(): Boolean
Tells whether this stream is ready to be read.
Return | |
---|---|
Boolean |
True if the next read() is guaranteed not to block for input |
Exceptions | |
---|---|
java.io.IOException |
If the stream is closed |
reset
open fun reset(): Unit
Resets the stream to the most recent mark, or to the beginning of the string if it has never been marked.
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |
skip
open fun skip(ns: Long): Long
Skips the specified number of characters in the stream. Returns the number of characters that were skipped.
The ns
parameter may be negative, even though the skip
method of the Reader
superclass throws an exception in this case. Negative values of ns
cause the stream to skip backwards. Negative return values indicate a skip backwards. It is not possible to skip backwards past the beginning of the string.
If the entire string has been read or skipped, then this method has no effect and always returns 0.
Parameters | |
---|---|
n |
The number of characters to skip |
Return | |
---|---|
Long |
The number of characters actually skipped |
Exceptions | |
---|---|
java.io.IOException |
If an I/O error occurs |