Show / Hide Table of Contents

    Class Stream

    Provides a generic view of a sequence of bytes. This is an abstract class.

    Inheritance
    Object
    MarshalByRefObject
    Stream
    FileStream
    MemoryStream
    NetworkStream
    Implements
    IDisposable
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: System.IO
    Assembly: System.IO.Streams.dll
    Syntax
    [Serializable]
    public abstract class Stream : MarshalByRefObject, IDisposable

    Properties

    | Improve this Doc View Source

    CanRead

    When overridden in a derived class, gets a value indicating whether the current stream supports reading.

    Declaration
    public abstract bool CanRead { get; }
    Property Value
    Type Description
    Boolean

    true if the stream supports reading; otherwise, false.

    | Improve this Doc View Source

    CanSeek

    When overridden in a derived class, gets a value indicating whether the current stream supports seeking.

    Declaration
    public abstract bool CanSeek { get; }
    Property Value
    Type Description
    Boolean

    true if the stream supports seeking; otherwise, false.

    | Improve this Doc View Source

    CanTimeout

    Gets a value that determines whether the current stream can time out.

    Declaration
    public virtual bool CanTimeout { get; }
    Property Value
    Type Description
    Boolean

    A value that determines whether the current stream can time out.

    | Improve this Doc View Source

    CanWrite

    When overridden in a derived class, gets a value indicating whether the current stream supports writing.

    Declaration
    public abstract bool CanWrite { get; }
    Property Value
    Type Description
    Boolean

    true if the stream supports writing; otherwise, false.

    | Improve this Doc View Source

    Length

    When overridden in a derived class, gets the length in bytes of the stream.

    Declaration
    public abstract long Length { get; }
    Property Value
    Type Description
    Int64

    A long value representing the length of the stream in bytes.

    | Improve this Doc View Source

    Position

    When overridden in a derived class, gets or sets the position within the current stream.

    Declaration
    public abstract long Position { get; set; }
    Property Value
    Type Description
    Int64

    The current position within the stream.

    | Improve this Doc View Source

    ReadTimeout

    Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.

    Declaration
    public virtual int ReadTimeout { get; set; }
    Property Value
    Type Description
    Int32

    A value, in milliseconds, that determines how long the stream will attempt to read before timing out.

    Exceptions
    Type Condition
    InvalidOperationException
    | Improve this Doc View Source

    WriteTimeout

    Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.

    Declaration
    public virtual int WriteTimeout { get; set; }
    Property Value
    Type Description
    Int32

    A value, in milliseconds, that determines how long the stream will attempt to write before timing out.

    Exceptions
    Type Condition
    InvalidOperationException

    Methods

    | Improve this Doc View Source

    Close()

    Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.

    Declaration
    public virtual void Close()
    Remarks

    Stream used to require that all cleanup logic went into Close(), which was thought up before we invented IDisposable. However, we need to follow the IDisposable pattern so that users can write sensible subclasses without needing to inspect all their base classes, and without worrying about version brittleness, from a base class switching to the Dispose pattern. We're moving Stream to the Dispose(bool) pattern - that's where all subclasses should put their cleanup starting in V2.

    | Improve this Doc View Source

    CopyTo(Stream)

    Reads the bytes from the current stream and writes them to another stream.

    Declaration
    public void CopyTo(Stream destination)
    Parameters
    Type Name Description
    Stream destination

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

    Remarks

    Copying begins at the current position in the current stream, and does not reset the position of the destination stream after the copy operation is complete.

    Exceptions
    Type Condition
    ArgumentNullException

    destination is null.

    NotSupportedException

    The current stream does not support reading.

    -or-

    destination does not support writing.

    ObjectDisposedException

    Either the current stream or destination were closed before the CopyTo(Stream) method was called.

    IOException

    An I/O error occurred.

    | Improve this Doc View Source

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

    Declaration
    public void Dispose()
    | Improve this Doc View Source

    Dispose(Boolean)

    Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    Boolean disposing

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

    | Improve this Doc View Source

    Finalize()

    Declaration
    protected void Finalize()
    | Improve this Doc View Source

    Flush()

    When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.

    Declaration
    public abstract void Flush()
    | Improve this Doc View Source

    Read(Byte[], Int32, Int32)

    When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

    Declaration
    public abstract int Read(byte[] buffer, int offset, int count)
    Parameters
    Type Name Description
    Byte[] buffer

    An array of bytes. 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.

    Int32 offset

    The zero-based byte offset in buffer at which to begin storing the data read from the current stream.

    Int32 count

    The maximum number of bytes to be read from the current stream.

    Returns
    Type Description
    Int32

    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 (0) if the end of the stream has been reached.

    | Improve this Doc View Source

    Read(SpanByte)

    When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

    Declaration
    public abstract int Read(SpanByte buffer)
    Parameters
    Type Name Description
    SpanByte buffer

    A region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.

    Returns
    Type Description
    Int32

    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 (0) if the end of the stream has been reached.

    | Improve this Doc View Source

    ReadByte()

    Reads a byte from the stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.

    Declaration
    public virtual int ReadByte()
    Returns
    Type Description
    Int32

    The unsigned byte cast to an Int32, or -1 if at the end of the stream.

    | Improve this Doc View Source

    Seek(Int64, SeekOrigin)

    When overridden in a derived class, sets the position within the current stream.

    Declaration
    public abstract long Seek(long offset, SeekOrigin origin)
    Parameters
    Type Name Description
    Int64 offset

    A byte offset relative to the origin parameter.

    SeekOrigin origin

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

    Returns
    Type Description
    Int64

    The new position within the current stream.

    | Improve this Doc View Source

    SetLength(Int64)

    When overridden in a derived class, sets the length of the current stream.

    Declaration
    public abstract void SetLength(long value)
    Parameters
    Type Name Description
    Int64 value

    The desired length of the current stream in bytes.

    | Improve this Doc View Source

    Write(Byte[], Int32, Int32)

    When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

    Declaration
    public abstract void Write(byte[] buffer, int offset, int count)
    Parameters
    Type Name Description
    Byte[] buffer

    An array of bytes. This method copies count bytes from buffer to the current stream.

    Int32 offset

    The zero-based byte offset in buffer at which to begin copying bytes to the current stream.

    Int32 count

    The number of bytes to be written to the current stream.

    | Improve this Doc View Source

    WriteByte(Byte)

    Writes a byte to the current position in the stream and advances the position within the stream by one byte.

    Declaration
    public virtual void WriteByte(byte value)
    Parameters
    Type Name Description
    Byte value

    The byte to write to the stream.

    Implements

    IDisposable

    Extension Methods

    LogDispatcher.GetCurrentClassLogger(Object)
    • Improve this Doc
    • View Source
    Back to top Copyright © 2018 nanoFramework Contributors
    Generated by DocFX