Class ReadOnlyStream
A wrapper stream that provides read-only access to an underlying stream.
public class ReadOnlyStream : Stream, IDisposable
- Inheritance
-
ReadOnlyStream
- Implements
- Inherited Members
- Extension Methods
Constructors
ReadOnlyStream(Stream)
Initializes a new instance of the ReadOnlyStream class.
public ReadOnlyStream(Stream innerStream)
Parameters
innerStream
StreamThe underlying stream to wrap.
Exceptions
- ArgumentNullException
Thrown when
innerStream
isnull
.
Properties
CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports reading.
public override bool CanRead { get; }
Property Value
- bool
true if the stream supports reading; otherwise, false.
CanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeking.
public override bool CanSeek { get; }
Property Value
- bool
true if the stream supports seeking; otherwise, false.
CanTimeout
Gets a value that determines whether the current stream can time out.
public override bool CanTimeout { get; }
Property Value
- bool
A value that determines whether the current stream can time out.
CanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writing.
public override bool CanWrite { get; }
Property Value
- bool
true if the stream supports writing; otherwise, false.
Remarks
This stream is read-only and always returns false
.
Length
When overridden in a derived class, gets the length in bytes of the stream.
public override long Length { get; }
Property Value
- long
A long value representing the length of the stream in bytes.
Position
When overridden in a derived class, gets or sets the position within the current stream.
public override long Position { get; set; }
Property Value
- long
The current position within the stream.
ReadTimeout
Gets or sets a value, in milliseconds, that determines how long the stream will attempt to read before timing out.
public override int ReadTimeout { get; set; }
Property Value
- int
A value, in milliseconds, that determines how long the stream will attempt to read before timing out.
Exceptions
WriteTimeout
Gets or sets a value, in milliseconds, that determines how long the stream will attempt to write before timing out.
public override int WriteTimeout { get; set; }
Property Value
- int
A value, in milliseconds, that determines how long the stream will attempt to write before timing out.
Remarks
Setting or getting this property is not supported for a read-only stream.
Exceptions
- InvalidOperationException
- NotSupportedException
Always thrown when accessing this property.
Methods
Dispose(bool)
Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
protected override void Dispose(bool disposing)
Parameters
disposing
booltrue to release both managed and unmanaged resources; false to release only unmanaged resources.
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.
public override void Flush()
Remarks
Flushing of a read-only stream is not supported.
Exceptions
- NotSupportedException
Always thrown when called.
Read(byte[], int, int)
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.
public override int Read(byte[] buffer, int offset, int count)
Parameters
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 current source.
offset
intThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
count
intThe maximum number of bytes to be read from the current stream.
Returns
- int
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.
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.
public override int Read(SpanByte buffer)
Parameters
buffer
SpanByteA region of memory. When this method returns, the contents of this region are replaced by the bytes read from the current source.
Returns
- int
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.
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.
public override int ReadByte()
Returns
- int
The unsigned byte cast to an Int32, or -1 if at the end of the stream.
Seek(long, SeekOrigin)
When overridden in a derived class, sets the position within the current stream.
public override long Seek(long offset, SeekOrigin origin)
Parameters
offset
longA byte offset relative to the origin parameter.
origin
SeekOriginA value of type SeekOrigin indicating the reference point used to obtain the new position.
Returns
- long
The new position within the current stream.
SetLength(long)
When overridden in a derived class, sets the length of the current stream.
public override void SetLength(long value)
Parameters
value
longThe desired length of the current stream in bytes.
Remarks
Setting the length of a read-only stream is not supported.
Exceptions
- NotSupportedException
Always thrown when called.
Write(byte[], int, int)
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.
public override void Write(byte[] buffer, int offset, int count)
Parameters
buffer
byte[]An array of bytes. This method copies count bytes from buffer to the current stream.
offset
intThe zero-based byte offset in buffer at which to begin copying bytes to the current stream.
count
intThe number of bytes to be written to the current stream.
Remarks
Writing to a read-only stream is not supported.
Exceptions
- NotSupportedException
Always thrown when called.
WriteByte(byte)
Writes a byte to the current position in the stream and advances the position within the stream by one byte.
public override void WriteByte(byte value)
Parameters
value
byteThe byte to write to the stream.
Remarks
Writing a byte to a read-only stream is not supported.
Exceptions
- NotSupportedException
Always thrown when called.