mscorlib(4.0.0.0) API with additions
MemoryStream.cs
4 using System.Threading;
6 
7 namespace System.IO
8 {
10  [Serializable]
11  [ComVisible(true)]
12  [__DynamicallyInvokable]
13  public class MemoryStream : Stream
14  {
15  private byte[] _buffer;
16 
17  private int _origin;
18 
19  private int _position;
20 
21  private int _length;
22 
23  private int _capacity;
24 
25  private bool _expandable;
26 
27  private bool _writable;
28 
29  private bool _exposable;
30 
31  private bool _isOpen;
32 
33  [NonSerialized]
34  private Task<int> _lastReadTask;
35 
36  private const int MemStreamMaxLength = int.MaxValue;
37 
41  [__DynamicallyInvokable]
42  public override bool CanRead
43  {
44  [__DynamicallyInvokable]
45  get
46  {
47  return _isOpen;
48  }
49  }
50 
54  [__DynamicallyInvokable]
55  public override bool CanSeek
56  {
57  [__DynamicallyInvokable]
58  get
59  {
60  return _isOpen;
61  }
62  }
63 
67  [__DynamicallyInvokable]
68  public override bool CanWrite
69  {
70  [__DynamicallyInvokable]
71  get
72  {
73  return _writable;
74  }
75  }
76 
83  [__DynamicallyInvokable]
84  public virtual int Capacity
85  {
86  [__DynamicallyInvokable]
87  get
88  {
89  if (!_isOpen)
90  {
91  __Error.StreamIsClosed();
92  }
93  return _capacity - _origin;
94  }
95  [__DynamicallyInvokable]
96  set
97  {
98  if (value < Length)
99  {
100  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_SmallCapacity"));
101  }
102  if (!_isOpen)
103  {
104  __Error.StreamIsClosed();
105  }
106  if (!_expandable && value != Capacity)
107  {
108  __Error.MemoryStreamNotExpandable();
109  }
110  if (!_expandable || value == _capacity)
111  {
112  return;
113  }
114  if (value > 0)
115  {
116  byte[] array = new byte[value];
117  if (_length > 0)
118  {
119  Buffer.InternalBlockCopy(_buffer, 0, array, 0, _length);
120  }
121  _buffer = array;
122  }
123  else
124  {
125  _buffer = null;
126  }
127  _capacity = value;
128  }
129  }
130 
134  [__DynamicallyInvokable]
135  public override long Length
136  {
137  [__DynamicallyInvokable]
138  get
139  {
140  if (!_isOpen)
141  {
142  __Error.StreamIsClosed();
143  }
144  return _length - _origin;
145  }
146  }
147 
152  [__DynamicallyInvokable]
153  public override long Position
154  {
155  [__DynamicallyInvokable]
156  get
157  {
158  if (!_isOpen)
159  {
160  __Error.StreamIsClosed();
161  }
162  return _position - _origin;
163  }
164  [__DynamicallyInvokable]
165  set
166  {
167  if (value < 0)
168  {
169  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
170  }
171  if (!_isOpen)
172  {
173  __Error.StreamIsClosed();
174  }
175  if (value > int.MaxValue)
176  {
177  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength"));
178  }
179  _position = _origin + (int)value;
180  }
181  }
182 
184  [__DynamicallyInvokable]
185  public MemoryStream()
186  : this(0)
187  {
188  }
189 
194  [__DynamicallyInvokable]
195  public MemoryStream(int capacity)
196  {
197  if (capacity < 0)
198  {
199  throw new ArgumentOutOfRangeException("capacity", Environment.GetResourceString("ArgumentOutOfRange_NegativeCapacity"));
200  }
201  _buffer = new byte[capacity];
202  _capacity = capacity;
203  _expandable = true;
204  _writable = true;
205  _exposable = true;
206  _origin = 0;
207  _isOpen = true;
208  }
209 
214  [__DynamicallyInvokable]
215  public MemoryStream(byte[] buffer)
216  : this(buffer, writable: true)
217  {
218  }
219 
225  [__DynamicallyInvokable]
226  public MemoryStream(byte[] buffer, bool writable)
227  {
228  if (buffer == null)
229  {
230  throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
231  }
232  _buffer = buffer;
233  _length = (_capacity = buffer.Length);
234  _writable = writable;
235  _exposable = false;
236  _origin = 0;
237  _isOpen = true;
238  }
239 
249  [__DynamicallyInvokable]
250  public MemoryStream(byte[] buffer, int index, int count)
251  : this(buffer, index, count, writable: true, publiclyVisible: false)
252  {
253  }
254 
265  [__DynamicallyInvokable]
266  public MemoryStream(byte[] buffer, int index, int count, bool writable)
267  : this(buffer, index, count, writable, publiclyVisible: false)
268  {
269  }
270 
283  [__DynamicallyInvokable]
284  public MemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible)
285  {
286  if (buffer == null)
287  {
288  throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
289  }
290  if (index < 0)
291  {
292  throw new ArgumentOutOfRangeException("index", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
293  }
294  if (count < 0)
295  {
296  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
297  }
298  if (buffer.Length - index < count)
299  {
300  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
301  }
302  _buffer = buffer;
303  _origin = (_position = index);
304  _length = (_capacity = index + count);
305  _writable = writable;
306  _exposable = publiclyVisible;
307  _expandable = false;
308  _isOpen = true;
309  }
310 
311  private void EnsureWriteable()
312  {
313  if (!CanWrite)
314  {
315  __Error.WriteNotSupported();
316  }
317  }
318 
322  [__DynamicallyInvokable]
323  protected override void Dispose(bool disposing)
324  {
325  try
326  {
327  if (disposing)
328  {
329  _isOpen = false;
330  _writable = false;
331  _expandable = false;
332  _lastReadTask = null;
333  }
334  }
335  finally
336  {
337  base.Dispose(disposing);
338  }
339  }
340 
341  private bool EnsureCapacity(int value)
342  {
343  if (value < 0)
344  {
345  throw new IOException(Environment.GetResourceString("IO.IO_StreamTooLong"));
346  }
347  if (value > _capacity)
348  {
349  int num = value;
350  if (num < 256)
351  {
352  num = 256;
353  }
354  if (num < _capacity * 2)
355  {
356  num = _capacity * 2;
357  }
358  if ((uint)(_capacity * 2) > 2147483591u)
359  {
360  num = ((value > 2147483591) ? value : 2147483591);
361  }
362  Capacity = num;
363  return true;
364  }
365  return false;
366  }
367 
369  [__DynamicallyInvokable]
370  public override void Flush()
371  {
372  }
373 
378  [ComVisible(false)]
379  [__DynamicallyInvokable]
380  [HostProtection(SecurityAction.LinkDemand, ExternalThreading = true)]
381  public override Task FlushAsync(CancellationToken cancellationToken)
382  {
383  if (cancellationToken.IsCancellationRequested)
384  {
385  return Task.FromCancellation(cancellationToken);
386  }
387  try
388  {
389  Flush();
390  return Task.CompletedTask;
391  }
392  catch (Exception exception)
393  {
394  return Task.FromException(exception);
395  }
396  }
397 
401  public virtual byte[] GetBuffer()
402  {
403  if (!_exposable)
404  {
405  throw new UnauthorizedAccessException(Environment.GetResourceString("UnauthorizedAccess_MemStreamBuffer"));
406  }
407  return _buffer;
408  }
409 
414  [__DynamicallyInvokable]
415  public virtual bool TryGetBuffer(out ArraySegment<byte> buffer)
416  {
417  if (!_exposable)
418  {
419  buffer = default(ArraySegment<byte>);
420  return false;
421  }
422  buffer = new ArraySegment<byte>(_buffer, _origin, _length - _origin);
423  return true;
424  }
425 
426  internal byte[] InternalGetBuffer()
427  {
428  return _buffer;
429  }
430 
431  [FriendAccessAllowed]
432  internal void InternalGetOriginAndLength(out int origin, out int length)
433  {
434  if (!_isOpen)
435  {
436  __Error.StreamIsClosed();
437  }
438  origin = _origin;
439  length = _length;
440  }
441 
442  internal int InternalGetPosition()
443  {
444  if (!_isOpen)
445  {
446  __Error.StreamIsClosed();
447  }
448  return _position;
449  }
450 
451  internal int InternalReadInt32()
452  {
453  if (!_isOpen)
454  {
455  __Error.StreamIsClosed();
456  }
457  int num = _position += 4;
458  if (num > _length)
459  {
460  _position = _length;
461  __Error.EndOfFile();
462  }
463  return _buffer[num - 4] | (_buffer[num - 3] << 8) | (_buffer[num - 2] << 16) | (_buffer[num - 1] << 24);
464  }
465 
466  internal int InternalEmulateRead(int count)
467  {
468  if (!_isOpen)
469  {
470  __Error.StreamIsClosed();
471  }
472  int num = _length - _position;
473  if (num > count)
474  {
475  num = count;
476  }
477  if (num < 0)
478  {
479  num = 0;
480  }
481  _position += num;
482  return num;
483  }
484 
497  [__DynamicallyInvokable]
498  public override int Read([In] [Out] byte[] buffer, int offset, int count)
499  {
500  if (buffer == null)
501  {
502  throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
503  }
504  if (offset < 0)
505  {
506  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
507  }
508  if (count < 0)
509  {
510  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
511  }
512  if (buffer.Length - offset < count)
513  {
514  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
515  }
516  if (!_isOpen)
517  {
518  __Error.StreamIsClosed();
519  }
520  int num = _length - _position;
521  if (num > count)
522  {
523  num = count;
524  }
525  if (num <= 0)
526  {
527  return 0;
528  }
529  if (num <= 8)
530  {
531  int num2 = num;
532  while (--num2 >= 0)
533  {
534  buffer[offset + num2] = _buffer[_position + num2];
535  }
536  }
537  else
538  {
539  Buffer.InternalBlockCopy(_buffer, _position, buffer, offset, num);
540  }
541  _position += num;
542  return num;
543  }
544 
559  [ComVisible(false)]
560  [__DynamicallyInvokable]
561  [HostProtection(SecurityAction.LinkDemand, ExternalThreading = true)]
562  public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
563  {
564  if (buffer == null)
565  {
566  throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
567  }
568  if (offset < 0)
569  {
570  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
571  }
572  if (count < 0)
573  {
574  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
575  }
576  if (buffer.Length - offset < count)
577  {
578  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
579  }
580  if (cancellationToken.IsCancellationRequested)
581  {
582  return Task.FromCancellation<int>(cancellationToken);
583  }
584  try
585  {
586  int num = Read(buffer, offset, count);
587  Task<int> lastReadTask = _lastReadTask;
588  return (lastReadTask != null && lastReadTask.Result == num) ? lastReadTask : (_lastReadTask = Task.FromResult(num));
589  }
590  catch (OperationCanceledException exception)
591  {
592  return Task.FromCancellation<int>(exception);
593  }
594  catch (Exception exception2)
595  {
596  return Task.FromException<int>(exception2);
597  }
598  }
599 
603  [__DynamicallyInvokable]
604  public override int ReadByte()
605  {
606  if (!_isOpen)
607  {
608  __Error.StreamIsClosed();
609  }
610  if (_position >= _length)
611  {
612  return -1;
613  }
614  return _buffer[_position++];
615  }
616 
628  [__DynamicallyInvokable]
629  public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
630  {
631  if (destination == null)
632  {
633  throw new ArgumentNullException("destination");
634  }
635  if (bufferSize <= 0)
636  {
637  throw new ArgumentOutOfRangeException("bufferSize", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
638  }
639  if (!CanRead && !CanWrite)
640  {
641  throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_StreamClosed"));
642  }
643  if (!destination.CanRead && !destination.CanWrite)
644  {
645  throw new ObjectDisposedException("destination", Environment.GetResourceString("ObjectDisposed_StreamClosed"));
646  }
647  if (!CanRead)
648  {
649  throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnreadableStream"));
650  }
651  if (!destination.CanWrite)
652  {
653  throw new NotSupportedException(Environment.GetResourceString("NotSupported_UnwritableStream"));
654  }
655  if (GetType() != typeof(MemoryStream))
656  {
657  return base.CopyToAsync(destination, bufferSize, cancellationToken);
658  }
659  if (cancellationToken.IsCancellationRequested)
660  {
661  return Task.FromCancellation(cancellationToken);
662  }
663  int position = _position;
664  int count = InternalEmulateRead(_length - _position);
665  MemoryStream memoryStream = destination as MemoryStream;
666  if (memoryStream == null)
667  {
668  return destination.WriteAsync(_buffer, position, count, cancellationToken);
669  }
670  try
671  {
672  memoryStream.Write(_buffer, position, count);
673  return Task.CompletedTask;
674  }
675  catch (Exception exception)
676  {
677  return Task.FromException(exception);
678  }
679  }
680 
691  [__DynamicallyInvokable]
692  public override long Seek(long offset, SeekOrigin loc)
693  {
694  if (!_isOpen)
695  {
696  __Error.StreamIsClosed();
697  }
698  if (offset > int.MaxValue)
699  {
700  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_StreamLength"));
701  }
702  switch (loc)
703  {
704  case SeekOrigin.Begin:
705  {
706  int num3 = _origin + (int)offset;
707  if (offset < 0 || num3 < _origin)
708  {
709  throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin"));
710  }
711  _position = num3;
712  break;
713  }
714  case SeekOrigin.Current:
715  {
716  int num2 = _position + (int)offset;
717  if (_position + offset < _origin || num2 < _origin)
718  {
719  throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin"));
720  }
721  _position = num2;
722  break;
723  }
724  case SeekOrigin.End:
725  {
726  int num = _length + (int)offset;
727  if (_length + offset < _origin || num < _origin)
728  {
729  throw new IOException(Environment.GetResourceString("IO.IO_SeekBeforeBegin"));
730  }
731  _position = num;
732  break;
733  }
734  default:
735  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidSeekOrigin"));
736  }
737  return _position;
738  }
739 
745  [__DynamicallyInvokable]
746  public override void SetLength(long value)
747  {
748  if (value < 0 || value > int.MaxValue)
749  {
750  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength"));
751  }
752  EnsureWriteable();
753  if (value > int.MaxValue - _origin)
754  {
755  throw new ArgumentOutOfRangeException("value", Environment.GetResourceString("ArgumentOutOfRange_StreamLength"));
756  }
757  int num = _origin + (int)value;
758  if (!EnsureCapacity(num) && num > _length)
759  {
760  Array.Clear(_buffer, _length, num - _length);
761  }
762  _length = num;
763  if (_position > num)
764  {
765  _position = num;
766  }
767  }
768 
771  [__DynamicallyInvokable]
772  public virtual byte[] ToArray()
773  {
774  byte[] array = new byte[_length - _origin];
775  Buffer.InternalBlockCopy(_buffer, _origin, array, 0, _length - _origin);
776  return array;
777  }
778 
792  [__DynamicallyInvokable]
793  public override void Write(byte[] buffer, int offset, int count)
794  {
795  if (buffer == null)
796  {
797  throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
798  }
799  if (offset < 0)
800  {
801  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
802  }
803  if (count < 0)
804  {
805  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
806  }
807  if (buffer.Length - offset < count)
808  {
809  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
810  }
811  if (!_isOpen)
812  {
813  __Error.StreamIsClosed();
814  }
815  EnsureWriteable();
816  int num = _position + count;
817  if (num < 0)
818  {
819  throw new IOException(Environment.GetResourceString("IO.IO_StreamTooLong"));
820  }
821  if (num > _length)
822  {
823  bool flag = _position > _length;
824  if (num > _capacity && EnsureCapacity(num))
825  {
826  flag = false;
827  }
828  if (flag)
829  {
830  Array.Clear(_buffer, _length, num - _length);
831  }
832  _length = num;
833  }
834  if (count <= 8 && buffer != _buffer)
835  {
836  int num2 = count;
837  while (--num2 >= 0)
838  {
839  _buffer[_position + num2] = buffer[offset + num2];
840  }
841  }
842  else
843  {
844  Buffer.InternalBlockCopy(buffer, offset, _buffer, _position, count);
845  }
846  _position = num;
847  }
848 
863  [ComVisible(false)]
864  [__DynamicallyInvokable]
865  [HostProtection(SecurityAction.LinkDemand, ExternalThreading = true)]
866  public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
867  {
868  if (buffer == null)
869  {
870  throw new ArgumentNullException("buffer", Environment.GetResourceString("ArgumentNull_Buffer"));
871  }
872  if (offset < 0)
873  {
874  throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
875  }
876  if (count < 0)
877  {
878  throw new ArgumentOutOfRangeException("count", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
879  }
880  if (buffer.Length - offset < count)
881  {
882  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOffLen"));
883  }
884  if (cancellationToken.IsCancellationRequested)
885  {
886  return Task.FromCancellation(cancellationToken);
887  }
888  try
889  {
890  Write(buffer, offset, count);
891  return Task.CompletedTask;
892  }
893  catch (OperationCanceledException exception)
894  {
895  return Task.FromCancellation<VoidTaskResult>(exception);
896  }
897  catch (Exception exception2)
898  {
899  return Task.FromException(exception2);
900  }
901  }
902 
907  [__DynamicallyInvokable]
908  public override void WriteByte(byte value)
909  {
910  if (!_isOpen)
911  {
912  __Error.StreamIsClosed();
913  }
914  EnsureWriteable();
915  if (_position >= _length)
916  {
917  int num = _position + 1;
918  bool flag = _position > _length;
919  if (num >= _capacity && EnsureCapacity(num))
920  {
921  flag = false;
922  }
923  if (flag)
924  {
925  Array.Clear(_buffer, _length, _position - _length);
926  }
927  _length = num;
928  }
929  _buffer[_position++] = value;
930  }
931 
937  [__DynamicallyInvokable]
938  public virtual void WriteTo(Stream stream)
939  {
940  if (stream == null)
941  {
942  throw new ArgumentNullException("stream", Environment.GetResourceString("ArgumentNull_Stream"));
943  }
944  if (!_isOpen)
945  {
946  __Error.StreamIsClosed();
947  }
948  stream.Write(_buffer, _origin, _length - _origin);
949  }
950  }
951 }
override bool CanRead
Gets a value indicating whether the current stream supports reading.
Definition: MemoryStream.cs:43
MemoryStream(byte[] buffer)
Initializes a new non-resizable instance of the T:System.IO.MemoryStream class based on the specified...
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...
override void WriteByte(byte value)
Writes a byte to the current stream at the current position.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override int Read([In] [Out] byte[] buffer, int offset, int count)
Reads a block of bytes from the current stream and writes the data to a buffer.
override long Length
Gets the length of the stream in bytes.
Propagates notification that operations should be canceled.
override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
Asynchronously reads all the bytes from the current stream and writes them to another stream,...
override void SetLength(long value)
Sets the length of the current stream to the specified value.
override bool CanSeek
Gets a value indicating whether the current stream supports seeking.
Definition: MemoryStream.cs:56
TResult Result
Gets the result value of this T:System.Threading.Tasks.Task`1.
Definition: Task.cs:57
MemoryStream(int capacity)
Initializes a new instance of the T:System.IO.MemoryStream class with an expandable capacity initiali...
static void Clear(Array array, int index, int length)
Sets a range of elements in an array to the default value of each element type.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
abstract bool CanWrite
When overridden in a derived class, gets a value indicating whether the current stream supports writi...
Definition: Stream.cs:610
virtual void WriteTo(Stream stream)
Writes the entire contents of this memory stream to another stream.
override bool CanWrite
Gets a value indicating whether the current stream supports writing.
Definition: MemoryStream.cs:69
bool IsCancellationRequested
Gets whether cancellation has been requested for this token.
override void Flush()
Overrides the M:System.IO.Stream.Flush method so that no action is performed.
SeekOrigin
Specifies the position in a stream to use for seeking.
Definition: SeekOrigin.cs:9
The exception that is thrown when an operation is performed on a disposed object.
virtual byte [] GetBuffer()
Returns the array of unsigned bytes from which this stream was created.
abstract bool CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports readi...
Definition: Stream.cs:577
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
MemoryStream(byte[] buffer, int index, int count, bool writable)
Initializes a new non-resizable instance of the T:System.IO.MemoryStream class based on the specified...
override void Write(byte[] buffer, int offset, int count)
Writes a block of bytes to the current stream using data read from a buffer.
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
Definition: MemoryStream.cs:13
virtual byte [] ToArray()
Writes the stream contents to a byte array, regardless of the P:System.IO.MemoryStream....
MemoryStream()
Initializes a new instance of the T:System.IO.MemoryStream class with an expandable capacity initiali...
static Task FromException(Exception exception)
Creates a T:System.Threading.Tasks.Task that has completed with a specified exception.
Definition: Task.cs:4130
The exception that is thrown when an I/O error occurs.
Definition: IOException.cs:10
override 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 st...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
static Task CompletedTask
Gets a task that has already completed successfully.
Definition: Task.cs:1453
override void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.IO.MemoryStream class and optionally releases t...
override Task FlushAsync(CancellationToken cancellationToken)
Asynchronously clears all buffers for this stream, and monitors cancellation requests.
void Dispose()
Releases all resources used by the current instance of the T:System.Threading.Tasks....
Definition: Task.cs:2191
override long Seek(long offset, SeekOrigin loc)
Sets the position within the current stream to the specified value.
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual int Capacity
Gets or sets the number of bytes allocated for this stream.
Definition: MemoryStream.cs:85
The exception that is thrown in a thread upon cancellation of an operation that the thread was execut...
virtual bool TryGetBuffer(out ArraySegment< byte > buffer)
Returns the array of unsigned bytes from which this stream was created. The return value indicates wh...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
override int ReadByte()
Reads a byte from the current stream.
MemoryStream(byte[] buffer, int index, int count, bool writable, bool publiclyVisible)
Initializes a new instance of the T:System.IO.MemoryStream class based on the specified region of a b...
Specifies that the class can be serialized.
MemoryStream(byte[] buffer, bool writable)
Initializes a new non-resizable instance of the T:System.IO.MemoryStream class based on the specified...
Task WriteAsync(byte[] buffer, int offset, int count)
Asynchronously writes a sequence of bytes to the current stream and advances the current position wit...
Definition: Stream.cs:1213
Manipulates arrays of primitive types.
Definition: Buffer.cs:11
The exception that is thrown when the operating system denies access because of an I/O error or a spe...
MemoryStream(byte[] buffer, int index, int count)
Initializes a new non-resizable instance of the T:System.IO.MemoryStream class based on the specified...
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
override 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...
override long Position
Gets or sets the current position within the stream.
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....
Definition: Stream.cs:16