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
Inherited Members
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 SourceMemoryTributary()
Initializes a new instance of the MemoryTributary class.
Declaration
public MemoryTributary()
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. |
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 SourceBlock
The block of memory currently addressed by Position
Declaration
protected byte[] Block { get; }
Property Value
Type | Description |
---|---|
System.Byte[] |
BlockId
The id of the block currently addressed by Position
Declaration
protected long BlockId { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
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 |
CanRead
Gets a value indicating whether the current stream supports reading.
Declaration
public override bool CanRead { get; }
Property Value
Type | Description |
---|---|
System.Boolean | Always |
Overrides
CanSeek
Gets a value indicating whether the current stream supports seeking.
Declaration
public override bool CanSeek { get; }
Property Value
Type | Description |
---|---|
System.Boolean | Always |
Overrides
CanWrite
Gets a value indicating whether the current stream supports writing.
Declaration
public override bool CanWrite { get; }
Property Value
Type | Description |
---|---|
System.Boolean | Always |
Overrides
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
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | Methods were called after the stream was closed. |
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.ObjectDisposedException | Methods were called after the stream was closed. |
Methods
| Improve this Doc View SourceCreateReader()
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
| Improve this Doc View SourceDispose(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
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 |
Flush()
Does nothing
Declaration
public override void Flush()
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.ArgumentNullException |
|
System.ArgumentOutOfRangeException |
|
System.ObjectDisposedException | Methods were called after the stream was closed. |
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
Exceptions
Type | Condition |
---|---|
System.ObjectDisposedException | Methods were called after the stream was closed. |
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 |
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.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
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. |
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 |
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.ObjectDisposedException | Write(Byte[], Int32, Int32) was called after the stream was closed. |
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.ObjectDisposedException | Methods were called after the stream was closed. |
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 |