using System;
using System.Runtime.InteropServices;
namespace System.IO
{
/// Provides access to unmanaged blocks of memory from managed code.
/// 2
// Token: 0x020001DB RID: 475
[CLSCompliant(false)]
public class UnmanagedMemoryStream : Stream
{
/// Initializes a new, empty instance of the class.
/// The user does not have the required permission.
// Token: 0x06001882 RID: 6274 RVA: 0x0005DB48 File Offset: 0x0005BD48
protected UnmanagedMemoryStream()
{
this.closed = true;
}
/// Initializes a new instance of the class using the specified location and memory length.
/// A pointer to an unmanaged memory location.
/// The length of the memory to use.
/// The user does not have the required permission.
/// The value is null.
/// The value is less than zero.- or -The is large enough to cause an overflow.
// Token: 0x06001883 RID: 6275 RVA: 0x0005DB58 File Offset: 0x0005BD58
public unsafe UnmanagedMemoryStream(byte* pointer, long length)
{
this.Initialize(pointer, length, length, FileAccess.Read);
}
/// Initializes a new instance of the class using the specified location, memory length, total amount of memory, and file access values.
/// A pointer to an unmanaged memory location.
/// The length of the memory to use.
/// The total amount of memory assigned to the stream.
/// One of the values.
/// The user does not have the required permission.
/// The value is null.
/// The value is less than zero.- or - The value is less than zero.- or -The value is greater than the value.
// Token: 0x06001884 RID: 6276 RVA: 0x0005DB6C File Offset: 0x0005BD6C
public unsafe UnmanagedMemoryStream(byte* pointer, long length, long capacity, FileAccess access)
{
this.Initialize(pointer, length, capacity, access);
}
// Token: 0x14000003 RID: 3
// (add) Token: 0x06001885 RID: 6277 RVA: 0x0005DB80 File Offset: 0x0005BD80
// (remove) Token: 0x06001886 RID: 6278 RVA: 0x0005DB9C File Offset: 0x0005BD9C
internal event EventHandler Closed;
/// Gets a value indicating whether a stream supports reading.
/// false if the object was created by a constructor with an parameter that did not include reading the stream and if the stream is closed; otherwise, true.
/// 2
// Token: 0x17000443 RID: 1091
// (get) Token: 0x06001887 RID: 6279 RVA: 0x0005DBB8 File Offset: 0x0005BDB8
public override bool CanRead
{
get
{
return !this.closed && this.fileaccess != FileAccess.Write;
}
}
/// Gets a value indicating whether a stream supports seeking.
/// false if the stream is closed; otherwise, true.
/// 2
// Token: 0x17000444 RID: 1092
// (get) Token: 0x06001888 RID: 6280 RVA: 0x0005DBD4 File Offset: 0x0005BDD4
public override bool CanSeek
{
get
{
return !this.closed;
}
}
/// Gets a value indicating whether a stream supports writing.
/// false if the object was created by a constructor with an parameter value that supports writing or was created by a constructor that had no parameters, or if the stream is closed; otherwise, true.
/// 2
// Token: 0x17000445 RID: 1093
// (get) Token: 0x06001889 RID: 6281 RVA: 0x0005DBE0 File Offset: 0x0005BDE0
public override bool CanWrite
{
get
{
return !this.closed && this.fileaccess != FileAccess.Read;
}
}
/// Gets the stream length (size) or the total amount of memory assigned to a stream (capacity).
/// The size or capacity of the stream.
/// The stream is closed.
/// 2
// Token: 0x17000446 RID: 1094
// (get) Token: 0x0600188A RID: 6282 RVA: 0x0005DBFC File Offset: 0x0005BDFC
public long Capacity
{
get
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
return this.capacity;
}
}
/// Gets the length of the data in a stream.
/// The length of the data in the stream.
/// The stream is closed.
/// 2
// Token: 0x17000447 RID: 1095
// (get) Token: 0x0600188B RID: 6283 RVA: 0x0005DC1C File Offset: 0x0005BE1C
public override long Length
{
get
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
return this.length;
}
}
/// Gets or sets the current position in a stream.
/// The current position in the stream.
/// The stream is closed.
/// The position is set to a value that is less than zero, or the position is larger than or results in overflow when added to the current pointer.
/// 2
// Token: 0x17000448 RID: 1096
// (get) Token: 0x0600188C RID: 6284 RVA: 0x0005DC3C File Offset: 0x0005BE3C
// (set) Token: 0x0600188D RID: 6285 RVA: 0x0005DC5C File Offset: 0x0005BE5C
public override long Position
{
get
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
return this.current_position;
}
set
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (value < 0L)
{
throw new ArgumentOutOfRangeException("value", "Non-negative number required.");
}
if (value > 2147483647L)
{
throw new ArgumentOutOfRangeException("value", "The position is larger than Int32.MaxValue.");
}
this.current_position = value;
}
}
/// Gets or sets a byte pointer to a stream based on the current position in the stream.
/// A byte pointer.
/// The current position is larger than the capacity of the stream.
/// The position is being set is not a valid position in the current stream.
/// The pointer is being set to a lower value than the starting position of the stream.
/// 2
///
///
///
// Token: 0x17000449 RID: 1097
// (get) Token: 0x0600188E RID: 6286 RVA: 0x0005DCBC File Offset: 0x0005BEBC
// (set) Token: 0x0600188F RID: 6287 RVA: 0x0005DD10 File Offset: 0x0005BF10
[CLSCompliant(false)]
public unsafe byte* PositionPointer
{
get
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (this.current_position >= this.length)
{
throw new IndexOutOfRangeException("value");
}
return (byte*)(void*)this.initial_pointer + this.current_position;
}
set
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (value < (byte*)(void*)this.initial_pointer)
{
throw new IOException("Address is below the inital address");
}
this.Position = (long)(value - (void*)this.initial_pointer);
}
}
/// Reads the specified number of bytes into the specified array.
/// 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.
/// When this method returns, contains the specified byte array with the values between and ( + - 1) replaced by the bytes read from the current source. This parameter is passed uninitialized.
/// The zero-based byte offset in at which to begin storing the data read from the current stream.
/// The maximum number of bytes to read from the current stream.
/// The stream is closed.
/// The underlying memory does not support reading.- or - The property is set to false.
/// The parameter is set to null.
/// The parameter is less than zero. - or - The parameter is less than zero.
/// The length of the buffer array minus the parameter is less than the parameter.
/// 2
// Token: 0x06001890 RID: 6288 RVA: 0x0005DD64 File Offset: 0x0005BF64
public override int Read([In] [Out] byte[] buffer, int offset, int count)
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (buffer == null)
{
throw new ArgumentNullException("buffer");
}
if (offset < 0)
{
throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
}
if (count < 0)
{
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
}
if (buffer.Length - offset < count)
{
throw new ArgumentException("The length of the buffer array minus the offset parameter is less than the count parameter");
}
if (this.fileaccess == FileAccess.Write)
{
throw new NotSupportedException("Stream does not support reading");
}
if (this.current_position >= this.length)
{
return 0;
}
int num = ((this.current_position + (long)count >= this.length) ? ((int)(this.length - this.current_position)) : count);
Marshal.Copy(new IntPtr(this.initial_pointer.ToInt64() + this.current_position), buffer, offset, num);
this.current_position += (long)num;
return num;
}
/// Reads a byte from a stream and advances the position within the stream by one byte, or returns -1 if at the end of the stream.
/// The unsigned byte cast to an object, or -1 if at the end of the stream.
/// The stream is closed.
/// The underlying memory does not support reading.- or -The current position is at the end of the stream.
/// 2
// Token: 0x06001891 RID: 6289 RVA: 0x0005DE60 File Offset: 0x0005C060
public override int ReadByte()
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (this.fileaccess == FileAccess.Write)
{
throw new NotSupportedException("Stream does not support reading");
}
if (this.current_position >= this.length)
{
return -1;
}
IntPtr intPtr = this.initial_pointer;
long num;
this.current_position = (num = this.current_position) + 1L;
return (int)Marshal.ReadByte(intPtr, (int)num);
}
/// Sets the current position of the current stream to the given value.
/// The new position in the stream.
/// The point relative to to begin seeking from.
/// Specifies the beginning, the end, or the current position as a reference point for , using a value of type .
/// An attempt was made to seek before the beginning of the stream.
/// The value is larger than the maximum size of the stream.
///
/// is invalid.
/// The stream is closed.
/// 2
// Token: 0x06001892 RID: 6290 RVA: 0x0005DECC File Offset: 0x0005C0CC
public override long Seek(long offset, SeekOrigin loc)
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
long num;
switch (loc)
{
case SeekOrigin.Begin:
if (offset < 0L)
{
throw new IOException("An attempt was made to seek before the beginning of the stream");
}
num = this.initial_position;
break;
case SeekOrigin.Current:
num = this.current_position;
break;
case SeekOrigin.End:
num = this.length;
break;
default:
throw new ArgumentException("Invalid SeekOrigin option");
}
num += offset;
if (num < this.initial_position)
{
throw new IOException("An attempt was made to seek before the beginning of the stream");
}
this.current_position = num;
return this.current_position;
}
/// Sets the length of a stream to a specified value.
/// The length of the stream.
/// An I/O error has occurred.
/// The stream is closed.
/// The underlying memory does not support writing.- or -An attempt is made to write to the stream and the property is false.
/// The specified exceeds the capacity of the stream.- or -The specified is negative.
/// 2
// Token: 0x06001893 RID: 6291 RVA: 0x0005DF74 File Offset: 0x0005C174
public override void SetLength(long value)
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (value < 0L)
{
throw new ArgumentOutOfRangeException("length", "Non-negative number required.");
}
if (value > this.capacity)
{
throw new IOException("Unable to expand length of this stream beyond its capacity.");
}
if (this.fileaccess == FileAccess.Read)
{
throw new NotSupportedException("Stream does not support writing.");
}
this.length = value;
if (this.length < this.current_position)
{
this.current_position = this.length;
}
}
/// Overrides the method so that no action is performed.
/// The stream is closed.
/// 2
// Token: 0x06001894 RID: 6292 RVA: 0x0005E004 File Offset: 0x0005C204
public override void Flush()
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
}
/// Releases the unmanaged resources used by the and optionally releases the managed resources.
/// true to release both managed and unmanaged resources; false to release only unmanaged resources.
// Token: 0x06001895 RID: 6293 RVA: 0x0005E01C File Offset: 0x0005C21C
protected override void Dispose(bool disposing)
{
if (this.closed)
{
return;
}
this.closed = true;
if (this.Closed != null)
{
this.Closed(this, null);
}
}
/// Writes a block of bytes to the current stream using data from a buffer.
/// The byte array from which to copy bytes to the current stream.
/// The offset in the buffer at which to begin copying bytes to the current stream.
/// The number of bytes to write to the current stream.
/// The stream is closed.
/// The underlying memory does not support writing. - or -An attempt is made to write to the stream and the property is false.- or -The value is greater than the capacity of the stream.- or -The position is at the end of the stream capacity.
/// An I/O error occurs.
/// One of the specified parameters is less than zero.
/// The parameter minus the length of the parameter is less than the parameter.
/// The parameter is null.
/// 2
// Token: 0x06001896 RID: 6294 RVA: 0x0005E04C File Offset: 0x0005C24C
public override void Write(byte[] buffer, int offset, int count)
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (buffer == null)
{
throw new ArgumentNullException("The buffer parameter is a null reference");
}
if (offset < 0)
{
throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
}
if (count < 0)
{
throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
}
if (buffer.Length - offset < count)
{
throw new ArgumentException("The length of the buffer array minus the offset parameter is less than the count parameter");
}
if (this.current_position > this.capacity - (long)count)
{
throw new NotSupportedException("Unable to expand length of this stream beyond its capacity.");
}
if (this.fileaccess == FileAccess.Read)
{
throw new NotSupportedException("Stream does not support writing.");
}
for (int i = 0; i < count; i++)
{
IntPtr intPtr = this.initial_pointer;
long num;
this.current_position = (num = this.current_position) + 1L;
Marshal.WriteByte(intPtr, (int)num, buffer[offset + i]);
}
if (this.current_position > this.length)
{
this.length = this.current_position;
}
}
/// Writes a byte to the current position in the file stream.
/// A byte value written to the stream.
/// The stream is closed.
/// The underlying memory does not support writing.- or -An attempt is made to write to the stream and the property is false.- or - The current position is at the end of the capacity of the stream.
/// The supplied causes the stream exceed its maximum capacity.
/// 2
// Token: 0x06001897 RID: 6295 RVA: 0x0005E14C File Offset: 0x0005C34C
public override void WriteByte(byte value)
{
if (this.closed)
{
throw new ObjectDisposedException("The stream is closed");
}
if (this.current_position == this.capacity)
{
throw new NotSupportedException("The current position is at the end of the capacity of the stream");
}
if (this.fileaccess == FileAccess.Read)
{
throw new NotSupportedException("Stream does not support writing.");
}
Marshal.WriteByte(this.initial_pointer, (int)this.current_position, value);
this.current_position += 1L;
if (this.current_position > this.length)
{
this.length = this.current_position;
}
}
/// Initializes a new instance of the class.
/// A pointer to an unmanaged memory location.
/// The length of the memory to use.
/// The total amount of memory assigned to the stream.
/// One of the values.
/// The user does not have the required permission.
/// The value is null.
/// The value is less than zero.- or - The value is less than zero.- or -The value is large enough to cause an overflow.
// Token: 0x06001898 RID: 6296 RVA: 0x0005E1E4 File Offset: 0x0005C3E4
protected unsafe void Initialize(byte* pointer, long length, long capacity, FileAccess access)
{
if (pointer == null)
{
throw new ArgumentNullException("pointer");
}
if (length < 0L)
{
throw new ArgumentOutOfRangeException("length", "Non-negative number required.");
}
if (capacity < 0L)
{
throw new ArgumentOutOfRangeException("capacity", "Non-negative number required.");
}
if (length > capacity)
{
throw new ArgumentOutOfRangeException("length", "The length cannot be greater than the capacity.");
}
if (access < FileAccess.Read || access > FileAccess.ReadWrite)
{
throw new ArgumentOutOfRangeException("access", "Enum value was out of legal range.");
}
this.fileaccess = access;
this.length = length;
this.capacity = capacity;
this.initial_position = 0L;
this.current_position = this.initial_position;
this.initial_pointer = new IntPtr((void*)pointer);
this.closed = false;
}
// Token: 0x0400072C RID: 1836
private long length;
// Token: 0x0400072D RID: 1837
private bool closed;
// Token: 0x0400072E RID: 1838
private long capacity;
// Token: 0x0400072F RID: 1839
private FileAccess fileaccess;
// Token: 0x04000730 RID: 1840
private IntPtr initial_pointer;
// Token: 0x04000731 RID: 1841
private long initial_position;
// Token: 0x04000732 RID: 1842
private long current_position;
}
}