Class DataStream
Base implementation of a data stream.
Inheritance
Implements
Inherited Members
Namespace: Kephas.Data.IO.DataStreams
Assembly: Kephas.Data.IO.dll
Syntax
public class DataStream : Stream, IDisposable
Constructors
| Improve this Doc View SourceDataStream(Stream, String, String, Encoding, Boolean)
Initializes a new instance of the DataStream class.
Declaration
public DataStream(Stream rawStream, string name = null, string mediaType = null, Encoding encoding = null, bool ownsStream = false)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | rawStream | The raw stream of data. |
| System.String | name | The name (optional). |
| System.String | mediaType | Type of the media (optional). |
| System.Text.Encoding | encoding | The encoding (optional). |
| System.Boolean | ownsStream | If set to true, upon disposing the raw stream will also be disposed (optional). |
Properties
| Improve this Doc View SourceCanRead
Gets a value indicating whether the current stream supports reading.
Declaration
public override bool CanRead { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | true if the stream supports reading; otherwise, false. |
Overrides
CanSeek
Gets a value indicating whether the current stream supports seeking.
Declaration
public override bool CanSeek { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | 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
| Type | Description |
|---|---|
| System.Boolean | A value that determines whether the current stream can time out. |
Overrides
CanWrite
Gets a value indicating whether the current stream supports writing.
Declaration
public override bool CanWrite { get; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | true if the stream supports writing; otherwise, false. |
Overrides
Encoding
Gets the encoding.
Declaration
public Encoding Encoding { get; }
Property Value
| Type | Description |
|---|---|
| System.Text.Encoding | The encoding. |
Guid
Gets the unique identifier.
Declaration
public Guid Guid { get; }
Property Value
| Type | Description |
|---|---|
| System.Guid | The unique identifier. |
Length
When overridden in a derived class, gets the length in bytes of the stream.
Declaration
public override long Length { get; }
Property Value
| Type | Description |
|---|---|
| System.Int64 | A long value representing the length of the stream in bytes. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | A class derived from Stream does not support seeking. |
| System.ObjectDisposedException | Methods were called after the stream was closed. |
MediaType
Gets the media type of the underlying stream.
Declaration
public string MediaType { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The media type. |
Name
Gets the name of the data stream.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| System.String | The name of the data stream. |
Remarks
Typically, this is the file name.
Position
Gets or sets the position within the current stream.
Declaration
public override long Position { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int64 | The current position within the stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.IO.IOException | An I/O error occurs. |
| System.NotSupportedException | The stream does not support seeking. |
| System.ObjectDisposedException | Methods were called after the stream was closed. |
RawStream
Gets the raw stream of dtaa.
Declaration
protected Stream RawStream { get; }
Property Value
| Type | Description |
|---|---|
| System.IO.Stream | The raw stream. |
ReadTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out.
Declaration
public override int ReadTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | A value, in miliseconds, that determines how long the stream will attempt to read before timing out. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.InvalidOperationException | The System.IO.Stream.ReadTimeout method always throws an System.InvalidOperationException. |
WriteTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out.
Declaration
public override int WriteTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 | A value, in miliseconds, that determines how long the stream will attempt to write before timing out. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.InvalidOperationException | The System.IO.Stream.WriteTimeout method always throws an System.InvalidOperationException. |
Methods
| Improve this Doc View SourceCopyToAsync(Stream, Int32, CancellationToken)
Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.
Declaration
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | destination | The stream to which the contents of the current stream will be copied. |
| System.Int32 | bufferSize | The size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920. |
| System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A task that represents the asynchronous copy operation. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
| System.ObjectDisposedException | Either the current stream or the destination stream is disposed. |
| System.NotSupportedException | The current stream does not support reading, or the destination stream does not support writing. |
Dispose(Boolean)
Releases the unmanaged resources used by the System.IO.Stream and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | disposing |
|
Overrides
Flush()
Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Declaration
public override void Flush()
Overrides
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
| Type | Name | Description |
|---|---|---|
| System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A task that represents the asynchronous flush operation. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ObjectDisposedException | The stream has been disposed. |
GetHashCode()
Serves as the default hash function.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 | A hash code for the current object. |
Overrides
Read(Byte[], Int32, Int32)
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
| Type | Name | Description |
|---|---|---|
| System.Byte[] | buffer | An array of bytes. When this method returns, the buffer contains the specified byte array with the values between |
| System.Int32 | offset | The zero-based byte offset in |
| System.Int32 | count | The maximum number of bytes to be read from the current stream. |
Returns
| Type | Description |
|---|---|
| System.Int32 | 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 the end of the stream has been reached. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | The sum of |
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
| System.IO.IOException | An I/O error occurs. |
| System.NotSupportedException | The stream does not support reading. |
| System.ObjectDisposedException | Methods were called after the stream was closed. |
ReadAsync(Byte[], Int32, Int32, 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
| Type | Name | Description |
|---|---|---|
| System.Byte[] | buffer | The buffer to write the data into. |
| System.Int32 | offset | The byte offset in |
| System.Int32 | count | The maximum number of bytes to read. |
| System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<System.Int32> | A task that represents the asynchronous read operation. The value of the |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
| System.ArgumentException | The sum of |
| System.NotSupportedException | The stream does not support reading. |
| System.ObjectDisposedException | The stream has been disposed. |
| System.InvalidOperationException | The stream is currently in use by a previous read operation. |
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
| Type | Description |
|---|---|
| System.Int32 | The unsigned byte cast to an Int32, or -1 if at the end of the stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.NotSupportedException | The stream does not support reading. |
| System.ObjectDisposedException | Methods were called after the stream was closed. |
Seek(Int64, SeekOrigin)
Sets the position within the current stream.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | offset | A byte offset relative to the |
| System.IO.SeekOrigin | origin | A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position. |
Returns
| Type | Description |
|---|---|
| System.Int64 | The new position within the current stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| 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(Int64)
Sets the length of the current stream.
Declaration
public override void SetLength(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int64 | value | The desired length of the current stream in bytes. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| 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. |
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| System.String | A System.String that represents this instance. |
Overrides
Write(Byte[], Int32, Int32)
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
| Type | Name | Description |
|---|---|---|
| System.Byte[] | buffer | An array of bytes. This method copies |
| System.Int32 | offset | The zero-based byte offset in |
| System.Int32 | count | The number of bytes to be written to the current stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | The sum of |
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
| System.IO.IOException | An I/O error occured, such as the specified file cannot be found. |
| System.NotSupportedException | The stream does not support writing. |
| System.ObjectDisposedException | System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32) was called after the stream was closed. |
WriteAsync(Byte[], Int32, Int32, 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
| Type | Name | Description |
|---|---|---|
| System.Byte[] | buffer | The buffer to write data from. |
| System.Int32 | offset | The zero-based byte offset in |
| System.Int32 | count | The maximum number of bytes to write. |
| System.Threading.CancellationToken | cancellationToken | The token to monitor for cancellation requests. The default value is System.Threading.CancellationToken.None. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | A task that represents the asynchronous write operation. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentNullException |
|
| System.ArgumentOutOfRangeException |
|
| System.ArgumentException | The sum of |
| System.NotSupportedException | The stream does not support writing. |
| System.ObjectDisposedException | The stream has been disposed. |
| System.InvalidOperationException | The stream is currently in use by a previous write operation. |
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
| Type | Name | Description |
|---|---|---|
| System.Byte | value | The byte to write to the stream. |
Overrides
Exceptions
| Type | Condition |
|---|---|
| System.IO.IOException | An I/O error occurs. |
| System.NotSupportedException | The stream does not support writing, or the stream is already closed. |
| System.ObjectDisposedException | Methods were called after the stream was closed. |