ClassExpandableMemoryStream
A high-performance memory stream implementation optimized for large data. Uses segmented buffers to reduce large contiguous memory allocations.
Definition
Namespace:Telerik.Documents.Core.Data
Assembly:Telerik.Windows.Documents.Core.dll
Syntax:
public class ExpandableMemoryStream : Stream, IDisposable, IAsyncDisposable
Inheritance: objectMarshalByRefObjectStreamExpandableMemoryStream
Implements:
Inherited Members
Constructors
ExpandableMemoryStream(byte[], int)
Initializes a new instance of ExpandableMemoryStream with the specified initial data.
Declaration
public ExpandableMemoryStream(byte[] data, int bufferSize = 1000000)
Parameters
data
byte[]
The initial content to copy into the stream.
bufferSize
Optional custom buffer size in bytes for each segment. Default is 1 MB.
Exceptions
Thrown when data is null.
Thrown when bufferSize is less than or equal to zero.
ExpandableMemoryStream(int)
Initializes a new instance of ExpandableMemoryStream.
Declaration
public ExpandableMemoryStream(int bufferSize = 1000000)
Parameters
bufferSize
Optional custom buffer size in bytes for each segment. Default is 1 MB.
Exceptions
Thrown when bufferSize is less than or equal to zero.
Properties
CanRead
Gets a value indicating whether the current stream supports reading.
Declaration
public override bool CanRead { get; }
Property Value
true if the stream supports reading and is not disposed; otherwise, false.
Overrides
CanSeek
Gets a value indicating whether the current stream supports seeking.
Declaration
public override bool CanSeek { get; }
Property Value
true if the stream supports seeking and is not disposed; otherwise, false.
Overrides
CanWrite
Gets a value indicating whether the current stream supports writing.
Declaration
public override bool CanWrite { get; }
Property Value
true if the stream supports writing and is not disposed; otherwise, false.
Overrides
Length
Gets the length in bytes of the stream.
Declaration
public override long Length { get; }
Property Value
The number of bytes written to the stream.
Overrides
Position
Gets or sets the current position within the stream.
Declaration
public override long Position { get; set; }
Property Value
The current position within the stream.
Exceptions
The stream has been disposed.
The position is set to a value less than zero or greater than Length.
Overrides
Methods
Dispose(bool)
Releases the unmanaged resources used by the ExpandableMemoryStream and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
disposing
true to release both managed and unmanaged resources; false to release only unmanaged resources.
Overrides
Remarks
When disposing is true, the internal buffers list is cleared and the stream becomes unusable.
Flush()
Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Declaration
public override void Flush()
Exceptions
The stream has been disposed.
Overrides
Remarks
This implementation stores data entirely in memory; therefore, this method is a no-op.
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.
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
buffer
byte[]
The buffer to write the data into.
offset
The zero-based byte offset in buffer at which to begin storing the data read from the stream.
count
The maximum number of bytes to read.
Returns
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 if the end of the stream is reached.
Exceptions
The stream has been disposed.
buffer is null.
offset or count is negative, or the sum of offset and count is greater than the buffer length.
Overrides
Seek(long, SeekOrigin)
Sets the position within the current stream.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
offset
A byte offset relative to the origin parameter.
origin
A value of type SeekOrigin indicating the reference point used to obtain the new position.
Returns
The new position within the stream.
Exceptions
The stream has been disposed.
origin is not a valid SeekOrigin value.
Seeking results in a negative position.
Overrides
SetLength(long)
Sets the length of the current stream.
Declaration
public override void SetLength(long value)
Parameters
value
The desired length of the current stream in bytes.
Exceptions
The stream has been disposed.
value is negative.
Overrides
Remarks
If the new length is shorter than the current length, the stream is truncated and data beyond the new length is discarded. If the new length is longer, the stream is extended and the added region is initialized to zeros.
Write(byte[], int, int)
Writes a sequence of bytes to the current stream and advances the position within the stream by the number of bytes written.
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
buffer
byte[]
The buffer that contains the data to write to the stream.
offset
The zero-based byte offset in buffer at which to begin copying bytes to the stream.
count
The number of bytes to write to the stream.
Exceptions
The stream has been disposed.
buffer is null.
offset or count is negative, or the sum of offset and count is greater than the buffer length.
Overrides
Remarks
The stream automatically grows to accommodate the written data. Data may span multiple underlying segments.
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
value
The byte to write to the stream.
Exceptions
The stream has been disposed.
Overrides