Class StreamSegment
Represents a portion of the underlying stream in the its of the read-onyl view.
Namespace: DotNext.IO
Assembly: DotNext.dll
Syntax
public sealed class StreamSegment : Stream
Remarks
The segmentation is supported only for seekable streams.
Constructors
| Improve this Doc View SourceStreamSegment(Stream, Boolean)
Initializes a new segment of the specified stream.
Declaration
public StreamSegment(Stream stream, bool leaveOpen = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | The underlying stream represented by the segment. |
| Boolean | leaveOpen | true to leave |
Properties
| Improve this Doc View SourceBaseStream
Gets underlying stream.
Declaration
public Stream BaseStream { get; }
Property Value
| Type | Description |
|---|---|
| Stream |
CanRead
Gets a value indicating whether the current stream supports reading.
Declaration
public override bool CanRead { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | true if the stream supports reading; otherwise, false. |
CanSeek
Gets a value indicating whether the current stream supports seeking.
Declaration
public override bool CanSeek { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | true if the stream supports seeking; otherwise, false. |
CanTimeout
Gets a value that determines whether the current stream can time out.
Declaration
public override bool CanTimeout { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | A value that determines whether the current stream can time out. |
CanWrite
Gets a value indicating whether the current stream supports writing.
Declaration
public override bool CanWrite { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | Always false. |
Length
Gets the length in bytes of the stream.
Declaration
public override long Length { get; }
Property Value
| Type | Description |
|---|---|
| Int64 |
Position
Gets or sets relative position from the beginning of this segment.
Declaration
public override long Position { get; set; }
Property Value
| Type | Description |
|---|---|
| Int64 |
ReadTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to read before timing out.
Declaration
public override int ReadTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| Int32 | A value, in miliseconds, that determines how long the stream will attempt to read before timing out. |
WriteTimeout
Gets or sets a value, in miliseconds, that determines how long the stream will attempt to write before timing out.
Declaration
public override int WriteTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| Int32 | A value, in miliseconds, that determines how long the stream will attempt to write before timing out. |
Methods
| Improve this Doc View SourceAdjust(Int64, Int64)
Establishes segment bounds.
Declaration
public void Adjust(long offset, long length)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | offset | The offset in the underlying stream. |
| Int64 | length | The length of the segment. |
Remarks
This method modifies
Dispose(Boolean)
Releases the unmanaged resources used by this stream and optionally releases the managed resources.
Declaration
protected override void Dispose(bool disposing)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | disposing | true to release both managed and unmanaged resources; false to release only unmanaged resources. |
Flush()
Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Declaration
public override void Flush()
FlushAsync(CancellationToken)
Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.
Declaration
public override Task FlushAsync(CancellationToken token = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | token | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task | A task that represents the asynchronous flush operation. |
Read(Byte[], Int32, Int32)
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | Contains the specified byte array with the values between |
| Int32 | offset | The zero-based byte offset in buffer at which to begin storing the data read from the current stream. |
| Int32 | count | The maximum number of bytes to be read from the current stream. |
Returns
| Type | Description |
|---|---|
| Int32 | The total number of bytes read into the buffer. |
ReadAsync(Byte[], Int32, Int32, CancellationToken)
Asynchronously reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
Declaration
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken token = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | Contains the specified byte array with the values between |
| Int32 | offset | The zero-based byte offset in buffer at which to begin storing the data read from the current stream. |
| Int32 | count | The maximum number of bytes to be read from the current stream. |
| CancellationToken | token | The token to monitor for cancellation requests. |
Returns
| Type | Description |
|---|---|
| Task<Int32> | The total number of bytes read into the buffer. |
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.
Declaration
public override int ReadByte()
Returns
| Type | Description |
|---|---|
| Int32 | The unsigned byte cast to an Int32, or -1 if at the end of the stream. |
Seek(Int64, SeekOrigin)
Sets the position within the current stream.
Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | offset | A byte offset relative to the origin parameter. |
| SeekOrigin | origin | The reference point used to obtain the new position. |
Returns
| Type | Description |
|---|---|
| Int64 | The new position within the current stream. |
SetLength(Int64)
Sets the length of the current stream.
Declaration
public override void SetLength(long value)
Parameters
| Type | Name | Description |
|---|---|---|
| Int64 | value | The desired length of the current stream in bytes. |
Write(Byte[], Int32, Int32)
This method is not supported.
Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | |
| Int32 | offset | |
| Int32 | count |
WriteAsync(Byte[], Int32, Int32, CancellationToken)
This method is not supported.
Declaration
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token = null)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte[] | buffer | |
| Int32 | offset | |
| Int32 | count | |
| CancellationToken | token |
Returns
| Type | Description |
|---|---|
| Task |
WriteByte(Byte)
This method is not supported.
Declaration
public override void WriteByte(byte value)
Parameters
| Type | Name | Description |
|---|---|---|
| Byte | value | The byte to write to the stream. |