Class NoFlushStream

Inheritance
NoFlushStream
Namespace: ETLBox.Helper
Assembly: ETLBox.dll
Syntax
    public class NoFlushStream : Stream, IAsyncDisposable, IDisposable

Constructors

NoFlushStream(Stream)

Declaration
    public NoFlushStream(Stream inner)
Parameters
TypeNameDescription
Streaminner

Properties

CanRead

When overridden in a derived class, gets a value indicating whether the current stream supports reading.

Declaration
    public override bool CanRead { get; }
Property Value
TypeDescription
bool

true if the stream supports reading; otherwise, false.

Overrides

CanSeek

When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

Declaration
    public override bool CanSeek { get; }
Property Value
TypeDescription
bool

true if the stream supports seeking; otherwise, false.

Overrides

CanTimeout

Gets a value that determines whether the current stream can time out.

Declaration
    public override bool CanTimeout { get; }
Property Value
TypeDescription
bool

A value that determines whether the current stream can time out.

Overrides

CanWrite

When overridden in a derived class, gets a value indicating whether the current stream supports writing.

Declaration
    public override bool CanWrite { get; }
Property Value
TypeDescription
bool

true if the stream supports writing; otherwise, false.

Overrides

Length

When overridden in a derived class, gets the length in bytes of the stream.

Declaration
    public override long Length { get; }
Property Value
TypeDescription
long

A long value representing the length of the stream in bytes.

Overrides
Exceptions
TypeCondition
NotSupportedException

A class derived from Stream does 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.

Declaration
    public override long Position { get; set; }
Property Value
TypeDescription
long

The current position within the stream.

Overrides
Exceptions
TypeCondition
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.

Declaration
    public override int ReadTimeout { get; set; }
Property Value
TypeDescription
int

A value, in milliseconds, that determines how long the stream will attempt to read before timing out.

Overrides
Exceptions
TypeCondition
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.

Declaration
    public override int WriteTimeout { get; set; }
Property Value
TypeDescription
int

A value, in milliseconds, that determines how long the stream will attempt to write before timing out.

Overrides
Exceptions
TypeCondition
InvalidOperationException

The WriteTimeout method always throws an InvalidOperationException.

Methods

BeginRead(byte[], int, int, AsyncCallback, object)

Begins an asynchronous read operation. (Consider using ReadAsync(byte[], int, int) instead.)

Declaration
    public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Parameters
TypeNameDescription
byte[]buffer

The buffer to read the data into.

intoffset

The byte offset in buffer at which to begin writing data read from the stream.

intcount

The maximum number of bytes to read.

AsyncCallbackcallback

An optional asynchronous callback, to be called when the read is complete.

objectstate

A user-provided object that distinguishes this particular asynchronous read request from other requests.

Returns
TypeDescription
IAsyncResult

An IAsyncResult that represents the asynchronous read, which could still be pending.

Overrides
Exceptions
TypeCondition
IOException

Attempted an asynchronous read past the end of the stream, or a disk error occurs.

ArgumentException

One or more of the arguments is invalid.

ObjectDisposedException

Methods were called after the stream was closed.

NotSupportedException

The current Stream implementation does not support the read operation.

BeginWrite(byte[], int, int, AsyncCallback, object)

Begins an asynchronous write operation. (Consider using WriteAsync(byte[], int, int) instead.)

Declaration
    public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Parameters
TypeNameDescription
byte[]buffer

The buffer to write data from.

intoffset

The byte offset in buffer from which to begin writing.

intcount

The maximum number of bytes to write.

AsyncCallbackcallback

An optional asynchronous callback, to be called when the write is complete.

objectstate

A user-provided object that distinguishes this particular asynchronous write request from other requests.

Returns
TypeDescription
IAsyncResult

An IAsyncResult that represents the asynchronous write, which could still be pending.

Overrides
Exceptions
TypeCondition
IOException

Attempted an asynchronous write past the end of the stream, or a disk error occurs.

ArgumentException

One or more of the arguments is invalid.

ObjectDisposedException

Methods were called after the stream was closed.

NotSupportedException

The current Stream implementation does not support the write operation.

Close()

Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.

Declaration
    public override void Close()
Overrides

CopyToAsync(Stream, int, CancellationToken)

Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. Both streams positions are advanced by the number of bytes copied.

Declaration
    public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
Parameters
TypeNameDescription
Streamdestination

The stream to which the contents of the current stream will be copied.

intbufferSize

The size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920.

CancellationTokencancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns
TypeDescription
Task

A task that represents the asynchronous copy operation.

Overrides
Exceptions
TypeCondition
ArgumentNullException

destination is null.

ArgumentOutOfRangeException

bufferSize is negative or zero.

ObjectDisposedException

Either the current stream or the destination stream is disposed.

NotSupportedException

The current stream does not support reading, or the destination stream does not support writing.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

EndRead(IAsyncResult)

Waits for the pending asynchronous read to complete. (Consider using ReadAsync(byte[], int, int) instead.)

Declaration
    public override int EndRead(IAsyncResult asyncResult)
Parameters
TypeNameDescription
IAsyncResultasyncResult

The reference to the pending asynchronous request to finish.

Returns
TypeDescription
int

The number of bytes read from the stream, between zero (0) and the number of bytes requested. ReadAsync returns zero (0) only if zero bytes were requested or if no more bytes will be available because it's at the end of the stream; otherwise, read operations do not complete until at least one byte is available. If zero bytes are requested, read operations may complete immediately or may not complete until at least one byte is available (but without consuming any data).

Overrides
Exceptions
TypeCondition
ArgumentNullException

asyncResult is null.

ArgumentException

A handle to the pending read operation is not available.

-or-

The pending operation does not support reading.

InvalidOperationException

asyncResult did not originate from a BeginRead(byte[], int, int, AsyncCallback, object) method on the current stream.

IOException

The stream is closed or an internal error has occurred.

EndWrite(IAsyncResult)

Ends an asynchronous write operation. (Consider using WriteAsync(byte[], int, int) instead.)

Declaration
    public override void EndWrite(IAsyncResult asyncResult)
Parameters
TypeNameDescription
IAsyncResultasyncResult

A reference to the outstanding asynchronous I/O request.

Overrides
Exceptions
TypeCondition
ArgumentNullException

asyncResult is null.

ArgumentException

A handle to the pending write operation is not available.

-or-

The pending operation does not support writing.

InvalidOperationException

asyncResult did not originate from a BeginWrite(byte[], int, int, AsyncCallback, object) method on the current stream.

IOException

The stream is closed or an internal error has occurred.

Flush()

When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

Declaration
    public override void Flush()
Overrides
Exceptions
TypeCondition
IOException

An I/O error occurs.

FlushAsync(CancellationToken)

Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

Declaration
    public override Task FlushAsync(CancellationToken cancellationToken)
Parameters
TypeNameDescription
CancellationTokencancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns
TypeDescription
Task

A task that represents the asynchronous flush operation.

Overrides
Exceptions
TypeCondition
ObjectDisposedException

The stream has been disposed.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

Read(byte[], int, int)

When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Declaration
    public override int Read(byte[] buffer, int offset, int count)
Parameters
TypeNameDescription
byte[]buffer

An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.

intoffset

The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

intcount

The maximum number of bytes to be read from the current stream.

Returns
TypeDescription
int

The total number of bytes read into the buffer. This can be less than the number of bytes requested if that many bytes are not currently available, or zero (0) if count is 0 or the end of the stream has been reached.

Overrides
Exceptions
TypeCondition
ArgumentException

The sum of offset and count is larger than the buffer length.

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

IOException

An I/O error occurs.

NotSupportedException

The stream does not support reading.

ObjectDisposedException

Methods were called after the stream was closed.

ReadAsync(byte[], int, int, 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.

Declaration
    public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
TypeNameDescription
byte[]buffer

The buffer to write the data into.

intoffset

The byte offset in buffer at which to begin writing data from the stream.

intcount

The maximum number of bytes to read.

CancellationTokencancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns
TypeDescription
Task<int>

A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if count is 0 or if the end of the stream has been reached.

Overrides
Exceptions
TypeCondition
ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

ArgumentException

The sum of offset and count is larger than the buffer length.

NotSupportedException

The stream does not support reading.

ObjectDisposedException

The stream has been disposed.

InvalidOperationException

The stream is currently in use by a previous read operation.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

ReadByte()

Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

Declaration
    public override int ReadByte()
Returns
TypeDescription
int

The unsigned byte cast to an int, or -1 if at the end of the stream.

Overrides
Exceptions
TypeCondition
NotSupportedException

The stream does not support reading.

ObjectDisposedException

Methods were called after the stream was closed.

Seek(long, SeekOrigin)

When overridden in a derived class, sets the position within the current stream.

Declaration
    public override long Seek(long offset, SeekOrigin origin)
Parameters
TypeNameDescription
longoffset

A byte offset relative to the origin parameter.

SeekOriginorigin

A value of type SeekOrigin indicating the reference point used to obtain the new position.

Returns
TypeDescription
long

The new position within the current stream.

Overrides
Exceptions
TypeCondition
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.

Declaration
    public override void SetLength(long value)
Parameters
TypeNameDescription
longvalue

The desired length of the current stream in bytes.

Overrides
Exceptions
TypeCondition
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.

Write(byte[], int, int)

When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Declaration
    public override void Write(byte[] buffer, int offset, int count)
Parameters
TypeNameDescription
byte[]buffer

An array of bytes. This method copies count bytes from buffer to the current stream.

intoffset

The zero-based byte offset in buffer at which to begin copying bytes to the current stream.

intcount

The number of bytes to be written to the current stream.

Overrides
Exceptions
TypeCondition
ArgumentException

The sum of offset and count is greater than the buffer length.

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

IOException

An I/O error occurred, such as the specified file cannot be found.

NotSupportedException

The stream does not support writing.

ObjectDisposedException

Write(byte[], int, int) was called after the stream was closed.

WriteAsync(byte[], int, int, 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.

Declaration
    public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
TypeNameDescription
byte[]buffer

The buffer to write data from.

intoffset

The zero-based byte offset in buffer from which to begin copying bytes to the stream.

intcount

The maximum number of bytes to write.

CancellationTokencancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns
TypeDescription
Task

A task that represents the asynchronous write operation.

Overrides
Exceptions
TypeCondition
ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

ArgumentException

The sum of offset and count is larger than the buffer length.

NotSupportedException

The stream does not support writing.

ObjectDisposedException

The stream has been disposed.

InvalidOperationException

The stream is currently in use by a previous write operation.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

WriteByte(byte)

Writes a byte to the current position in the stream and advances the position within the stream by one byte.

Declaration
    public override void WriteByte(byte value)
Parameters
TypeNameDescription
bytevalue

The byte to write to the stream.

Overrides
Exceptions
TypeCondition
IOException

An I/O error occurs.

NotSupportedException

The stream does not support writing, or the stream is already closed.

ObjectDisposedException

Methods were called after the stream was closed.

Implements