C# Class Redzen.IO.NonClosingStreamWrapper

Wraps a stream and prevents calls to Close() and Dispose() from being made on it. This is useful for other classes that wrap a stream but have no option to leave the wrapped stream open upon Dispose(), e.g. CryptoStream and BinaryWriter. Note. Later versions of the .NET framework have added a 'leaveOpen' option to some classes. Check before using this class.
Inheritance: Stream
Afficher le fichier Open project: colgreen/Redzen

Méthodes publiques

Méthode Description
BeginRead ( byte buffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous read operation.

BeginWrite ( byte buffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult

Begins an asynchronous write operation.

Close ( ) : void

This method is not proxied to the underlying stream; instead, the wrapper is marked as unusable for other (non-close/Dispose) operations. The underlying stream is flushed if the wrapper wasn't closed before this call.

CreateObjRef ( Type requestedType ) : ObjRef

Not implemented. Throws NotSupportedException.

EndRead ( IAsyncResult asyncResult ) : int

Waits for the pending asynchronous read to complete.

EndWrite ( IAsyncResult asyncResult ) : void

Ends an asynchronous write operation.

Flush ( ) : void

Flushes the underlying stream.

InitializeLifetimeService ( ) : object

Not implemented. Throws NotSupportedException.

NonClosingStreamWrapper ( Stream stream ) : System

Construct with the provided stream to be wrapped.

Read ( byte buffer, int offset, int count ) : int

Reads a sequence of bytes from the underlying stream and advances the position within the stream by the number of bytes read.

ReadByte ( ) : int

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.

Seek ( long offset, SeekOrigin origin ) : long

Sets the position within the current stream.

SetLength ( long value ) : void

Sets the length of the underlying stream.

Write ( byte buffer, int offset, int count ) : void

Writes a sequence of bytes to the underlying stream and advances the current position within the stream by the number of bytes written.

WriteByte ( byte value ) : void

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

Private Methods

Méthode Description
CheckClosed ( ) : void

Throws an InvalidOperationException if the wrapper is closed.

Method Details

BeginRead() public méthode

Begins an asynchronous read operation.
public BeginRead ( byte buffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult
buffer byte The buffer to read the data into.
offset int The byte offset in buffer at which to begin writing data read from the stream.
count int The maximum number of bytes to read.
callback AsyncCallback An optional asynchronous callback, to be called when the read is complete.
state object A user-provided object that distinguishes this particular asynchronous read request from other requests.
Résultat IAsyncResult

BeginWrite() public méthode

Begins an asynchronous write operation.
public BeginWrite ( byte buffer, int offset, int count, AsyncCallback callback, object state ) : IAsyncResult
buffer byte The buffer to write data from.
offset int The byte offset in buffer from which to begin writing.
count int The maximum number of bytes to write.
callback AsyncCallback An optional asynchronous callback, to be called when the write is complete.
state object A user-provided object that distinguishes this particular asynchronous write request from other requests.
Résultat IAsyncResult

Close() public méthode

This method is not proxied to the underlying stream; instead, the wrapper is marked as unusable for other (non-close/Dispose) operations. The underlying stream is flushed if the wrapper wasn't closed before this call.
public Close ( ) : void
Résultat void

CreateObjRef() public méthode

Not implemented. Throws NotSupportedException.
public CreateObjRef ( Type requestedType ) : ObjRef
requestedType System.Type The Type of the object that the new ObjRef will reference.
Résultat System.Runtime.Remoting.ObjRef

EndRead() public méthode

Waits for the pending asynchronous read to complete.
public EndRead ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult The reference to the pending asynchronous request to finish.
Résultat int

EndWrite() public méthode

Ends an asynchronous write operation.
public EndWrite ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult A reference to the outstanding asynchronous I/O request.
Résultat void

Flush() public méthode

Flushes the underlying stream.
public Flush ( ) : void
Résultat void

InitializeLifetimeService() public méthode

Not implemented. Throws NotSupportedException.
public InitializeLifetimeService ( ) : object
Résultat object

NonClosingStreamWrapper() public méthode

Construct with the provided stream to be wrapped.
public NonClosingStreamWrapper ( Stream stream ) : System
stream Stream The stream to be wrapped.
Résultat System

Read() public méthode

Reads a sequence of bytes from the underlying stream and advances the position within the stream by the number of bytes read.
public Read ( byte buffer, int offset, int count ) : int
buffer byte 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 underlying source.
offset int The zero-based byte offset in buffer at which to begin storing the data /// read from the underlying stream.
count int The maximum number of bytes to be read from the underlying stream.
Résultat int

ReadByte() public méthode

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.
public ReadByte ( ) : int
Résultat int

Seek() public méthode

Sets the position within the current stream.
public Seek ( long offset, SeekOrigin origin ) : long
offset long A byte offset relative to the origin parameter.
origin SeekOrigin A value of type SeekOrigin indicating the reference point used to obtain the new position.
Résultat long

SetLength() public méthode

Sets the length of the underlying stream.
public SetLength ( long value ) : void
value long The desired length of the underlying stream in bytes.
Résultat void

Write() public méthode

Writes a sequence of bytes to the underlying stream and advances the current position within the stream by the number of bytes written.
public Write ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes. This method copies count bytes from buffer to the underlying stream.
offset int The zero-based byte offset in buffer at which to begin copying bytes to the underlying stream.
count int The number of bytes to be written to the underlying stream.
Résultat void

WriteByte() public méthode

Writes a byte to the current position in the stream and advances the position within the stream by one byte.
public WriteByte ( byte value ) : void
value byte The byte to write to the stream.
Résultat void