Table of Contents

Class MultiBufferMemoryStream

Namespace
Microsoft.WindowsAzure.Storage.Core
Assembly
Microsoft.WindowsAzure.Storage.dll

Creates a multi-buffer stream whose backing store is memory.

public class MultiBufferMemoryStream : Stream, IDisposable, IAsyncDisposable
Inheritance
MultiBufferMemoryStream
Implements
Inherited Members

Constructors

MultiBufferMemoryStream(IBufferManager, int)

Initializes a new instance of the MultiBufferMemoryStream class with the specified buffer manager.

public MultiBufferMemoryStream(IBufferManager bufferManager, int bufferSize = 65536)

Parameters

bufferManager IBufferManager

The IBufferManager to use to acquire and return buffers for the stream. May be null.

bufferSize int

The buffer size to use for each block. The default size is 64 KB. Note that this parameter is disregarded when an IBufferManager is specified.

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

true if the stream supports seeking; otherwise, false.

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.

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.

Methods

BeginFastCopyTo(Stream, DateTime?, AsyncCallback, object)

Begins an asynchronous fast-copy operation.

public IAsyncResult BeginFastCopyTo(Stream destination, DateTime? expiryTime, AsyncCallback callback, object state)

Parameters

destination Stream

The stream to which the contents of the current stream will be copied.

expiryTime DateTime?

DateTime indicating the expiry time.

callback AsyncCallback

An optional asynchronous callback, to be called when the copy is complete.

state object

A user-provided object that distinguishes this particular asynchronous copy request from other requests.

Returns

IAsyncResult

An IAsyncResult that represents the asynchronous copy, which could still be pending.

BeginRead(byte[], int, int, AsyncCallback, object)

Begins an asynchronous read operation.

public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)

Parameters

buffer byte[]

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.

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.

callback AsyncCallback

An optional asynchronous callback, to be called when the read is complete.

state object

A user-provided object that distinguishes this particular asynchronous read request from other requests.

Returns

IAsyncResult

An IAsyncResult that represents the asynchronous read, which could still be pending.

BeginWrite(byte[], int, int, AsyncCallback, object)

Begins an asynchronous write operation.

public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)

Parameters

buffer byte[]

The buffer to write data from.

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

callback AsyncCallback

An optional asynchronous callback, to be called when the write is complete.

state object

A user-provided object that distinguishes this particular asynchronous write request from other requests.

Returns

IAsyncResult

An IAsyncResult that represents the asynchronous write, which could still be pending.

ComputeMD5Hash()

Computes the hash value for this stream.

public string ComputeMD5Hash()

Returns

string

String representation of the computed hash value.

Dispose(bool)

Releases all resources used by the MultiBufferMemoryStream.

protected override void Dispose(bool disposing)

Parameters

disposing bool

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

EndFastCopyTo(IAsyncResult)

Ends an asynchronous copy operation.

public void EndFastCopyTo(IAsyncResult asyncResult)

Parameters

asyncResult IAsyncResult

The reference to the pending asynchronous request to finish.

EndRead(IAsyncResult)

Waits for the pending asynchronous read to complete.

public override int EndRead(IAsyncResult asyncResult)

Parameters

asyncResult IAsyncResult

The reference to the pending asynchronous request to finish.

Returns

int

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 has been reached.

EndWrite(IAsyncResult)

Ends an asynchronous write operation.

public override void EndWrite(IAsyncResult asyncResult)

Parameters

asyncResult IAsyncResult

The reference to the pending asynchronous request to finish.

FastCopyTo(Stream, DateTime?)

Reads the bytes from the current stream and writes them to another stream. This method writes directly to the destination stream, rather than copying the data into a temporary buffer.

public void FastCopyTo(Stream destination, DateTime? expiryTime)

Parameters

destination Stream

The stream to which the contents of the current stream will be copied.

expiryTime DateTime?

A DateTime indicating the expiry time.

Flush()

Does not perform any operation, as the stream is an in-memory stream.

public override void Flush()

Read(byte[], int, int)

Reads a block of bytes from the current stream and writes the data to a buffer.

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

Parameters

buffer byte[]

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.

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.

Returns

int

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 has been reached.

Seek(long, SeekOrigin)

Sets the position within the current stream.

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long

A byte offset relative to the origin parameter.

origin SeekOrigin

A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.

Returns

long

The new position within the current stream.

Exceptions

ArgumentException

Thrown if offset is invalid for SeekOrigin.

SetLength(long)

Sets the length of the current stream.

public override void SetLength(long value)

Parameters

value long

The desired length of the current stream in bytes.

Exceptions

ArgumentOutOfRangeException

If the value is negative.

Write(byte[], int, int)

Writes a block of bytes to the current stream using data read from a buffer.

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

Parameters

buffer byte[]

The buffer to write data from.

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