[]
        
(Showing Draft Content)

GrapeCity.Documents.DX.DataStream

Class DataStream

Namespace
GrapeCity.Documents.DX
Assembly
GcDocs.DX.Windows.dll

Provides a stream interface to a buffer located in unmanaged memory.

public class DataStream : Stream, IDisposable
Inheritance
object
System.MarshalByRefObject
System.IO.Stream
DataStream
Implements
System.IDisposable
Inherited Members
System.IO.Stream.Null
System.IO.Stream.CopyToAsync(System.IO.Stream)
System.IO.Stream.CopyToAsync(System.IO.Stream, int)
System.IO.Stream.CopyToAsync(System.IO.Stream, int, System.Threading.CancellationToken)
System.IO.Stream.CopyTo(System.IO.Stream)
System.IO.Stream.CopyTo(System.IO.Stream, int)
System.IO.Stream.Close()
System.IO.Stream.Dispose()
System.IO.Stream.FlushAsync()
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
System.IO.Stream.CreateWaitHandle()
System.IO.Stream.BeginRead(byte[], int, int, System.AsyncCallback, object)
System.IO.Stream.EndRead(System.IAsyncResult)
System.IO.Stream.ReadAsync(byte[], int, int)
System.IO.Stream.ReadAsync(byte[], int, int, System.Threading.CancellationToken)
System.IO.Stream.BeginWrite(byte[], int, int, System.AsyncCallback, object)
System.IO.Stream.EndWrite(System.IAsyncResult)
System.IO.Stream.WriteAsync(byte[], int, int)
System.IO.Stream.WriteAsync(byte[], int, int, System.Threading.CancellationToken)
System.IO.Stream.WriteByte(byte)
System.IO.Stream.Synchronized(System.IO.Stream)
System.IO.Stream.ObjectInvariant()
System.IO.Stream.CanTimeout
System.IO.Stream.ReadTimeout
System.IO.Stream.WriteTimeout
System.MarshalByRefObject.GetLifetimeService()
System.MarshalByRefObject.InitializeLifetimeService()
System.MarshalByRefObject.MemberwiseClone(bool)
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()

Constructors

DataStream(DataPointer)

Initializes a new instance of the DataStream class.

public DataStream(DataPointer dataPointer)

Parameters

dataPointer DataPointer

The data pointer.

DataStream(Blob)

Initializes a new instance of the DataStream class from a Blob buffer.

public DataStream(Blob buffer)

Parameters

buffer Blob

The buffer.

DataStream(int, bool, bool)

Initializes a new instance of the DataStream class, and allocates a new buffer to use as a backing store.

public DataStream(int sizeInBytes, bool canRead, bool canWrite)

Parameters

sizeInBytes int

The size of the buffer to be allocated, in bytes.

canRead bool

true if reading from the buffer should be allowed; otherwise, false.

canWrite bool

true if writing to the buffer should be allowed; otherwise, false.

DataStream(IntPtr, long, bool, bool)

Initializes a new instance of the DataStream class, using an unmanaged buffer as a backing store.

public DataStream(IntPtr userBuffer, long sizeInBytes, bool canRead, bool canWrite)

Parameters

userBuffer System.IntPtr

A pointer to the buffer to be used as a backing store.

sizeInBytes long

The size of the buffer provided, in bytes.

canRead bool

true if reading from the buffer should be allowed; otherwise, false.

canWrite bool

true if writing to the buffer should be allowed; otherwise, false.

Properties

CanRead

Gets a value indicating whether the current stream supports reading.

public override bool CanRead { get; }

Property Value

bool

true if the stream supports reading; otherwise, false.

CanSeek

Gets a value indicating whether the current stream supports seeking.

public override bool CanSeek { get; }

Property Value

bool

Always true.

CanWrite

Gets a value indicating whether the current stream supports writing.

public override bool CanWrite { get; }

Property Value

bool

true if the stream supports writing; otherwise, false.

DataPointer

Gets the internal pointer to the current stream's backing store.

public IntPtr DataPointer { get; }

Property Value

System.IntPtr

An IntPtr to the buffer being used as a backing store.

Length

Gets the length in bytes of the stream.

public override long Length { get; }

Property Value

long

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

Position

Gets or sets the position within the current stream.

public override long Position { get; set; }

Property Value

long

The current position within the stream.

See Also
System.IO.Stream

PositionPointer

Gets the position pointer.

public IntPtr PositionPointer { get; }

Property Value

System.IntPtr

The position pointer.

RemainingLength

Gets the length of the remaining.

public long RemainingLength { get; }

Property Value

long

The length of the remaining.

Methods

Create<T>(T[], bool, bool, int, bool)

Initializes a new instance of the DataStream class, using a managed buffer as a backing store.

public static DataStream Create<T>(T[] userBuffer, bool canRead, bool canWrite, int index = 0, bool pinBuffer = true) where T : struct

Parameters

userBuffer T[]

A managed array to be used as a backing store.

canRead bool

true if reading from the buffer should be allowed; otherwise, false.

canWrite bool

true if writing to the buffer should be allowed; otherwise, false.

index int

Index inside the buffer in terms of element count (not size in bytes).

pinBuffer bool

True to keep the managed buffer and pin it, false will allocate unmanaged memory and make a copy of it. Default is true.

Returns

DataStream

Type Parameters

T

Dispose(bool)

Releases unmanaged and - optionally - managed resources

protected override void Dispose(bool disposing)

Parameters

disposing bool

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

Flush()

Not supported.

public override void Flush()

Exceptions

System.NotSupportedException

Always thrown.

Read(byte[], int, int)

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

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

Parameters

buffer byte[]

An array of values to be read from the stream.

offset int

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

count int

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

Returns

int

The number of bytes read from the stream.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support reading.

Read(IntPtr, int, int)

Reads a sequence of bytes from the current stream and advances the current position within this stream by the number of bytes written.

public void Read(IntPtr buffer, int offset, int count)

Parameters

buffer System.IntPtr

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

offset int

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

count int

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

Read<T>()

Reads a single value from the current stream and advances the current position within this stream by the number of bytes read.

public T Read<T>() where T : struct

Returns

T

The value that was read.

Type Parameters

T

The type of the value to be read from the stream.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support reading.

ReadBoolean()

Reads a bool.

public bool ReadBoolean()

Returns

bool

an bool from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadByte()

public override int ReadByte()

Returns

int

ReadColorF()

Reads a ColorF.

public ColorF ReadColorF()

Returns

ColorF

an Color4 from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadFloat()

Reads a float.

public float ReadFloat()

Returns

float

a float from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadInt()

Reads a int.

public int ReadInt()

Returns

int

an int from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadMatrix4x4()

Reads a Matrix.

public Matrix4x4 ReadMatrix4x4()

Returns

Matrix4x4

a Matrix from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadRange<T>(T[], int, int)

Reads a sequence of elements from the current stream into a target buffer and advances the position within the stream by the number of bytes read.

public int ReadRange<T>(T[] buffer, int offset, int count) where T : struct

Parameters

buffer T[]

An array of values to be read from the stream.

offset int

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

count int

The number of values to be read from the current stream.

Returns

int

The number of bytes read from the stream.

Type Parameters

T

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support reading.

ReadRange<T>(int)

Reads an array of values from the current stream, and advances the current position within this stream by the number of bytes written.

public T[] ReadRange<T>(int count) where T : struct

Parameters

count int

Returns

T[]

An array of values that was read from the current stream.

Type Parameters

T

The type of the values to be read from the stream.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadShort()

Reads a short.

public short ReadShort()

Returns

short

an short from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadVector2()

Reads a Vector2.

public Vector2 ReadVector2()

Returns

Vector2

an Vector2 from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadVector3()

Reads a Vector3.

public Vector3 ReadVector3()

Returns

Vector3

an Vector3 from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

ReadVector4()

Reads a Vector4.

public Vector4 ReadVector4()

Returns

Vector4

an Vector4 from the stream

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Seek(long, SeekOrigin)

Sets the position within the current stream.

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long
origin System.IO.SeekOrigin

Returns

long

Exceptions

System.InvalidOperationException

Attempted to seek outside of the bounds of the stream.

SetLength(long)

Not supported.

public override void SetLength(long value)

Parameters

value long

Always ignored.

Exceptions

System.NotSupportedException

Always thrown.

Write(ColorF)

Writes the specified value.

public void Write(ColorF value)

Parameters

value ColorF

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(Matrix4x4)

Writes the specified value.

public void Write(Matrix4x4 value)

Parameters

value Matrix4x4

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(Vector2)

Writes the specified value.

public void Write(Vector2 value)

Parameters

value Vector2

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(Vector3)

Writes the specified value.

public void Write(Vector3 value)

Parameters

value Vector3

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(Vector4)

Writes the specified value.

public void Write(Vector4 value)

Parameters

value Vector4

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(bool)

Writes the specified value.

public void Write(bool value)

Parameters

value bool

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(byte[], int, int)

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

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

Parameters

buffer byte[]

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

offset int

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

count int

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

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support writing.

Write(short)

Writes the specified value.

public void Write(short value)

Parameters

value short

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(int)

Writes the specified value.

public void Write(int value)

Parameters

value int

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write(IntPtr, 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.

public void Write(IntPtr buffer, int offset, int count)

Parameters

buffer System.IntPtr

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

offset int

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

count int

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

Write(float)

Writes the specified value.

public void Write(float value)

Parameters

value float

The value.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Write<T>(T)

Writes a single value to the stream, and advances the current position within this stream by the number of bytes written.

public void Write<T>(T value) where T : struct

Parameters

value T

The value to write to the stream.

Type Parameters

T

The type of the value to be written to the stream.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

The stream does not support writing.

WriteRange(IntPtr, long)

Writes a range of bytes to the current stream, and advances the current position within this stream by the number of bytes written.

public void WriteRange(IntPtr source, long count)

Parameters

source System.IntPtr

A pointer to the location to start copying from.

count long

The number of bytes to copy from source to the current stream.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support writing.

WriteRange<T>(T[], int, int)

Writes an array of values to the current stream, and advances the current position within this stream by the number of bytes written.

public void WriteRange<T>(T[] data, int offset, int count) where T : struct

Parameters

data T[]

An array of values to be written to the stream.

offset int

The zero-based offset in data at which to begin copying values to the current stream.

count int

The number of values to be written to the current stream. If this is zero, all of the contents data will be written.

Type Parameters

T

The type of the values to be written to the stream.

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support writing.

WriteRange<T>(T[])

Writes an array of values to the current stream, and advances the current position within this stream by the number of bytes written.

public void WriteRange<T>(T[] data) where T : struct

Parameters

data T[]

An array of values to be written to the current stream.

Type Parameters

T

Remarks

In order to provide faster read/write, this operation doesn't check stream bound. A client must carefully not read/write above the size of this datastream.

Exceptions

System.NotSupportedException

This stream does not support writing.

Operators

implicit operator DataPointer(DataStream)

Performs an explicit conversion from DataStream to DataPointer.

public static implicit operator DataPointer(DataStream from)

Parameters

from DataStream

The from value.

Returns

DataPointer

The result of the conversion.