BufferedOutputStream class

The class implements a buffered output stream.

By setting up such an output stream, an application can write bytes to the underlying output stream without necessarily causing a call to the underlying system for each byte written.

Example Usage

// Basic buffered writing
final buffered = BufferedOutputStream(FileOutputStream('output.bin'));
try {
  for (int i = 0; i < 10000; i++) {
    await buffered.writeByte(i % 256);
  }
  await buffered.flush(); // Ensure all data is written
} finally {
  await buffered.close();
}

// Writing large amounts of data efficiently
final buffered = BufferedOutputStream(
  FileOutputStream('large_output.bin'),
  bufferSize: 65536 // 64KB buffer
);
try {
  final data = generateLargeDataSet();
  await buffered.write(data);
  await buffered.flush();
} finally {
  await buffered.close();
}
Inheritance

Constructors

BufferedOutputStream(OutputStream output, {int bufferSize = _defaultBufferSize})
Creates a new buffered output stream to write data to the specified underlying output stream.

Properties

bufferedCount int
Returns the number of bytes currently in the buffer.
no setter
bufferSize int
Returns the size of the internal buffer.
no setter
hashCode int
The hash code for this object.
no setterinherited
isClosed bool
Returns true if this stream has been closed.
no setterinherited
remainingBufferSpace int
Returns the remaining space in the buffer.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
underlyingStream OutputStream
Returns the underlying output stream.
no setter

Methods

checkClosed() → void
Checks if the stream is closed and throws an exception if it is.
inherited
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.
override
writeByte(int b) Future<void>
Writes the specified byte to this output stream.
override
writeBytes(Uint8List data) Future<void>
Writes all bytes from the specified Uint8List to this output stream.
inherited
writeString(String str) Future<void>
Writes a string to this output stream using UTF-8 encoding.
inherited

Operators

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