NetworkOutputStream class
An OutputStream implementation that writes bytes to a Dart HttpClientRequest
.
This stream is used to send body content to a server over HTTP.
Use case:
This is typically used by a higher-level UrlConnection abstraction to manage writing request bodies before connecting the request.
Example:
final request = await HttpClient().postUrl(Uri.parse('https://example.com'));
final stream = NetworkOutputStream(request);
await stream.write([72, 101, 108, 108, 111]); // writes "Hello"
await stream.flush(); // ensures data is sent to the request buffer
await stream.close(); // closes the stream (but not the request itself)
// The actual HTTP request is sent by calling:
final response = await request.close();
⚠️ Do not call
_request.close()
in this stream. That should be done externally.
- Inheritance
-
- Object
- OutputStream
- NetworkOutputStream
Constructors
- NetworkOutputStream(HttpClientRequest _request)
-
An OutputStream implementation that writes bytes to a Dart
HttpClientRequest
.
Properties
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