close method

  1. @override
Future<void> close()
override

Closes this output stream and releases any system resources associated with this stream.

A closed stream cannot perform output operations and cannot be reopened. The close method of OutputStream calls flush before closing the stream.

Example

final output = FileOutputStream('output.txt');
try {
  await output.writeString('Hello, World!');
  // flush() is called automatically by close()
} finally {
  await output.close(); // Always close in finally block
}

Throws IOException if an I/O error occurs.

Implementation

@override
Future<void> close() async {
  if (!isClosed) {
    // Important: Do NOT call _request.close() here.
    // The HttpClientRequest is closed by UrlConnection.connect()
    // to ensure the request is sent after all data is written.
    await super.close();
  }
}