Class BBStream
Stream wrapper which adds ability to flush and check for available data on all streams which need to be accessed. Also adds ability to have a timeout on stream read and writes without the underlying connection closing on failure
Assembly: Brainboxes.IO.dll
View Source
public abstract class BBStream : Stream, IAsyncDisposable, IDisposable
Inheritance: System.Object -> System.MarshalByRefObject -> System.IO.Stream
Implements:
System.IAsyncDisposable, System.IDisposable
Properties
BaseStream
the underlying stream
View Source
public Stream BaseStream { get; }
DataAvailable
Indicates whether data is available, can be 0, for no data, 1 for 1 or more bytes, or a number representing the precise number of bytes
View Source
public abstract int DataAvailable { get; }
CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports reading.
View Source
public override bool CanRead { get; }
CanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeking.
View Source
public override bool CanSeek { get; }
CanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writing.
View Source
public override bool CanWrite { get; }
Length
When overridden in a derived class, gets the length in bytes of the stream.
View Source
public override long Length { get; }
Position
When overridden in a derived class, gets or sets the position within the current stream.
View Source
public override long Position { get; set; }
ReadTimeout
Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.
View Source
public override int ReadTimeout { get; set; }
WriteTimeout
Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.
View Source
public override int WriteTimeout { get; set; }
Fields
_baseStream
View Source
protected Stream _baseStream
_readTimeout
View Source
protected int _readTimeout
Methods
Read(byte[], int, int)
implement a read timeout which does not cause the connection to go into an unknown state. Specifically NetworkStream timeouts cause disconnection, we don't want the protocol/device objects to have to know about or handle this. Disconnecting and Reconnecting the connection on timeout can be extremely slow instead, implement our own timeout mechanism.
View Source
public override int Read(byte[] buffer, int offset, int count)
Returns
System.Int32
Parameters
| Type | Name |
|---|---|
System.Byte[] | buffer |
System.Int32 | offset |
System.Int32 | count |
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.
View Source
public override void Write(byte[] buffer, int offset, int count)
Parameters
| Type | Name | Description |
|---|---|---|
System.Byte[] | buffer | An array of bytes. This method copies <code class="paramref">count</code> bytes from <code class="paramref">buffer</code> to the current stream. |
System.Int32 | offset | The zero-based byte offset in <code class="paramref">buffer</code> at which to begin copying bytes to the current stream. |
System.Int32 | count | The number of bytes to be written to the current stream. |
Exceptions
System.ArgumentException
The sum of <code class="paramref">offset</code> and <code class="paramref">count</code> is greater than the buffer length.
System.ArgumentNullException
<code class="paramref">buffer</code> is null.
System.ArgumentOutOfRangeException
<code class="paramref">offset</code> or <code class="paramref">count</code> is negative.
System.IO.IOException
An I/O error occurred, such as the specified file cannot be found.
System.NotSupportedException
The stream does not support writing.
System.ObjectDisposedException
System.IO.Stream.Write(System.Byte%5b%5d%2cSystem.Int32%2cSystem.Int32) was called after the stream was closed.
Flush()
Clear the read and write streams
View Source
public override void Flush()
Seek(long, SeekOrigin)
When overridden in a derived class, sets the position within the current stream.
View Source
public override long Seek(long offset, SeekOrigin origin)
Returns
System.Int64: The new position within the current stream.
Parameters
| Type | Name | Description |
|---|---|---|
System.Int64 | offset | A byte offset relative to the <code class="paramref">origin</code> parameter. |
System.IO.SeekOrigin | origin | A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position. |
Exceptions
System.IO.IOException
An I/O error occurs.
System.NotSupportedException
The stream does not support seeking, such as if the stream is constructed from a pipe or console output.
System.ObjectDisposedException
Methods were called after the stream was closed.
SetLength(long)
When overridden in a derived class, sets the length of the current stream.
View Source
public override void SetLength(long value)
Parameters
| Type | Name | Description |
|---|---|---|
System.Int64 | value | The desired length of the current stream in bytes. |
Exceptions
System.IO.IOException
An I/O error occurs.
System.NotSupportedException
The stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.
System.ObjectDisposedException
Methods were called after the stream was closed.
Dispose(bool)
Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed resources.
View Source
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
System.Boolean | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Implements
System.IAsyncDisposableSystem.IDisposable