Skip to main content
Version: v2.0.0

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​
Declaration
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​
Declaration
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​
Declaration
public abstract int DataAvailable { get; }

CanRead​

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

View Source​
Declaration
public override bool CanRead { get; }

CanSeek​

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

View Source​
Declaration
public override bool CanSeek { get; }

CanWrite​

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

View Source​
Declaration
public override bool CanWrite { get; }

Length​

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

View Source​
Declaration
public override long Length { get; }

Position​

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

View Source​
Declaration
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​
Declaration
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​
Declaration
public override int WriteTimeout { get; set; }

Fields​

_baseStream​

View Source​
Declaration
protected Stream _baseStream

_readTimeout​

View Source​
Declaration
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​
Declaration
public override int Read(byte[] buffer, int offset, int count)
Returns​

System.Int32

Parameters​
TypeName
System.Byte[]buffer
System.Int32offset
System.Int32count

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​
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters​
TypeNameDescription
System.Byte[]bufferAn array of bytes. This method copies <code class="paramref">count</code> bytes from <code class="paramref">buffer</code> to the current stream.
System.Int32offsetThe zero-based byte offset in <code class="paramref">buffer</code> at which to begin copying bytes to the current stream.
System.Int32countThe 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​
Declaration
public override void Flush()

Seek(long, SeekOrigin)​

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

View Source​
Declaration
public override long Seek(long offset, SeekOrigin origin)
Returns​

System.Int64: The new position within the current stream.

Parameters​
TypeNameDescription
System.Int64offsetA byte offset relative to the <code class="paramref">origin</code> parameter.
System.IO.SeekOriginoriginA 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​
Declaration
public override void SetLength(long value)
Parameters​
TypeNameDescription
System.Int64valueThe 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​
Declaration
protected override void Dispose(bool disposing)
Parameters​
TypeNameDescription
System.Booleandisposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Implements​

  • System.IAsyncDisposable
  • System.IDisposable