Show / Hide Table of Contents

Class MemoryTributary

MemoryTributary is a re-implementation of MemoryStream that uses a dynamic list of byte arrays as a backing store, instead of a single byte array, the allocation of which will fail for relatively small streams as it requires contiguous memory.

Inheritance
System.Object
System.IO.Stream
MemoryTributary
Inherited Members
System.IO.Stream.Null
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.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.Dispose()
System.IO.Stream.FlushAsync()
System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
System.IO.Stream.CanTimeout
System.IO.Stream.ReadTimeout
System.IO.Stream.WriteTimeout
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Innovator.Client
Assembly: Innovator.Client.dll
Syntax
public class MemoryTributary : Stream, IDisposable, IXmlStream
Remarks

Adapted from Code Project: A replacement for MemoryStream

Constructors

| Improve this Doc View Source

MemoryTributary()

Initializes a new instance of the MemoryTributary class.

Declaration
public MemoryTributary()
| Improve this Doc View Source

MemoryTributary(Byte[])

Initializes a new instance of the MemoryTributary class.

Declaration
public MemoryTributary(byte[] source)
Parameters
Type Name Description
System.Byte[] source

The source data.

| Improve this Doc View Source

MemoryTributary(Int32)

Initializes a new instance of the MemoryTributary class.

Declaration
public MemoryTributary(int length)
Parameters
Type Name Description
System.Int32 length

The length.

Remarks

length is largely ignored because capacity has no meaning unless we implement an artifical limit

Properties

| Improve this Doc View Source

Block

The block of memory currently addressed by Position

Declaration
protected byte[] Block { get; }
Property Value
Type Description
System.Byte[]
| Improve this Doc View Source

BlockId

The id of the block currently addressed by Position

Declaration
protected long BlockId { get; }
Property Value
Type Description
System.Int64
| Improve this Doc View Source

BlockOffset

The offset of the byte currently addressed by Position, into the block that contains it

Declaration
protected long BlockOffset { get; }
Property Value
Type Description
System.Int64
| 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

Always true as the stream supports reading.

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

Always true as the stream supports seeking.

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

Always true as the stream supports writing.

Overrides
System.IO.Stream.CanWrite
| Improve this Doc View Source

Length

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.ObjectDisposedException

Methods were called after the stream was closed.

| 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.ObjectDisposedException

Methods were called after the stream was closed.

Methods

| Improve this Doc View Source

CreateReader()

Creates an System.Xml.XmlReader for reading XML from the stream

Declaration
public XmlReader CreateReader()
Returns
Type Description
System.Xml.XmlReader

An System.Xml.XmlReader for reading XML

Implements
IXmlStream.CreateReader()
| 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

EnsureCapacity(Int64)

Guarantees that the underlying memory has at least the specified number of bytes of capacity

Declaration
protected void EnsureCapacity(long intendedLength)
Parameters
Type Name Description
System.Int64 intendedLength

Intended length of the data

| Improve this Doc View Source

Flush()

Does nothing

Declaration
public override void Flush()
Overrides
System.IO.Stream.Flush()
| 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.ArgumentNullException

buffer is null.

System.ArgumentOutOfRangeException

offset or count is negative.

System.ObjectDisposedException

Methods were called after the stream was closed.

| 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 System.Int32, or -1 if at the end of the stream.

Overrides
System.IO.Stream.ReadByte()
Exceptions
Type Condition
System.ObjectDisposedException

Methods were called after the stream was closed.

| Improve this Doc View Source

ReadFrom(Stream, Int64)

Reads length bytes from source into the this instance at the current position.

Declaration
public void ReadFrom(Stream source, long length)
Parameters
Type Name Description
System.IO.Stream source

The stream containing the data to copy

System.Int64 length

The number of bytes to copy

| 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.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)
Remarks

value is largely ignored because capacity has no meaning unless we implement an artifical limit

Exceptions
Type Condition
System.ObjectDisposedException

Methods were called after the stream was closed.

| Improve this Doc View Source

ToArray()

Returns the entire content of the stream as a byte array. This is not safe because the call to new byte[] may fail if the stream is large enough. Where possible use methods which operate on streams directly instead.

Declaration
public byte[] ToArray()
Returns
Type Description
System.Byte[]

A byte[] containing the current data in the stream

| 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.ObjectDisposedException

Write(Byte[], Int32, Int32) was called after the stream was closed.

| 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.ObjectDisposedException

Methods were called after the stream was closed.

| Improve this Doc View Source

WriteTo(Stream)

Writes the entire stream into destination, regardless of Position, which remains unchanged.

Declaration
public void WriteTo(Stream destination)
Parameters
Type Name Description
System.IO.Stream destination

The stream to write the content of this stream to

Extension Methods

Extensions.AsString(Stream)
Extensions.AsBytes(Stream)
  • Improve this Doc
  • View Source
Back to top Copyright © 2015-2017 Microsoft
Generated by DocFX