OutputStream constructor
OutputStream()
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();
}
Implementation
OutputStream();