mscorlib(4.0.0.0) API with additions
System.IO.Stream Class Referenceabstract

Provides a generic view of a sequence of bytes. This is an abstract class.To browse the .NET Framework source code for this type, see the Reference Source. More...

Inheritance diagram for System.IO.Stream:
[legend]
Collaboration diagram for System.IO.Stream:
[legend]

Public Member Functions

Task CopyToAsync (Stream destination)
 Asynchronously reads the bytes from the current stream and writes them to another stream. More...
 
Task CopyToAsync (Stream destination, int bufferSize)
 Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size. More...
 
virtual Task CopyToAsync (Stream destination, int bufferSize, CancellationToken cancellationToken)
 Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token. More...
 
void CopyTo (Stream destination)
 Reads the bytes from the current stream and writes them to another stream. More...
 
void CopyTo (Stream destination, int bufferSize)
 Reads the bytes from the current stream and writes them to another stream, using a specified buffer size. More...
 
virtual void 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. More...
 
void Dispose ()
 Releases all resources used by the T:System.IO.Stream. More...
 
abstract void 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. More...
 
Task FlushAsync ()
 Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device. More...
 
virtual Task FlushAsync (CancellationToken cancellationToken)
 Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests. More...
 
virtual IAsyncResult BeginRead (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 Begins an asynchronous read operation. (Consider using M:System.IO.Stream.ReadAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.) More...
 
virtual int EndRead (IAsyncResult asyncResult)
 Waits for the pending asynchronous read to complete. (Consider using M:System.IO.Stream.ReadAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.) More...
 
Task< int > ReadAsync (byte[] buffer, int offset, int count)
 Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read. More...
 
virtual Task< int > ReadAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests. More...
 
virtual IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 Begins an asynchronous write operation. (Consider using M:System.IO.Stream.WriteAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.) More...
 
virtual void EndWrite (IAsyncResult asyncResult)
 Ends an asynchronous write operation. (Consider using M:System.IO.Stream.WriteAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.) More...
 
Task WriteAsync (byte[] buffer, int offset, int count)
 Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written. More...
 
virtual Task WriteAsync (byte[] buffer, int offset, int count, CancellationToken cancellationToken)
 Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests. More...
 
abstract long Seek (long offset, SeekOrigin origin)
 When overridden in a derived class, sets the position within the current stream. More...
 
abstract void SetLength (long value)
 When overridden in a derived class, sets the length of the current stream. More...
 
abstract int Read ([In] [Out] byte[] buffer, int offset, int count)
 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. More...
 
virtual int 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. More...
 
abstract void Write (byte[] buffer, int offset, int count)
 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. More...
 
virtual void WriteByte (byte value)
 Writes a byte to the current position in the stream and advances the position within the stream by one byte. More...
 
- Public Member Functions inherited from System.MarshalByRefObject
object GetLifetimeService ()
 Retrieves the current lifetime service object that controls the lifetime policy for this instance. More...
 
virtual object InitializeLifetimeService ()
 Obtains a lifetime service object to control the lifetime policy for this instance. More...
 
virtual ObjRef CreateObjRef (Type requestedType)
 Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. More...
 

Static Public Member Functions

static Stream Synchronized (Stream stream)
 Creates a thread-safe (synchronized) wrapper around the specified T:System.IO.Stream object. More...
 

Static Public Attributes

static readonly Stream Null = new NullStream()
 A Stream with no backing store. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Releases the unmanaged resources used by the T:System.IO.Stream and optionally releases the managed resources. More...
 
virtual WaitHandle CreateWaitHandle ()
 Allocates a T:System.Threading.WaitHandle object. More...
 
virtual void ObjectInvariant ()
 Provides support for a T:System.Diagnostics.Contracts.Contract. More...
 
 Stream ()
 Initializes a new instance of the T:System.IO.Stream class. More...
 
- Protected Member Functions inherited from System.MarshalByRefObject
MarshalByRefObject MemberwiseClone (bool cloneIdentity)
 Creates a shallow copy of the current T:System.MarshalByRefObject object. More...
 

Properties

abstract bool CanRead [get]
 When overridden in a derived class, gets a value indicating whether the current stream supports reading. More...
 
abstract bool CanSeek [get]
 When overridden in a derived class, gets a value indicating whether the current stream supports seeking. More...
 
virtual bool CanTimeout [get]
 Gets a value that determines whether the current stream can time out. More...
 
abstract bool CanWrite [get]
 When overridden in a derived class, gets a value indicating whether the current stream supports writing. More...
 
abstract long Length [get]
 When overridden in a derived class, gets the length in bytes of the stream. More...
 
abstract long Position [get, set]
 When overridden in a derived class, gets or sets the position within the current stream. More...
 
virtual int ReadTimeout [get, set]
 Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out. More...
 
virtual int WriteTimeout [get, set]
 Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out. More...
 

Detailed Description

Provides a generic view of a sequence of bytes. This is an abstract class.To browse the .NET Framework source code for this type, see the Reference Source.

Definition at line 16 of file Stream.cs.

Constructor & Destructor Documentation

◆ Stream()

System.IO.Stream.Stream ( )
protected

Initializes a new instance of the T:System.IO.Stream class.

Definition at line 1406 of file Stream.cs.

Member Function Documentation

◆ BeginRead()

virtual IAsyncResult System.IO.Stream.BeginRead ( byte []  buffer,
int  offset,
int  count,
AsyncCallback  callback,
object  state 
)
virtual

Begins an asynchronous read operation. (Consider using M:System.IO.Stream.ReadAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.)

Parameters
bufferThe buffer to read the data into.
offsetThe byte offset in buffer at which to begin writing data read from the stream.
countThe maximum number of bytes to read.
callbackAn optional asynchronous callback, to be called when the read is complete.
stateA user-provided object that distinguishes this particular asynchronous read request from other requests.
Returns
An T:System.IAsyncResult that represents the asynchronous read, which could still be pending.
Exceptions
T:System.IO.IOExceptionAttempted an asynchronous read past the end of the stream, or a disk error occurs.
T:System.ArgumentExceptionOne or more of the arguments is invalid.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.
T:System.NotSupportedExceptionThe current Stream implementation does not support the read operation.

Reimplemented in System.IO.FileStream, System.Net.Security.NegotiateStream, System.Net.Security.SslStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, System.Net.Sockets.NetworkStream, System.IO.Pipes.PipeStream, System.IO.BufferedStream, System.IO.Compression.DeflateStream, and System.IO.Compression.GZipStream.

Definition at line 928 of file Stream.cs.

◆ BeginWrite()

virtual IAsyncResult System.IO.Stream.BeginWrite ( byte []  buffer,
int  offset,
int  count,
AsyncCallback  callback,
object  state 
)
virtual

Begins an asynchronous write operation. (Consider using M:System.IO.Stream.WriteAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.)

Parameters
bufferThe buffer to write data from.
offsetThe byte offset in buffer from which to begin writing.
countThe maximum number of bytes to write.
callbackAn optional asynchronous callback, to be called when the write is complete.
stateA user-provided object that distinguishes this particular asynchronous write request from other requests.
Returns
An IAsyncResult that represents the asynchronous write, which could still be pending.
Exceptions
T:System.IO.IOExceptionAttempted an asynchronous write past the end of the stream, or a disk error occurs.
T:System.ArgumentExceptionOne or more of the arguments is invalid.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.
T:System.NotSupportedExceptionThe current Stream implementation does not support the write operation.

Reimplemented in System.IO.FileStream, System.Net.Security.NegotiateStream, System.IO.BufferedStream, System.Net.Security.SslStream, System.IO.Pipes.PipeStream, System.IO.Compression.DeflateStream, System.Net.Sockets.NetworkStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, and System.IO.Compression.GZipStream.

Definition at line 1086 of file Stream.cs.

◆ Close()

virtual void System.IO.Stream.Close ( )
virtual

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.

Definition at line 855 of file Stream.cs.

◆ CopyTo() [1/2]

void System.IO.Stream.CopyTo ( Stream  destination)

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

Parameters
destinationThe stream to which the contents of the current stream will be copied.
Exceptions
T:System.ArgumentNullExceptiondestination is null.
T:System.NotSupportedExceptionThe current stream does not support reading.-or- destination does not support writing.
T:System.ObjectDisposedExceptionEither the current stream or destination were closed before the M:System.IO.Stream.CopyTo(System.IO.Stream) method was called.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 778 of file Stream.cs.

◆ CopyTo() [2/2]

void System.IO.Stream.CopyTo ( Stream  destination,
int  bufferSize 
)

Reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

Parameters
destinationThe stream to which the contents of the current stream will be copied.
bufferSizeThe size of the buffer. This value must be greater than zero. The default size is 81920.
Exceptions
T:System.ArgumentNullExceptiondestination is null.
T:System.ArgumentOutOfRangeExceptionbufferSize is negative or zero.
T:System.NotSupportedExceptionThe current stream does not support reading.-or- destination does not support writing.
T:System.ObjectDisposedExceptionEither the current stream or destination were closed before the M:System.IO.Stream.CopyTo(System.IO.Stream) method was called.
T:System.IO.IOExceptionAn I/O error occurred.

Definition at line 815 of file Stream.cs.

◆ CopyToAsync() [1/3]

Task System.IO.Stream.CopyToAsync ( Stream  destination)

Asynchronously reads the bytes from the current stream and writes them to another stream.

Parameters
destinationThe stream to which the contents of the current stream will be copied.
Returns
A task that represents the asynchronous copy operation.
Exceptions
T:System.ArgumentNullExceptiondestination is null.
T:System.ObjectDisposedExceptionEither the current stream or the destination stream is disposed.
T:System.NotSupportedExceptionThe current stream does not support reading, or the destination stream does not support writing.

Definition at line 693 of file Stream.cs.

◆ CopyToAsync() [2/3]

Task System.IO.Stream.CopyToAsync ( Stream  destination,
int  bufferSize 
)

Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size.

Parameters
destinationThe stream to which the contents of the current stream will be copied.
bufferSizeThe size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920.
Returns
A task that represents the asynchronous copy operation.
Exceptions
T:System.ArgumentNullExceptiondestination is null.
T:System.ArgumentOutOfRangeExceptionbuffersize is negative or zero.
T:System.ObjectDisposedExceptionEither the current stream or the destination stream is disposed.
T:System.NotSupportedExceptionThe current stream does not support reading, or the destination stream does not support writing.

Definition at line 711 of file Stream.cs.

◆ CopyToAsync() [3/3]

virtual Task System.IO.Stream.CopyToAsync ( Stream  destination,
int  bufferSize,
CancellationToken  cancellationToken 
)
virtual

Asynchronously reads the bytes from the current stream and writes them to another stream, using a specified buffer size and cancellation token.

Parameters
destinationThe stream to which the contents of the current stream will be copied.
bufferSizeThe size, in bytes, of the buffer. This value must be greater than zero. The default size is 81920.
cancellationTokenThe token to monitor for cancellation requests. The default value is P:System.Threading.CancellationToken.None.
Returns
A task that represents the asynchronous copy operation.
Exceptions
T:System.ArgumentNullExceptiondestination is null.
T:System.ArgumentOutOfRangeExceptionbuffersize is negative or zero.
T:System.ObjectDisposedExceptionEither the current stream or the destination stream is disposed.
T:System.NotSupportedExceptionThe current stream does not support reading, or the destination stream does not support writing.

Reimplemented in System.IO.MemoryStream.

Definition at line 730 of file Stream.cs.

◆ CreateWaitHandle()

virtual WaitHandle System.IO.Stream.CreateWaitHandle ( )
protectedvirtual

Allocates a T:System.Threading.WaitHandle object.

Returns
A reference to the allocated WaitHandle.

Definition at line 910 of file Stream.cs.

◆ Dispose() [1/2]

void System.IO.Stream.Dispose ( )

Releases all resources used by the T:System.IO.Stream.

Implements System.IDisposable.

Definition at line 863 of file Stream.cs.

◆ Dispose() [2/2]

virtual void System.IO.Stream.Dispose ( bool  disposing)
protectedvirtual

◆ EndRead()

virtual int System.IO.Stream.EndRead ( IAsyncResult  asyncResult)
virtual

Waits for the pending asynchronous read to complete. (Consider using M:System.IO.Stream.ReadAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.)

Parameters
asyncResultThe reference to the pending asynchronous request to finish.
Returns
The number of bytes read from the stream, between zero (0) and the number of bytes you requested. Streams return zero (0) only at the end of the stream, otherwise, they should block until at least one byte is available.
Exceptions
T:System.ArgumentNullExceptionasyncResult is null.
T:System.ArgumentExceptionA handle to the pending read operation is not available.-or-The pending operation does not support reading.
T:System.InvalidOperationExceptionasyncResult did not originate from a M:System.IO.Stream.BeginRead(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object) method on the current stream.
T:System.IO.IOExceptionThe stream is closed or an internal error has occurred.

Reimplemented in System.IO.FileStream, System.Net.Security.NegotiateStream, System.Net.Security.SslStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, System.Net.Sockets.NetworkStream, System.IO.Pipes.PipeStream, System.IO.BufferedStream, System.IO.Compression.DeflateStream, and System.IO.Compression.GZipStream.

Definition at line 982 of file Stream.cs.

◆ EndWrite()

virtual void System.IO.Stream.EndWrite ( IAsyncResult  asyncResult)
virtual

Ends an asynchronous write operation. (Consider using M:System.IO.Stream.WriteAsync(System.Byte[],System.Int32,System.Int32) instead; see the Remarks section.)

Parameters
asyncResultA reference to the outstanding asynchronous I/O request.
Exceptions
T:System.ArgumentNullExceptionasyncResult is null.
T:System.ArgumentExceptionA handle to the pending write operation is not available.-or-The pending operation does not support writing.
T:System.InvalidOperationExceptionasyncResult did not originate from a M:System.IO.Stream.BeginWrite(System.Byte[],System.Int32,System.Int32,System.AsyncCallback,System.Object) method on the current stream.
T:System.IO.IOExceptionThe stream is closed or an internal error has occurred.

Reimplemented in System.IO.FileStream, System.IO.BufferedStream, System.Net.Security.NegotiateStream, System.Net.Security.SslStream, System.IO.Pipes.PipeStream, System.IO.Compression.DeflateStream, System.Net.Sockets.NetworkStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, and System.IO.Compression.GZipStream.

Definition at line 1162 of file Stream.cs.

◆ Flush()

abstract void System.IO.Stream.Flush ( )
pure virtual

◆ FlushAsync() [1/2]

Task System.IO.Stream.FlushAsync ( )

Asynchronously clears all buffers for this stream and causes any buffered data to be written to the underlying device.

Returns
A task that represents the asynchronous flush operation.
Exceptions
T:System.ObjectDisposedExceptionThe stream has been disposed.

Definition at line 887 of file Stream.cs.

◆ FlushAsync() [2/2]

virtual Task System.IO.Stream.FlushAsync ( CancellationToken  cancellationToken)
virtual

Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

Parameters
cancellationTokenThe token to monitor for cancellation requests. The default value is P:System.Threading.CancellationToken.None.
Returns
A task that represents the asynchronous flush operation.
Exceptions
T:System.ObjectDisposedExceptionThe stream has been disposed.

Reimplemented in System.IO.FileStream, System.Net.Sockets.NetworkStream, System.IO.UnmanagedMemoryStream, System.IO.MemoryStream, System.IO.BufferedStream, and System.Security.Cryptography.CryptoStream.

Definition at line 899 of file Stream.cs.

◆ ObjectInvariant()

virtual void System.IO.Stream.ObjectInvariant ( )
protectedvirtual

Provides support for a T:System.Diagnostics.Contracts.Contract.

Definition at line 1358 of file Stream.cs.

◆ Read()

abstract int System.IO.Stream.Read ( [Out] byte []  buffer,
int  offset,
int  count 
)
pure virtual

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.

Parameters
bufferAn 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.
offsetThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countThe maximum number of bytes to be read from the current stream.
Returns
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.
Exceptions
T:System.ArgumentExceptionThe sum of offset and count is larger than the buffer length.
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionoffset or count is negative.
T:System.IO.IOExceptionAn I/O error occurs.
T:System.NotSupportedExceptionThe stream does not support reading.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Implemented in System.IO.FileStream, System.Net.Security.NegotiateStream, System.Net.Security.SslStream, System.IO.MemoryStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, System.IO.UnmanagedMemoryStream, System.IO.Pipes.PipeStream, System.IO.BufferedStream, System.Net.Sockets.NetworkStream, System.IO.Compression.DeflateStream, System.IO.Compression.GZipStream, and System.Security.Cryptography.CryptoStream.

◆ ReadAsync() [1/2]

Task<int> System.IO.Stream.ReadAsync ( byte []  buffer,
int  offset,
int  count 
)

Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Parameters
bufferThe buffer to write the data into.
offsetThe byte offset in buffer at which to begin writing data from the stream.
countThe maximum number of bytes to read.
Returns
A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
Exceptions
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionoffset or count is negative.
T:System.ArgumentExceptionThe sum of offset and count is larger than the buffer length.
T:System.NotSupportedExceptionThe stream does not support reading.
T:System.ObjectDisposedExceptionThe stream has been disposed.
T:System.InvalidOperationExceptionThe stream is currently in use by a previous read operation.

Definition at line 1032 of file Stream.cs.

◆ ReadAsync() [2/2]

virtual Task<int> System.IO.Stream.ReadAsync ( byte []  buffer,
int  offset,
int  count,
CancellationToken  cancellationToken 
)
virtual

Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.

Parameters
bufferThe buffer to write the data into.
offsetThe byte offset in buffer at which to begin writing data from the stream.
countThe maximum number of bytes to read.
cancellationTokenThe token to monitor for cancellation requests. The default value is P:System.Threading.CancellationToken.None.
Returns
A task that represents the asynchronous read operation. The value of the TResult parameter contains the total number of bytes read into the buffer. The result value can be less than the number of bytes requested if the number of bytes currently available is less than the requested number, or it can be 0 (zero) if the end of the stream has been reached.
Exceptions
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionoffset or count is negative.
T:System.ArgumentExceptionThe sum of offset and count is larger than the buffer length.
T:System.NotSupportedExceptionThe stream does not support reading.
T:System.ObjectDisposedExceptionThe stream has been disposed.
T:System.InvalidOperationExceptionThe stream is currently in use by a previous read operation.

Reimplemented in System.IO.FileStream, System.IO.BufferedStream, System.IO.MemoryStream, System.IO.UnmanagedMemoryStream, and System.Security.Cryptography.CryptoStream.

Definition at line 1054 of file Stream.cs.

◆ ReadByte()

virtual int System.IO.Stream.ReadByte ( )
virtual

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.

Returns
The unsigned byte cast to an Int32, or -1 if at the end of the stream.
Exceptions
T:System.NotSupportedExceptionThe stream does not support reading.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Reimplemented in System.IO.FileStream, System.IO.Pipes.PipeStream, System.IO.BufferedStream, System.IO.MemoryStream, System.IO.UnmanagedMemoryStream, and System.IO.IsolatedStorage.IsolatedStorageFileStream.

Definition at line 1297 of file Stream.cs.

◆ Seek()

abstract long System.IO.Stream.Seek ( long  offset,
SeekOrigin  origin 
)
pure virtual

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

Parameters
offsetA byte offset relative to the origin parameter.
originA value of type T:System.IO.SeekOrigin indicating the reference point used to obtain the new position.
Returns
The new position within the current stream.
Exceptions
T:System.IO.IOExceptionAn I/O error occurs.
T:System.NotSupportedExceptionThe stream does not support seeking, such as if the stream is constructed from a pipe or console output.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Implemented in System.IO.FileStream, System.IO.BufferedStream, System.IO.Pipes.PipeStream, System.Net.Security.NegotiateStream, System.IO.MemoryStream, System.Net.Security.SslStream, System.IO.UnmanagedMemoryStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, System.IO.Compression.DeflateStream, System.Net.Sockets.NetworkStream, System.Security.Cryptography.CryptoStream, and System.IO.Compression.GZipStream.

◆ SetLength()

abstract void System.IO.Stream.SetLength ( long  value)
pure virtual

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

Parameters
valueThe desired length of the current stream in bytes.
Exceptions
T:System.IO.IOExceptionAn I/O error occurs.
T:System.NotSupportedExceptionThe stream does not support both writing and seeking, such as if the stream is constructed from a pipe or console output.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Implemented in System.IO.BufferedStream, System.IO.FileStream, System.IO.Pipes.PipeStream, System.Net.Sockets.NetworkStream, System.IO.MemoryStream, System.Net.Security.NegotiateStream, System.IO.UnmanagedMemoryStream, System.Net.Security.SslStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, System.IO.Compression.DeflateStream, System.Security.Cryptography.CryptoStream, System.IO.Compression.GZipStream, and System.IO.MemoryMappedFiles.MemoryMappedViewStream.

◆ Synchronized()

static Stream System.IO.Stream.Synchronized ( Stream  stream)
static

Creates a thread-safe (synchronized) wrapper around the specified T:System.IO.Stream object.

Parameters
streamThe T:System.IO.Stream object to synchronize.
Returns
A thread-safe T:System.IO.Stream object.
Exceptions
T:System.ArgumentNullExceptionstream is null.

Definition at line 1343 of file Stream.cs.

◆ Write()

abstract void System.IO.Stream.Write ( byte []  buffer,
int  offset,
int  count 
)
pure virtual

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.

Parameters
bufferAn array of bytes. This method copies count bytes from buffer to the current stream.
offsetThe zero-based byte offset in buffer at which to begin copying bytes to the current stream.
countThe number of bytes to be written to the current stream.
Exceptions
T:System.ArgumentExceptionThe sum of offset and count is greater than the buffer length.
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionoffset or count is negative.
T:System.IO.IOExceptionAn I/O error occured, such as the specified file cannot be found.
T:System.NotSupportedExceptionThe stream does not support writing.
T:System.ObjectDisposedExceptionM:System.IO.Stream.Write(System.Byte[],System.Int32,System.Int32) was called after the stream was closed.

Implemented in System.IO.FileStream, System.IO.MemoryStream, System.Net.Security.NegotiateStream, System.IO.BufferedStream, System.Net.Security.SslStream, System.IO.UnmanagedMemoryStream, System.IO.Pipes.PipeStream, System.IO.IsolatedStorage.IsolatedStorageFileStream, System.IO.Compression.DeflateStream, System.Security.Cryptography.CryptoStream, System.Net.Sockets.NetworkStream, and System.IO.Compression.GZipStream.

◆ WriteAsync() [1/2]

Task System.IO.Stream.WriteAsync ( byte []  buffer,
int  offset,
int  count 
)

Asynchronously writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.

Parameters
bufferThe buffer to write data from.
offsetThe zero-based byte offset in buffer from which to begin copying bytes to the stream.
countThe maximum number of bytes to write.
Returns
A task that represents the asynchronous write operation.
Exceptions
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionoffset or count is negative.
T:System.ArgumentExceptionThe sum of offset and count is larger than the buffer length.
T:System.NotSupportedExceptionThe stream does not support writing.
T:System.ObjectDisposedExceptionThe stream has been disposed.
T:System.InvalidOperationExceptionThe stream is currently in use by a previous write operation.

Definition at line 1213 of file Stream.cs.

◆ WriteAsync() [2/2]

virtual Task System.IO.Stream.WriteAsync ( byte []  buffer,
int  offset,
int  count,
CancellationToken  cancellationToken 
)
virtual

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

Parameters
bufferThe buffer to write data from.
offsetThe zero-based byte offset in buffer from which to begin copying bytes to the stream.
countThe maximum number of bytes to write.
cancellationTokenThe token to monitor for cancellation requests. The default value is P:System.Threading.CancellationToken.None.
Returns
A task that represents the asynchronous write operation.
Exceptions
T:System.ArgumentNullExceptionbuffer is null.
T:System.ArgumentOutOfRangeExceptionoffset or count is negative.
T:System.ArgumentExceptionThe sum of offset and count is larger than the buffer length.
T:System.NotSupportedExceptionThe stream does not support writing.
T:System.ObjectDisposedExceptionThe stream has been disposed.
T:System.InvalidOperationExceptionThe stream is currently in use by a previous write operation.

Reimplemented in System.IO.FileStream, System.IO.BufferedStream, System.IO.MemoryStream, System.IO.UnmanagedMemoryStream, and System.Security.Cryptography.CryptoStream.

Definition at line 1235 of file Stream.cs.

◆ WriteByte()

virtual void System.IO.Stream.WriteByte ( byte  value)
virtual

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

Parameters
valueThe byte to write to the stream.
Exceptions
T:System.IO.IOExceptionAn I/O error occurs.
T:System.NotSupportedExceptionThe stream does not support writing, or the stream is already closed.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Reimplemented in System.IO.FileStream, System.IO.BufferedStream, System.IO.MemoryStream, System.IO.Pipes.PipeStream, System.IO.UnmanagedMemoryStream, and System.IO.IsolatedStorage.IsolatedStorageFileStream.

Definition at line 1329 of file Stream.cs.

Member Data Documentation

◆ Null

readonly Stream System.IO.Stream.Null = new NullStream()
static

A Stream with no backing store.

Definition at line 562 of file Stream.cs.

Property Documentation

◆ CanRead

abstract bool System.IO.Stream.CanRead
get

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

Returns
true if the stream supports reading; otherwise, false.

Definition at line 577 of file Stream.cs.

◆ CanSeek

abstract bool System.IO.Stream.CanSeek
get

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

Returns
true if the stream supports seeking; otherwise, false.

Definition at line 587 of file Stream.cs.

◆ CanTimeout

virtual bool System.IO.Stream.CanTimeout
get

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

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

Definition at line 597 of file Stream.cs.

◆ CanWrite

abstract bool System.IO.Stream.CanWrite
get

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

Returns
true if the stream supports writing; otherwise, false.

Definition at line 610 of file Stream.cs.

◆ Length

abstract long System.IO.Stream.Length
get

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

Returns
A long value representing the length of the stream in bytes.
Exceptions
T:System.NotSupportedExceptionA class derived from Stream does not support seeking.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Definition at line 621 of file Stream.cs.

◆ Position

abstract long System.IO.Stream.Position
getset

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

Returns
The current position within the stream.
Exceptions
T:System.IO.IOExceptionAn I/O error occurs.
T:System.NotSupportedExceptionThe stream does not support seeking.
T:System.ObjectDisposedExceptionMethods were called after the stream was closed.

Definition at line 633 of file Stream.cs.

◆ ReadTimeout

virtual int System.IO.Stream.ReadTimeout
getset

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

Returns
A value, in miliseconds, that determines how long the stream will attempt to read before timing out.
Exceptions
T:System.InvalidOperationExceptionThe P:System.IO.Stream.ReadTimeout method always throws an T:System.InvalidOperationException.

Definition at line 646 of file Stream.cs.

◆ WriteTimeout

virtual int System.IO.Stream.WriteTimeout
getset

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

Returns
A value, in miliseconds, that determines how long the stream will attempt to write before timing out.
Exceptions
T:System.InvalidOperationExceptionThe P:System.IO.Stream.WriteTimeout method always throws an T:System.InvalidOperationException.

Definition at line 665 of file Stream.cs.


The documentation for this class was generated from the following file: