Class BufferedStreamEx
Special wrapper which allow us to control access to stream and cache data. Our implementation fix bug of NET BufferedStream class: on Position property set class reset internal cache. Our class detect situations when reset of cache not needed.
Inheritance
Implements
Inherited Members
Namespace: Syncfusion.IO
Assembly: Syncfusion.MIME.Base.dll
Syntax
public class BufferedStreamEx : Stream, IDisposable
Constructors
BufferedStreamEx(Stream)
Initialize class by stream and DefaultBufferSize == 4096.
Declaration
public BufferedStreamEx(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | Stream which our class must wrap |
BufferedStreamEx(Stream, Int32)
Initialize class by instance of stream and user defined cache size
Declaration
public BufferedStreamEx(Stream stream, int bufferSize)
Parameters
Type | Name | Description |
---|---|---|
System.IO.Stream | stream | Stream which our class must wrap |
System.Int32 | bufferSize | User defined cache size |
Exceptions
Type | Condition |
---|---|
System.ArgumentException | stream does not support Read and Write operations |
System.ArgumentOutOfRangeException | bufferSize is equel or less of zero |
Properties
BaseStream
Get reference on stream wrapped by BufferStreamEx
Declaration
public Stream BaseStream { get; }
Property Value
Type |
---|
System.IO.Stream |
CanRead
Indicate can be data readed from wrapped stream. TRUE - data can be readed.
Declaration
public override bool CanRead { get; }
Property Value
Type |
---|
System.Boolean |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | class instance was disposed |
CanSeek
Indicate does wrapped stream support Seek operations or not
Declaration
public override bool CanSeek { get; }
Property Value
Type |
---|
System.Boolean |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | class instance was disposed |
CanWrite
Indicate can data be written to wrapped stream.
Declaration
public override bool CanWrite { get; }
Property Value
Type |
---|
System.Boolean |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | class instance was disposed |
Length
Get Length of wrapped stream. On property value get class Flush not written to stream data.
Declaration
public override long Length { get; }
Property Value
Type |
---|
System.Int64 |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | class instance was disposed |
Position
Get current position of stream. Position can be differ then wrapped stream has, because wrapped stream will point on last byte of our cached data. On property set not written data flushed to stream.
Declaration
public override long Position { get; set; }
Property Value
Type |
---|
System.Int64 |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | class instance was disposed |
System.ArgumentException | wrapped stream does not support seek operation |
Methods
Close()
Save all data from cache and Close stream.
Declaration
public override void Close()
Overrides
Flush()
Flush data. reset cache.
Declaration
public override void Flush()
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | When stream is null |
Read(Byte[], Int32, Int32)
Read data from stream. If data is cached then class will not call wrapped stream and simple returned copy of cached data.
Declaration
public override int Read(byte[] array, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | Output buffer |
System.Int32 | offset | offset in output buffer where data from stream must be placed |
System.Int32 | count | count of bytes which class must return |
Returns
Type | Description |
---|---|
System.Int32 | quantity of read bytes |
Overrides
ReadByte()
Reads a byte from the underlying stream. Returns the byte cast to an int or -1 if reading from the end of the stream.
Declaration
public override int ReadByte()
Returns
Type | Description |
---|---|
System.Int32 | read byte |
Overrides
Seek(Int64, SeekOrigin)
Seek operation. On any seek operation not written data from cache will be flushed to wrapped stream. Better use Position property it optimized for cache use.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | offset | New offset of stream |
System.IO.SeekOrigin | origin | Start point of seek operation |
Returns
Type | Description |
---|---|
System.Int64 | Current position |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If stream is null |
System.ArgumentException | If can't seek in the stream |
SetLength(Int64)
Set length of wrapped stream
Declaration
public override void SetLength(long value)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | value | new Length of stream |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | When value is less than zero |
System.ArgumentNullException | When stream is null |
System.ArgumentException | If can't seek or can't write into stream |
Write(Byte[], Int32, Int32)
Write portion of data into wrapped stream. If data can be placed into cache then it will be there and only on Flush operation data will be saved to wrapped stream.
Declaration
public override void Write(byte[] array, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | array | array containing data |
System.Int32 | offset | offset to the beginning of the portion of data |
System.Int32 | count | number of bytes in the portion of data |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If array or stream is null |
System.ArgumentOutOfRangeException | If offset or count is less than zero |
System.ArgumentException | If array does not contain required elements count |
WriteByte(Byte)
Write on byte of information into stream.
Declaration
public override void WriteByte(byte value)
Parameters
Type | Name | Description |
---|---|---|
System.Byte | value | Value which must be written |
Overrides
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If stream is null |
System.ArgumentException | If can't write into stream |