InputStreamReader

port of InputStreamReader

An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified [ ]. The charset that it uses may be specified by name or may be given explicitly, or the default charset may be used.

Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.

For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:

{@snippet lang=java :

  • BufferedReader in = new BufferedReader(new InputStreamReader(anInputStream));
  • }

Author

Mark Reinhold

Since

1.1

See also

Constructors

Link copied to clipboard
constructor(in: InputStream)

Creates an InputStreamReader that uses the default charset.

constructor(in: InputStream, cs: Charset)

Creates an InputStreamReader that uses the given charset.

constructor(in: InputStream, dec: CharsetDecoder)

Creates an InputStreamReader that uses the given charset decoder.

Properties

Link copied to clipboard

Functions

Link copied to clipboard
open override fun close()

Closes the reader and releases any associated resources.

Link copied to clipboard
open override fun read(): Int

Reads a single character.

open override fun read(target: CharBuffer): Int

Reads characters into a CharBuffer. This default implementation reads into an array and then puts the characters into the buffer.

open override fun read(cbuf: CharArray, off: Int, len: Int): Int

{@inheritDoc}

Link copied to clipboard
open override fun ready(): Boolean

Tells whether this stream is ready to be read. An InputStreamReader is ready if its input buffer is not empty, or if bytes are available to be read from the underlying byte stream.

Link copied to clipboard
open fun reset()

Resets the stream. If the stream has been marked, then attempt to reposition it at the mark. If the stream has not been marked, then attempt to reset it in some way appropriate to the particular stream, for example by repositioning it to its starting point. Not all character-input streams support the reset() operation, and some support reset() without supporting mark().

Link copied to clipboard
open fun transferTo(out: Writer): Long

Reads all characters from this Reader and writes them to out. Returns the number of characters transferred.