Reader class abstract

Abstract class for reading character streams.

The only methods that a subclass must implement are readChar and close. Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both.

Design Philosophy

The Reader class provides a uniform interface for reading character data from various sources. Unlike InputStream which deals with raw bytes, Reader handles character encoding and provides text-oriented operations.

Example Usage

// Reading from a file
final reader = FileReader('document.txt');
try {
  String line;
  while ((line = await reader.readLine()) != null) {
    print('Line: $line');
  }
} finally {
  await reader.close();
}

// Reading with buffering for better performance
final bufferedReader = BufferedReader(FileReader('large_document.txt'));
try {
  final content = await bufferedReader.readAll();
  processText(content);
} finally {
  await bufferedReader.close();
}
Implemented types
Implementers

Constructors

Reader()
Abstract class for reading character streams.

Properties

hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Returns true if this reader has been closed.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkClosed() → void
Checks if the reader is closed and throws an exception if it is.
close() Future<void>
Closes the stream and releases any system resources associated with it.
override
mark(int readAheadLimit) → void
Marks the present position in the stream.
markSupported() bool
Tells whether this stream supports the mark() operation.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
read(List<int> cbuf, [int offset = 0, int? length]) Future<int>
Reads characters into an array.
readAll() Future<String>
Reads all remaining characters from the reader.
readChar() Future<int>
Reads a single character.
readLine() Future<String?>
Reads a line of text.
ready() Future<bool>
Tells whether this stream is ready to be read.
reset() Future<void>
Resets the stream.
skip(int n) Future<int>
Skips characters.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited