Mono Class Library: System.IO NamespaceSystem.IO.Stream Class |
See Also: Stream Members
System.Object
System.MarshalByRefObject
System.IO.Stream
|
All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.
Streams involve three fundamental operations:
- You can read from streams. Reading is the transfer of data from a stream into a data structure, such as an array of bytes.
- You can write to streams. Writing is the transfer of data from a data structure into a stream.
- Streams can support seeking. Seeking is the querying and modifying of the current position within a stream. Seek capability depends on the kind of backing store a stream has. For example, network streams have no unified concept of a current position, and therefore typically do not support seeking.
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]
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0