Wraps a stream and grants access only to a subsection Modified from code found here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/c409b63b-37df-40ca-9322-458ffe06ea48/how-to-access-part-of-a-filestream-or-memorystream?forum=netfxbcl
More...
|
| SubStream (Stream baseStream, long startPosition, long length, bool ownsStream=false) |
|
| SubStream (Stream baseStream, long length, bool ownsStream=false) |
|
override int | ReadByte () |
|
override int | Read (byte[] buffer, int offset, int count) |
|
override void | Flush () |
|
override long | Seek (long offset, SeekOrigin origin) |
|
override void | SetLength (long value) |
|
override void | Write (byte[] buffer, int offset, int count) |
|
|
override void | Dispose (bool disposing) |
|
◆ SubStream() [1/2]
BGC.IO.SubStream.SubStream |
( |
Stream |
baseStream, |
|
|
long |
startPosition, |
|
|
long |
length, |
|
|
bool |
ownsStream = false |
|
) |
| |
|
inline |
Definition at line 68 of file SubStream.cs.
76 throw new ArgumentNullException(nameof(
baseStream));
81 throw new ArgumentException(
"Can't read BaseStream");
84 if (startPosition < 0 || startPosition + length >
baseStream.Length)
104 throw new NotSupportedException(
"BaseStream can't seek backwards to StartPosition");
109 const int BUFFER_SIZE = 512;
110 byte[] buffer =
new byte[BUFFER_SIZE];
112 while (deltaPosition > 0)
117 count: deltaPosition < BUFFER_SIZE ? (
int)deltaPosition : BUFFER_SIZE);
119 deltaPosition -= read;
123 throw new Exception(
"Failed to read past required samples");
readonly long startPosition
◆ SubStream() [2/2]
BGC.IO.SubStream.SubStream |
( |
Stream |
baseStream, |
|
|
long |
length, |
|
|
bool |
ownsStream = false |
|
) |
| |
|
inline |
Definition at line 130 of file SubStream.cs.
137 throw new ArgumentNullException(
"baseStream");
142 throw new ArgumentException(
"Can't read base stream");
readonly long startPosition
◆ CheckDisposed()
void BGC.IO.SubStream.CheckDisposed |
( |
| ) |
|
|
inlineprivate |
Definition at line 225 of file SubStream.cs.
229 throw new ObjectDisposedException(GetType().Name);
◆ Dispose()
override void BGC.IO.SubStream.Dispose |
( |
bool |
disposing | ) |
|
|
inlineprotected |
Definition at line 236 of file SubStream.cs.
238 base.Dispose(disposing);
readonly long startPosition
◆ Flush()
override void BGC.IO.SubStream.Flush |
( |
| ) |
|
|
inline |
◆ Read()
override int BGC.IO.SubStream.Read |
( |
byte [] |
buffer, |
|
|
int |
offset, |
|
|
int |
count |
|
) |
| |
|
inline |
◆ ReadByte()
override int BGC.IO.SubStream.ReadByte |
( |
| ) |
|
|
inline |
◆ Seek()
override long BGC.IO.SubStream.Seek |
( |
long |
offset, |
|
|
SeekOrigin |
origin |
|
) |
| |
|
inline |
Definition at line 186 of file SubStream.cs.
References BGC.Mathematics.GeneralMath.Clamp().
190 throw new NotSupportedException(
"BaseStream does not support seeking");
195 case SeekOrigin.Begin:
201 case SeekOrigin.Current:
213 throw new NotSupportedException($
"SeekOrigin not implemented: {origin}");
readonly long startPosition
static decimal Clamp(decimal value, decimal min, decimal max)
◆ SetLength()
override void BGC.IO.SubStream.SetLength |
( |
long |
value | ) |
|
◆ Write()
override void BGC.IO.SubStream.Write |
( |
byte [] |
buffer, |
|
|
int |
offset, |
|
|
int |
count |
|
) |
| |
◆ _disposed
bool BGC.IO.SubStream._disposed = false |
|
private |
◆ baseStream
Stream BGC.IO.SubStream.baseStream = null |
|
private |
◆ length
readonly long BGC.IO.SubStream.length |
|
private |
◆ ownsStream
readonly bool BGC.IO.SubStream.ownsStream |
|
private |
◆ position
long BGC.IO.SubStream.position = 0 |
|
private |
◆ startPosition
readonly long BGC.IO.SubStream.startPosition |
|
private |
◆ CanRead
override bool BGC.IO.SubStream.CanRead |
|
get |
◆ CanSeek
override bool BGC.IO.SubStream.CanSeek |
|
get |
◆ CanWrite
override bool BGC.IO.SubStream.CanWrite |
|
get |
◆ Length
override long BGC.IO.SubStream.Length |
|
get |
◆ Position
override long BGC.IO.SubStream.Position |
|
getset |
The documentation for this class was generated from the following file: