Class InputStreamReader

java.lang.Object
java.io.Reader
org.jline.utils.InputStreamReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

public class InputStreamReader extends Reader
A specialized InputStreamReader that reads the minimal number of bytes needed.

This class is a custom implementation of InputStreamReader that reads only the minimal number of bytes needed from the input stream to decode characters. Unlike the standard JRE InputStreamReader, which often reads more bytes than necessary, this implementation is optimized for character-by-character reading, which is essential for terminal input handling.

The standard InputStreamReader's behavior of reading ahead is problematic for terminal applications because:

  • It can consume bytes that belong to the next user input
  • It makes it difficult to implement non-blocking character reading
  • It interferes with the character-by-character model used in terminals

This implementation is based on the Apache Harmony code and has been adapted for JLine's needs. It provides the same functionality as the standard InputStreamReader but with more precise control over how many bytes are read from the underlying input stream.

This class turns a byte stream into a character stream. Data read from the source input stream is converted into characters by either a default or a provided character converter. The default encoding is taken from the "file.encoding" system property. It contains a buffer of bytes read from the source stream and converts these into characters as needed. The buffer size is 8K.

This class is used internally by JLine components that need to read characters from input streams, such as terminal input handling and non-blocking readers.

See Also: