Class PublicBufferMemoryStream
- Namespace
- Alis.Core.Network
- Assembly
- Alis.dll
This memory stream is not instance thread safe (not to be confused with the BufferPool which is instance thread safe)
public class PublicBufferMemoryStream : MemoryStream, IAsyncDisposable, IDisposable
Inheritance
Implements
Inherited Members
Constructors
PublicBufferMemoryStream(byte[], BufferPool)
Initializes a new instance of the Alis.Core.Network.PublicBufferMemoryStream class
public PublicBufferMemoryStream(byte[] buffer, BufferPool bufferPool)
Parameters
buffer
byte[]-
The buffer
bufferPool
BufferPool-
The buffer pool
Fields
_buffer
The buffer
internal byte[] _buffer
Field Value
- byte[]
_bufferPoolInternal
The buffer pool internal
internal readonly BufferPool _bufferPoolInternal
Field Value
_ms
The ms
internal MemoryStream _ms
Field Value
Properties
CanRead
Gets the value of the can read
public override bool CanRead { get; }
Property Value
CanSeek
Gets the value of the can seek
public override bool CanSeek { get; }
Property Value
CanTimeout
Gets the value of the can timeout
public override bool CanTimeout { get; }
Property Value
CanWrite
Gets the value of the can write
public override bool CanWrite { get; }
Property Value
Capacity
Gets or sets the value of the capacity
public override int Capacity { get; set; }
Property Value
Position
Gets or sets the value of the position
public override long Position { get; set; }
Property Value
ReadTimeout
Gets or sets the value of the read timeout
public override int ReadTimeout { get; set; }
Property Value
WriteTimeout
Gets or sets the value of the write timeout
public override int WriteTimeout { get; set; }
Property Value
Methods
BeginRead(byte[], int, int, AsyncCallback, object)
Begins the read using the specified buffer
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Parameters
buffer
byte[]-
The buffer
offset
int-
The offset
count
int-
The count
callback
AsyncCallback-
The callback
state
object-
The state
Returns
- IAsyncResult
-
The async result
BeginWrite(byte[], int, int, AsyncCallback, object)
Begins the write using the specified buffer
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
Parameters
buffer
byte[]-
The buffer
offset
int-
The offset
count
int-
The count
callback
AsyncCallback-
The callback
state
object-
The state
Returns
- IAsyncResult
-
The async result
CalculateInitialNewSize()
Calculates the initial new size
internal long CalculateInitialNewSize()
Returns
- long
-
The long
CalculateNewSize(int, int)
Calculates the new size using the specified count
internal long CalculateNewSize(int count, int position)
Parameters
Returns
- long
-
The new size
Exceptions
- WebSocketBufferOverflowException
-
Tried to create a buffer ({requiredSize:#,##0} bytes) that was larger than the max allowed size ({int.MaxValue:#,##0})
CalculateRequiredSize(int, int)
Calculates the required size using the specified count
internal long CalculateRequiredSize(int count, int position)
Parameters
Returns
- long
-
The long
Close()
Closes this instance
public override void Close()
ComputeCandidateSize(long)
Computes the candidate size using the specified required size
internal long ComputeCandidateSize(long requiredSize)
Parameters
requiredSize
long-
The required size
Returns
- long
-
The long
CopyToAsync(Stream, int, CancellationToken)
Copies the to using the specified destination
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
Parameters
destination
Stream-
The destination
bufferSize
int-
The buffer size
cancellationToken
CancellationToken-
The cancellation token
Returns
CreateNewBuffer(int)
Creates the new buffer using the specified count
internal void CreateNewBuffer(int count)
Parameters
count
int-
The count
EndRead(IAsyncResult)
Ends the read using the specified async result
public override int EndRead(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult-
The async result
Returns
- int
-
The int
EndWrite(IAsyncResult)
Ends the write using the specified async result
public override void EndWrite(IAsyncResult asyncResult)
Parameters
asyncResult
IAsyncResult-
The async result
EnlargeBufferIfRequired(int)
Enlarges the buffer if required using the specified count
internal void EnlargeBufferIfRequired(int count)
Parameters
count
int-
The count
Exceptions
- WebSocketBufferOverflowException
-
Tried to create a buffer ({requiredSize:#,##0} bytes) that was larger than the max allowed size ({int.MaxValue:#,##0})
Flush()
Flushes this instance
public override void Flush()
FlushAsync(CancellationToken)
Flushes the cancellation token
public override Task FlushAsync(CancellationToken cancellationToken)
Parameters
cancellationToken
CancellationToken-
The cancellation token
Returns
GetBuffer()
Gets the buffer
public override byte[] GetBuffer()
Returns
- byte[]
-
The byte array
IsNewBufferRequired(int)
Describes whether this instance is new buffer required
internal bool IsNewBufferRequired(int count)
Parameters
count
int-
The count
Returns
- bool
-
The bool
IsNewSizeLessThanRequiredSize(long, long)
Describes whether this instance is new size less than required size
internal bool IsNewSizeLessThanRequiredSize(long newSize, long requiredSize)
Parameters
Returns
- bool
-
The bool
Read(byte[], int, int)
Reads the buffer
public override int Read(byte[] buffer, int offset, int count)
Parameters
Returns
- int
-
The int
ReadAsync(byte[], int, int, CancellationToken)
Reads the buffer
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
buffer
byte[]-
The buffer
offset
int-
The offset
count
int-
The count
cancellationToken
CancellationToken-
The cancellation token
Returns
ReadByte()
Reads the byte
public override int ReadByte()
Returns
- int
-
The int
Seek(long, SeekOrigin)
Seeks the offset
public override long Seek(long offset, SeekOrigin loc)
Parameters
offset
long-
The offset
loc
SeekOrigin-
The loc
Returns
- long
-
The long
SetLength(long)
Note: This will not make the MemoryStream any smaller, only larger
public override void SetLength(long value)
Parameters
value
long
ToArray()
Returns the array
public override byte[] ToArray()
Returns
- byte[]
-
The byte array
ValidateRequiredSize(long)
Validates the required size using the specified required size
internal void ValidateRequiredSize(long requiredSize)
Parameters
requiredSize
long-
The required size
Exceptions
- WebSocketBufferOverflowException
-
Tried to create a buffer ({requiredSize:#,##0} bytes) that was larger than the max allowed size ({int.MaxValue:#,##0})
Write(byte[], int, int)
Writes the buffer
public override void Write(byte[] buffer, int offset, int count)
Parameters
WriteAsync(byte[], int, int, CancellationToken)
Writes the buffer
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Parameters
buffer
byte[]-
The buffer
offset
int-
The offset
count
int-
The count
cancellationToken
CancellationToken-
The cancellation token
Returns
WriteByte(byte)
Writes the byte using the specified value
public override void WriteByte(byte value)
Parameters
value
byte-
The value
WriteTo(Stream)
Writes the to using the specified stream
public override void WriteTo(Stream stream)
Parameters
stream
Stream-
The stream