WinForms

Code Examples Upgrade Guide User Guide Demos Support Forums Download
  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class BufferedStreamEx

    Show / Hide Table of Contents

    Class BufferedStreamEx

    Special wrapper which allows users to control access to stream and cache data. Our implementation fixes the bug of .NET BufferedStream class: on setting Position property, class resets internal cache. Our class detects situations when reset of cache is not needed.

    Inheritance
    System.Object
    System.MarshalByRefObject
    System.IO.Stream
    BufferedStreamEx
    Implements
    System.IDisposable
    Inherited Members
    System.IO.Stream.Null
    System.IO.Stream.CopyToAsync(System.IO.Stream)
    System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32)
    System.IO.Stream.CopyToAsync(System.IO.Stream, System.Int32, System.Threading.CancellationToken)
    System.IO.Stream.CopyTo(System.IO.Stream)
    System.IO.Stream.CopyTo(System.IO.Stream, System.Int32)
    System.IO.Stream.Dispose()
    System.IO.Stream.Dispose(System.Boolean)
    System.IO.Stream.FlushAsync()
    System.IO.Stream.FlushAsync(System.Threading.CancellationToken)
    System.IO.Stream.CreateWaitHandle()
    System.IO.Stream.BeginRead(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
    System.IO.Stream.EndRead(System.IAsyncResult)
    System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32)
    System.IO.Stream.ReadAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
    System.IO.Stream.BeginWrite(System.Byte[], System.Int32, System.Int32, System.AsyncCallback, System.Object)
    System.IO.Stream.EndWrite(System.IAsyncResult)
    System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32)
    System.IO.Stream.WriteAsync(System.Byte[], System.Int32, System.Int32, System.Threading.CancellationToken)
    System.IO.Stream.Synchronized(System.IO.Stream)
    System.IO.Stream.ObjectInvariant()
    System.IO.Stream.CanTimeout
    System.IO.Stream.ReadTimeout
    System.IO.Stream.WriteTimeout
    System.MarshalByRefObject.MemberwiseClone(System.Boolean)
    System.MarshalByRefObject.GetLifetimeService()
    System.MarshalByRefObject.InitializeLifetimeService()
    System.MarshalByRefObject.CreateObjRef(System.Type)
    System.Object.ToString()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    Namespace: Syncfusion.HTMLUI.Base
    Assembly: Syncfusion.HTMLUI.Base.dll
    Syntax
    public sealed class BufferedStreamEx : Stream, IDisposable

    Constructors

    BufferedStreamEx(Stream)

    Overloaded constructor. Initializes class by an instance of 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)

    Initializes class by an 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 equal to or less than zero.

    Properties

    BaseStream

    Returns the reference on stream wrapped by BufferStreamEx.

    Declaration
    public Stream BaseStream { get; }
    Property Value
    Type Description
    System.IO.Stream

    CanRead

    Indicates whether data can be read from wrapped stream. True if data can be read.

    Declaration
    public override bool CanRead { get; }
    Property Value
    Type Description
    System.Boolean
    Overrides
    System.IO.Stream.CanRead
    Exceptions
    Type Condition
    System.ArgumentNullException

    Class instance was disposed.

    CanSeek

    Indicates whether wrapped stream supports seek operations.

    Declaration
    public override bool CanSeek { get; }
    Property Value
    Type Description
    System.Boolean
    Overrides
    System.IO.Stream.CanSeek
    Exceptions
    Type Condition
    System.ArgumentNullException

    Class instance was disposed.

    CanWrite

    Indicates whether data can be written to wrapped stream.

    Declaration
    public override bool CanWrite { get; }
    Property Value
    Type Description
    System.Boolean
    Overrides
    System.IO.Stream.CanWrite
    Exceptions
    Type Condition
    System.ArgumentNullException

    Class instance was disposed.

    Length

    Returns the length of wrapped stream. On property value get class Flush not written to stream data.

    Declaration
    public override long Length { get; }
    Property Value
    Type Description
    System.Int64
    Overrides
    System.IO.Stream.Length
    Exceptions
    Type Condition
    System.ArgumentNullException

    Class instance was disposed.

    Position

    Returns current position of stream. Position can be different when wrapped stream, because wrapped stream will point on last byte of cached data. On property set not written data flushed to stream.

    Declaration
    public override long Position { get; set; }
    Property Value
    Type Description
    System.Int64
    Overrides
    System.IO.Stream.Position
    Exceptions
    Type Condition
    System.ArgumentNullException

    Class instance was disposed.

    System.ArgumentException

    Wrapped stream does not support seek operation.

    Methods

    Close()

    Saves all data from cache and closes stream.

    Declaration
    public override void Close()
    Overrides
    System.IO.Stream.Close()

    Flush()

    Flushes data. Resets cache.

    Declaration
    public override void Flush()
    Overrides
    System.IO.Stream.Flush()
    Exceptions
    Type Condition
    System.ArgumentNullException

    When stream is NULL.

    Read(Byte[], Int32, Int32)

    Reads data from stream. If data is cached, then class will not call wrapped stream and simply return 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
    System.IO.Stream.Read(System.Byte[], System.Int32, System.Int32)

    ReadByte()

    Reads a byte from the underlying stream. Returns the byte cast to an integer; -1 if reading from the end of the stream.

    Declaration
    public override int ReadByte()
    Returns
    Type Description
    System.Int32

    Read byte.

    Overrides
    System.IO.Stream.ReadByte()

    Seek(Int64, SeekOrigin)

    Seek operation. On any seek operation not written, data from cache will be flushed to wrapped stream. It is better to use position property if 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
    System.IO.Stream.Seek(System.Int64, System.IO.SeekOrigin)
    Exceptions
    Type Condition
    System.ArgumentNullException

    If stream is NULL.

    System.ArgumentException

    If can't seek in the stream.

    SetLength(Int64)

    Sets the length of the wrapped stream.

    Declaration
    public override void SetLength(long value)
    Parameters
    Type Name Description
    System.Int64 value

    New length of stream.

    Overrides
    System.IO.Stream.SetLength(System.Int64)
    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)

    Writes 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
    System.IO.Stream.Write(System.Byte[], System.Int32, System.Int32)
    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)

    Writes 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
    System.IO.Stream.WriteByte(System.Byte)
    Exceptions
    Type Condition
    System.ArgumentNullException

    If stream is NULL.

    System.ArgumentException

    If can't write into stream.

    Implements

    System.IDisposable

    Extension Methods

    ExtensionMethods.GetBytes(Stream)
    ExtensionMethods.CopyTo(Stream, Stream)
    Back to top Generated by DocFX
    Copyright © 2001 - 2023 Syncfusion Inc. All Rights Reserved