Show / Hide Table of Contents

Class DataStream

Base implementation of a data stream.

Inheritance
System.Object
System.MarshalByRefObject
System.IO.Stream
DataStream
Implements
System.IDisposable
Inherited Members
System.IO.Stream.Null
System.IO.Stream.BeginRead(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.BeginWrite(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
System.IO.Stream.Close()
System.IO.Stream.CopyTo(System.IO.Stream)
System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)
System.IO.Stream.CopyToAsync(System.IO.Stream)
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32)
System.IO.Stream.CreateWaitHandle()
System.IO.Stream.Dispose()
System.IO.Stream.EndRead(System.IAsyncResult)
System.IO.Stream.EndWrite(System.IAsyncResult)
System.IO.Stream.FlushAsync()
System.IO.Stream.ObjectInvariant()
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.Synchronized(System.IO.Stream)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
System.MarshalByRefObject.GetLifetimeService()
System.MarshalByRefObject.InitializeLifetimeService()
System.MarshalByRefObject.MemberwiseClone(System.Boolean)
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Kephas.Data.IO.DataStreams
Assembly: Kephas.Data.IO.dll
Syntax
public class DataStream : Stream, IDisposable

Constructors

| Improve this Doc View Source

DataStream(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 Source

CanRead

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
System.IO.Stream.CanRead
| Improve this Doc View Source

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
System.IO.Stream.CanSeek
| Improve this Doc View Source

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
System.IO.Stream.CanTimeout
| Improve this Doc View Source

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
System.IO.Stream.CanWrite
| Improve this Doc View Source

Encoding

Gets the encoding.

Declaration
public Encoding Encoding { get; }
Property Value
Type Description
System.Text.Encoding

The encoding.

| Improve this Doc View Source

Guid

Gets the unique identifier.

Declaration
public Guid Guid { get; }
Property Value
Type Description
System.Guid

The unique identifier.

| Improve this Doc View Source

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
System.IO.Stream.Length
Exceptions
Type Condition
System.NotSupportedException

A class derived from Stream does not support seeking.

System.ObjectDisposedException

Methods were called after the stream was closed.

| Improve this Doc View Source

MediaType

Gets the media type of the underlying stream.

Declaration
public string MediaType { get; }
Property Value
Type Description
System.String

The media type.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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
System.IO.Stream.Position
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.

| Improve this Doc View Source

RawStream

Gets the raw stream of dtaa.

Declaration
protected Stream RawStream { get; }
Property Value
Type Description
System.IO.Stream

The raw stream.

| Improve this Doc View Source

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
System.IO.Stream.ReadTimeout
Exceptions
Type Condition
System.InvalidOperationException

The System.IO.Stream.ReadTimeout method always throws an System.InvalidOperationException.

| Improve this Doc View Source

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
System.IO.Stream.WriteTimeout
Exceptions
Type Condition
System.InvalidOperationException

The System.IO.Stream.WriteTimeout method always throws an System.InvalidOperationException.

Methods

| Improve this Doc View Source

CopyToAsync(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
System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
Exceptions
Type Condition
System.ArgumentNullException

destination is null.

System.ArgumentOutOfRangeException

bufferSize is negative or zero.

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.

| Improve this Doc View Source

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

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Overrides
System.IO.Stream.Dispose(System.Boolean)
| Improve this Doc View Source

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
System.IO.Stream.Flush()
| Improve this Doc View Source

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
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
Exceptions
Type Condition
System.ObjectDisposedException

The stream has been disposed.

| Improve this Doc View Source

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
System.Object.GetHashCode()
| Improve this Doc View Source

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 offset and (offset + count - 1) replaced by the bytes read from the current source.

System.Int32 offset

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

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
System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)
Exceptions
Type Condition
System.ArgumentException

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

System.ArgumentNullException

buffer is null.

System.ArgumentOutOfRangeException

offset or count is negative.

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.

| Improve this Doc View Source

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 buffer at which to begin writing data from the stream.

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 count 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 the end of the stream has been reached.

Overrides
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
Exceptions
Type Condition
System.ArgumentNullException

buffer is null.

System.ArgumentOutOfRangeException

offset or count is negative.

System.ArgumentException

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

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.

| Improve this Doc View Source

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
System.IO.Stream.ReadByte()
Exceptions
Type Condition
System.NotSupportedException

The stream does not support reading.

System.ObjectDisposedException

Methods were called after the stream was closed.

| Improve this Doc View Source

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 origin parameter.

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
System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)
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.

| Improve this Doc View Source

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
System.IO.Stream.SetLength(System.Int64)
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.

| Improve this Doc View Source

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
System.Object.ToString()
| Improve this Doc View Source

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 count bytes from buffer to the current stream.

System.Int32 offset

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

System.Int32 count

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

Overrides
System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32)
Exceptions
Type Condition
System.ArgumentException

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

System.ArgumentNullException

buffer is null.

System.ArgumentOutOfRangeException

offset or count is negative.

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.

| Improve this Doc View Source

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 buffer from which to begin copying bytes to the stream.

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
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
Exceptions
Type Condition
System.ArgumentNullException

buffer is null.

System.ArgumentOutOfRangeException

offset or count is negative.

System.ArgumentException

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

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.

| Improve this Doc View Source

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
System.IO.Stream.WriteByte(System.Byte)
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.

Implements

System.IDisposable

Extension Methods

DynamicObjectExtensions.SetPropertyValue(Object, String, Object)
DynamicObjectExtensions.TrySetPropertyValue(Object, String, Object)
DynamicObjectExtensions.GetPropertyValue(Object, String)
DynamicObjectExtensions.TryGetPropertyValue(Object, String, out Object)
DynamicObjectExtensions.GetRuntimeTypeInfo(Object)
DynamicObjectExtensions.ToDynamic(Object)
DynamicObjectExtensions.ToExpando(Object)
BehaviorValue.ToBehaviorValue<TValue>(TValue)
CollectionExtensions.AddRange<T, TItem>(T, IEnumerable<TItem>)
StreamExtensions.ReadAllBytes(Stream)
StreamExtensions.ReadAllBytesAsync(Stream, CancellationToken)
LoggingExtensions.GetLogger(Object, IContext)
TypeExtensions.GetAbstractType(Object)
TypeExtensions.GetAbstractTypeInfo(Object)
ReflectionHelper.GetTypeInfo(Object)
EntityEntryExtensions.TryGetAttachedEntityEntry(Object)
  • Improve this Doc
  • View Source
Back to top Generated by DocFX