ConsolePrintStream class

A concrete implementation of PrintStream that writes to the console using stdout.

ConsolePrintStream provides a high-level abstraction over stdout, offering utility methods like write, writeln, newline, flush, and close.

By default, it uses stdout.nonBlocking for efficient, non-blocking output, but you can also provide a custom IOSink to redirect output (e.g., to a file).


πŸ“¦ Example Usage:

final stream = ConsolePrintStream();
stream.write('Hello');
stream.writeln(' world');
stream.newline();
stream.flush();
await stream.close();

This class is useful when abstracting over console or file output in logging systems, REPLs, shell interfaces, and testable I/O components.

Implemented types

Constructors

ConsolePrintStream([IOSink? sink])
A concrete implementation of PrintStream that writes to the console using stdout.

Properties

hashCode β†’ int
The hash code for this object.
no setterinherited
runtimeType β†’ Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() β†’ Future<void>
An abstract interface representing a stream for formatted text output.
override
flush() β†’ void
An abstract interface representing a stream for formatted text output.
override
newline() β†’ void
An abstract interface representing a stream for formatted text output.
override
noSuchMethod(Invocation invocation) β†’ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
print(Object? obj) β†’ void
An abstract interface representing a stream for formatted text output.
override
println([Object? obj]) β†’ void
An abstract interface representing a stream for formatted text output.
override
toString() β†’ String
A string representation of this object.
inherited

Operators

operator ==(Object other) β†’ bool
The equality operator.
inherited