Mono Class Library: System.IO Namespace

System.IO.Stream Class

Abstract base class for all stream implementations. [Edit]

See Also: Stream Members

System.Object
     System.MarshalByRefObject
          System.IO.Stream

[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Stream : MarshalByRefObject, IDisposable

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

Streams involve three fundamental operations:

All classes that represent streams inherit from the System.IO.Stream class. The System.IO.Stream class and its subclasses provide a generic view of data sources and repositories, isolating the programmer from the specific details of the operating system and underlying devices.

Subclasses are required to provide implementations only for the synchronous read and write methods. The asynchronous read and write methods are implemented via the synchronous ones.

Note: The System.IO.Stream synchronous read and write methods are Stream.Read(Byte[], int, int) and Stream.Write(Byte[], int, int). The asynchronous read and write methods are Stream.BeginRead(Byte[], int, int, AsyncCallback, object), Stream.EndRead(IAsyncResult), Stream.BeginWrite(Byte[], int, int, AsyncCallback, object), and Stream.EndWrite(IAsyncResult).

Depending on the underlying data source or repository, streams might support only some of these capabilities. An application can query a stream for its capabilities by using the Stream.CanRead, Stream.CanWrite, and Stream.CanSeek properties.

The Stream.Read(Byte[], int, int) and Stream.Write(Byte[], int, int) methods read and write data in a variety of formats. For streams that support seeking, the Stream.Seek(long, SeekOrigin) and Stream.SetLength(long) methods, and the Stream.Position and Stream.Length properties can be used to query and modify the current position and length of a stream.

Some stream implementations perform local buffering of the underlying data to improve performance. For such streams, the Stream.Flush method can be used to clear any internal buffers and ensure that all data has been written to the underlying data source or repository.

Calling Stream.Close on a System.IO.Stream flushes any buffered data, essentially calling Stream.Flush for you. Stream.Close also releases operating system resources such as file handles, network connections, or memory used for any internal buffering.

If you need a System.IO.Stream with no backing store (i.e., a bit bucket), use Stream.Null .

[Edit]

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0