Class AsyncStreamDecorator<T>
Provides a base for a stream that wraps another one: its asynchronous I/O, capabilities, length, position, seeking and timeouts go to the source, and closing it closes the source, once, unless left open. Synchronous I/O is not supported, as on any AsyncStream.
public class AsyncStreamDecorator<T> : AsyncStream, IAsyncDisposable, IDisposable, IDataStream where T : Stream
Type Parameters
TThe source's type.
- Inheritance
-
AsyncStreamDecorator<T>
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
Its DisposeAsync() closes the source asynchronously: a synchronous close can block, as a QUIC stream's waits for its peer.
Constructors
AsyncStreamDecorator(T, bool)
Provides a base for a stream that wraps another one: its asynchronous I/O, capabilities, length, position, seeking and timeouts go to the source, and closing it closes the source, once, unless left open. Synchronous I/O is not supported, as on any AsyncStream.
public AsyncStreamDecorator(T sourceStream, bool leaveOpen)
Parameters
sourceStreamTThe source stream.
leaveOpenbooltrue to leave the source open when this stream is disposed.
Remarks
Its DisposeAsync() closes the source asynchronously: a synchronous close can block, as a QUIC stream's waits for its peer.
Fields
SourceStream
The source stream.
protected readonly T SourceStream
Field Value
- T
Properties
CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports reading.
public override bool CanRead { get; }
Property Value
Remarks
The source's.
CanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeking.
public override bool CanSeek { get; }
Property Value
Remarks
It is false here.
CanTimeout
Gets a value that determines whether the current stream can time out.
public override bool CanTimeout { get; }
Property Value
- bool
A value that determines whether the current stream can time out.
Remarks
The source's.
CanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writing.
public override bool CanWrite { get; }
Property Value
Remarks
The source's.
DataAvailable
Gets a value indicating whether data is waiting to be read: the source's, when it is an IDataStream or a NetworkStream; otherwise, null.
public virtual bool? DataAvailable { get; }
Property Value
- bool?
IsDisposed
Gets a value indicating whether the stream is disposed.
protected bool IsDisposed { get; }
Property Value
Length
When overridden in a derived class, gets the length in bytes of the stream.
public override long Length { get; }
Property Value
- long
A long value representing the length of the stream in bytes.
Remarks
The source's.
Exceptions
- NotSupportedException
A class derived from
Streamdoes not support seeking and the length is unknown.- ObjectDisposedException
Methods were called after the stream was closed.
Position
When overridden in a derived class, gets or sets the position within the current stream.
public override long Position { get; set; }
Property Value
- long
The current position within the stream.
Remarks
The source's.
Exceptions
- IOException
An I/O error occurs.
- NotSupportedException
The stream does not support seeking.
- ObjectDisposedException
Methods were called after the stream was closed.
ReadTimeout
Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.
public override sealed int ReadTimeout { get; set; }
Property Value
- int
A value, in milliseconds, that determines how long the stream will attempt to read before timing out.
Remarks
The source's.
Exceptions
- InvalidOperationException
The ReadTimeout method always throws an InvalidOperationException.
WriteTimeout
Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.
public override sealed int WriteTimeout { get; set; }
Property Value
- int
A value, in milliseconds, that determines how long the stream will attempt to write before timing out.
Remarks
The source's.
Exceptions
- InvalidOperationException
The WriteTimeout method always throws an InvalidOperationException.
Methods
CloseSourceAsync()
Closes the source asynchronously, once, by whichever close comes first.
protected ValueTask CloseSourceAsync()
Returns
- ValueTask
A task that represents the asynchronous operation.
Dispose(bool)
Closes the source synchronously, unless left open or closed already, when disposing.
protected override void Dispose(bool disposing)
Parameters
DisposeAsync()
Closes the source asynchronously, unless left open, then disposes this stream.
public override ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous operation.
FlushAsync(CancellationToken)
Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.
public override Task FlushAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- Task
A task that represents the asynchronous flush operation.
Remarks
It does nothing here.
Exceptions
- ObjectDisposedException
The stream has been disposed.
- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.
ReadAsync(Memory<byte>, CancellationToken)
Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default)
Parameters
bufferMemory<byte>The region of memory to write the data into.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- ValueTask<int>
A task that represents the asynchronous read operation. The value of its Result property contains the total number of bytes read into the buffer. The result value can be less than the length of the buffer if that many bytes are not currently available, or it can be 0 (zero) if the length of the buffer is 0 or if the end of the stream has been reached.
Remarks
The source's.
Exceptions
- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.
Seek(long, SeekOrigin)
When overridden in a derived class, sets the position within the current stream.
public override long Seek(long offset, SeekOrigin origin)
Parameters
offsetlongA byte offset relative to the
originparameter.originSeekOriginA value of type SeekOrigin indicating the reference point used to obtain the new position.
Returns
- long
The new position within the current stream.
Remarks
The source's.
Exceptions
- IOException
An I/O error occurs.
- NotSupportedException
The stream does not support seeking, such as if the stream is constructed from a pipe or console output.
- ObjectDisposedException
Methods were called after the stream was closed.
SetLength(long)
When overridden in a derived class, sets the length of the current stream.
public override void SetLength(long value)
Parameters
valuelongThe desired length of the current stream in bytes.
Remarks
The source's.
Exceptions
- IOException
An I/O error occurs.
- NotSupportedException
The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.
- ObjectDisposedException
Methods were called after the stream was closed.
WriteAsync(ReadOnlyMemory<byte>, CancellationToken)
Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
Parameters
bufferReadOnlyMemory<byte>The region of memory to write data from.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default value is None.
Returns
- ValueTask
A task that represents the asynchronous write operation.
Remarks
The source's.
Exceptions
- OperationCanceledException
The cancellation token was canceled. This exception is stored into the returned task.