OutputStream class abstract
This abstract class is the superclass of all classes representing an output stream of bytes.
An output stream accepts output bytes and sends them to some sink. Applications that need to define a subclass of OutputStream must always provide at least a method that writes one byte of output.
Design Philosophy
The OutputStream class provides a uniform interface for writing data to various destinations such as files, network connections, or memory buffers. It follows the decorator pattern, allowing streams to be wrapped with additional functionality like buffering or compression.
Example Usage
// Writing to a file
final output = FileOutputStream('output.bin');
try {
await output.write([72, 101, 108, 108, 111]); // "Hello"
await output.writeByte(33); // "!"
await output.flush();
} finally {
await output.close();
}
// Writing with buffering for better performance
final bufferedOutput = BufferedOutputStream(FileOutputStream('large_file.bin'));
try {
for (int i = 0; i < 1000000; i++) {
await bufferedOutput.writeByte(i % 256);
}
await bufferedOutput.flush(); // Ensure all data is written
} finally {
await bufferedOutput.close();
}
- Implemented types
- Implementers
Constructors
- OutputStream()
- This abstract class is the superclass of all classes representing an output stream of bytes.
Properties
Methods
-
checkClosed(
) → void - Checks if the stream is closed and throws an exception if it is.
-
close(
) → Future< void> -
Closes this output stream and releases any system resources associated
with this stream.
override
-
flush(
) → Future< void> -
Flushes this output stream and forces any buffered output bytes to be
written out.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
List< int> b, [int offset = 0, int? length]) → Future<void> -
Writes
b.length
bytes from the specified byte array to this output stream. -
writeByte(
int b) → Future< void> - Writes the specified byte to this output stream.
-
writeBytes(
Uint8List data) → Future< void> - Writes all bytes from the specified Uint8List to this output stream.
-
writeString(
String str) → Future< void> - Writes a string to this output stream using UTF-8 encoding.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited