9 [__DynamicallyInvokable]
12 private const int MaxCharBytesSize = 128;
16 private byte[] m_buffer;
20 private byte[] m_charBytes;
22 private char[] m_singleChar;
24 private char[] m_charBuffer;
26 private int m_maxCharsSize;
28 private bool m_2BytesPerChar;
30 private bool m_isMemoryStream;
32 private bool m_leaveOpen;
36 [__DynamicallyInvokable]
39 [__DynamicallyInvokable]
49 [__DynamicallyInvokable]
61 [__DynamicallyInvokable]
63 : this(input, encoding, leaveOpen: false)
75 [__DynamicallyInvokable]
98 m_buffer =
new byte[num];
100 m_isMemoryStream = (m_stream.GetType() == typeof(
MemoryStream));
101 m_leaveOpen = leaveOpen;
113 [__DynamicallyInvokable]
114 protected virtual void Dispose(
bool disposing)
120 if (stream !=
null && !m_leaveOpen)
134 [__DynamicallyInvokable]
144 [__DynamicallyInvokable]
147 if (m_stream ==
null)
149 __Error.FileNotOpen();
165 [__DynamicallyInvokable]
168 if (m_stream ==
null)
170 __Error.FileNotOpen();
172 return InternalReadOneChar();
181 [__DynamicallyInvokable]
185 return m_buffer[0] != 0;
193 [__DynamicallyInvokable]
196 if (m_stream ==
null)
198 __Error.FileNotOpen();
213 [CLSCompliant(
false)]
214 [__DynamicallyInvokable]
218 return (sbyte)m_buffer[0];
227 [__DynamicallyInvokable]
243 [__DynamicallyInvokable]
247 return (
short)(m_buffer[0] | (m_buffer[1] << 8));
255 [CLSCompliant(
false)]
256 [__DynamicallyInvokable]
260 return (ushort)(m_buffer[0] | (m_buffer[1] << 8));
268 [__DynamicallyInvokable]
271 if (m_isMemoryStream)
273 if (m_stream ==
null)
275 __Error.FileNotOpen();
278 return memoryStream.InternalReadInt32();
281 return m_buffer[0] | (m_buffer[1] << 8) | (m_buffer[2] << 16) | (m_buffer[3] << 24);
289 [CLSCompliant(
false)]
290 [__DynamicallyInvokable]
294 return (uint)(m_buffer[0] | (m_buffer[1] << 8) | (m_buffer[2] << 16) | (m_buffer[3] << 24));
302 [__DynamicallyInvokable]
306 uint num = (uint)(m_buffer[0] | (m_buffer[1] << 8) | (m_buffer[2] << 16) | (m_buffer[3] << 24));
307 uint num2 = (uint)(m_buffer[4] | (m_buffer[5] << 8) | (m_buffer[6] << 16) | (m_buffer[7] << 24));
308 return (
long)(((ulong)num2 << 32) | num);
316 [CLSCompliant(
false)]
317 [__DynamicallyInvokable]
321 uint num = (uint)(m_buffer[0] | (m_buffer[1] << 8) | (m_buffer[2] << 16) | (m_buffer[3] << 24));
322 uint num2 = (uint)(m_buffer[4] | (m_buffer[5] << 8) | (m_buffer[6] << 16) | (m_buffer[7] << 24));
323 return ((ulong)num2 << 32) | num;
331 [SecuritySafeCritical]
332 [__DynamicallyInvokable]
336 uint num = (uint)(m_buffer[0] | (m_buffer[1] << 8) | (m_buffer[2] << 16) | (m_buffer[3] << 24));
337 return *(
float*)(&num);
345 [SecuritySafeCritical]
346 [__DynamicallyInvokable]
350 uint num = (uint)(m_buffer[0] | (m_buffer[1] << 8) | (m_buffer[2] << 16) | (m_buffer[3] << 24));
351 uint num2 = (uint)(m_buffer[4] | (m_buffer[5] << 8) | (m_buffer[6] << 16) | (m_buffer[7] << 24));
352 ulong num3 = ((ulong)num2 << 32) | num;
353 return *(
double*)(&num3);
361 [__DynamicallyInvokable]
367 return decimal.ToDecimal(m_buffer);
380 [__DynamicallyInvokable]
383 if (m_stream ==
null)
385 __Error.FileNotOpen();
397 if (m_charBytes ==
null)
399 m_charBytes =
new byte[128];
401 if (m_charBuffer ==
null)
403 m_charBuffer =
new char[m_maxCharsSize];
408 int count = (num2 - num > 128) ? 128 : (num2 - num);
409 int num3 = m_stream.
Read(m_charBytes, 0, count);
414 int chars = m_decoder.
GetChars(m_charBytes, 0, num3, m_charBuffer, 0);
415 if (num == 0 && num3 == num2)
417 return new string(m_charBuffer, 0, chars);
419 if (stringBuilder ==
null)
421 stringBuilder = StringBuilderCache.Acquire(num2);
423 stringBuilder.
Append(m_charBuffer, 0, chars);
427 return StringBuilderCache.GetStringAndRelease(stringBuilder);
442 [SecuritySafeCritical]
443 [__DynamicallyInvokable]
444 public virtual int Read(
char[] buffer,
int index,
int count)
458 if (buffer.Length - index < count)
462 if (m_stream ==
null)
464 __Error.FileNotOpen();
466 return InternalReadChars(buffer, index, count);
470 private unsafe
int InternalReadChars(
char[] buffer,
int index,
int count)
474 if (m_charBytes ==
null)
476 m_charBytes =
new byte[128];
482 DecoderNLS decoderNLS = m_decoder as DecoderNLS;
483 if (decoderNLS !=
null && decoderNLS.HasState && num > 1)
497 if (m_isMemoryStream)
499 MemoryStream memoryStream = m_stream as MemoryStream;
500 num4 = memoryStream.InternalGetPosition();
501 num = memoryStream.InternalEmulateRead(num);
502 array = memoryStream.InternalGetBuffer();
506 num = m_stream.
Read(m_charBytes, 0, num);
516 if (num4 < 0 || num < 0 || num4 + num > array.Length)
518 throw new ArgumentOutOfRangeException(
"byteCount");
520 if (index < 0 || num2 < 0 || index + num2 > buffer.Length)
522 throw new ArgumentOutOfRangeException(
"charsRemaining");
526 fixed (
byte* ptr = array2)
528 fixed (
char* ptr2 = buffer)
530 num3 = m_decoder.
GetChars((
byte*)checked(unchecked((ulong)ptr) + unchecked((ulong)num4)), num, (
char*)checked(unchecked((ulong)ptr2) + unchecked((ulong)(UIntPtr)(
void*)checked(unchecked((
long)index) * 2L))), num2, flush:
false);
539 private int InternalReadOneChar()
543 long num3 = num3 = 0
L;
548 if (m_charBytes ==
null)
550 m_charBytes =
new byte[128];
552 if (m_singleChar ==
null)
554 m_singleChar =
new char[1];
558 num2 = ((!m_2BytesPerChar) ? 1 : 2);
560 m_charBytes[0] = (byte)num4;
568 m_charBytes[1] = (byte)num4;
580 num = m_decoder.
GetChars(m_charBytes, 0, num2, m_singleChar, 0);
595 return m_singleChar[0];
606 [SecuritySafeCritical]
607 [__DynamicallyInvokable]
614 if (m_stream ==
null)
616 __Error.FileNotOpen();
620 return EmptyArray<char>.Value;
622 char[] array =
new char[count];
623 int num = InternalReadChars(array, 0, count);
626 char[] array2 =
new char[num];
627 Buffer.InternalBlockCopy(array, 0, array2, 0, 2 * num);
645 [__DynamicallyInvokable]
646 public virtual int Read(
byte[] buffer,
int index,
int count)
660 if (buffer.Length - index < count)
664 if (m_stream ==
null)
666 __Error.FileNotOpen();
668 return m_stream.
Read(buffer, index, count);
679 [__DynamicallyInvokable]
686 if (m_stream ==
null)
688 __Error.FileNotOpen();
692 return EmptyArray<byte>.Value;
694 byte[] array =
new byte[count];
698 int num2 = m_stream.
Read(array, num, count);
707 if (num != array.Length)
709 byte[] array2 =
new byte[num];
710 Buffer.InternalBlockCopy(array, 0, array2, 0, num);
721 [__DynamicallyInvokable]
724 if (m_buffer !=
null && (numBytes < 0 || numBytes > m_buffer.Length))
730 if (m_stream ==
null)
732 __Error.FileNotOpen();
741 m_buffer[0] = (byte)num2;
746 num2 = m_stream.
Read(m_buffer, num, numBytes - num);
753 while (num < numBytes);
762 [__DynamicallyInvokable]
775 num |= (b & 0x7F) << num2;
778 while ((b & 0x80) != 0);
Represents a character encoding.To browse the .NET Framework source code for this type,...
virtual int Read(char[] buffer, int index, int count)
Reads the specified number of characters from the stream, starting from a specified point in the char...
BinaryReader(Stream input, Encoding encoding)
Initializes a new instance of the T:System.IO.BinaryReader class based on the specified stream and ch...
virtual void Close()
Closes the current reader and the underlying stream.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
abstract int Read([In] [Out] byte[] buffer, int offset, int count)
When overridden in a derived class, reads a sequence of bytes from the current stream and advances th...
virtual char [] ReadChars(int count)
Reads the specified number of characters from the current stream, returns the data in a character arr...
virtual int ReadInt32()
Reads a 4-byte signed integer from the current stream and advances the current position of the stream...
abstract bool CanSeek
When overridden in a derived class, gets a value indicating whether the current stream supports seeki...
virtual ulong ReadUInt64()
Reads an 8-byte unsigned integer from the current stream and advances the position of the stream by e...
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
abstract int GetMaxCharCount(int byteCount)
When overridden in a derived class, calculates the maximum number of characters produced by decoding ...
BinaryReader(Stream input)
Initializes a new instance of the T:System.IO.BinaryReader class based on the specified stream and us...
The exception that is thrown when the value of an argument is outside the allowable range of values a...
virtual int Read(byte[] buffer, int index, int count)
Reads the specified number of bytes from the stream, starting from a specified point in the byte arra...
BinaryReader(Stream input, Encoding encoding, bool leaveOpen)
Initializes a new instance of the T:System.IO.BinaryReader class based on the specified stream and ch...
virtual decimal ReadDecimal()
Reads a decimal value from the current stream and advances the current position of the stream by sixt...
virtual Decoder GetDecoder()
When overridden in a derived class, obtains a decoder that converts an encoded sequence of bytes into...
virtual byte ReadByte()
Reads the next byte from the current stream and advances the current position of the stream by one by...
virtual ushort ReadUInt16()
Reads a 2-byte unsigned integer from the current stream using little-endian encoding and advances the...
SeekOrigin
Specifies the position in a stream to use for seeking.
virtual short ReadInt16()
Reads a 2-byte signed integer from the current stream and advances the current position of the stream...
abstract bool CanRead
When overridden in a derived class, gets a value indicating whether the current stream supports readi...
virtual uint ReadUInt32()
Reads a 4-byte unsigned integer from the current stream and advances the position of the stream by fo...
Provides information about, and means to manipulate, the current environment and platform....
virtual void Close()
Closes the current stream and releases any resources (such as sockets and file handles) associated wi...
virtual sbyte ReadSByte()
Reads a signed byte from this stream and advances the current position of the stream by one byte.
Creates a stream whose backing store is memory.To browse the .NET Framework source code for this type...
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
Represents a UTF-16 encoding of Unicode characters.
virtual byte [] ReadBytes(int count)
Reads the specified number of bytes from the current stream into a byte array and advances the curren...
virtual bool ReadBoolean()
Reads a Boolean value from the current stream and advances the current position of the stream by one ...
Reads primitive data types as binary values in a specific encoding.
Converts a sequence of encoded bytes into a set of characters.
The exception that is thrown when an I/O error occurs.
Represents a UTF-8 encoding of Unicode characters.
virtual int ReadByte()
Reads a byte from the stream and advances the position within the stream by one byte,...
virtual int Read()
Reads characters from the underlying stream and advances the current position of the stream in accord...
abstract long Seek(long offset, SeekOrigin origin)
When overridden in a derived class, sets the position within the current stream.
virtual void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.IO.BinaryReader class and optionally releases t...
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
virtual Stream BaseStream
Exposes access to the underlying stream of the T:System.IO.BinaryReader.
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual char ReadChar()
Reads the next character from the current stream and advances the current position of the stream in a...
virtual unsafe float ReadSingle()
Reads a 4-byte floating point value from the current stream and advances the current position of the ...
void Dispose()
Releases all resources used by the current instance of the T:System.IO.BinaryReader class.
abstract int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex)
When overridden in a derived class, decodes a sequence of bytes from the specified byte array and any...
abstract long Position
When overridden in a derived class, gets or sets the position within the current stream.
virtual unsafe double ReadDouble()
Reads an 8-byte floating point value from the current stream and advances the current position of the...
Manipulates arrays of primitive types.
virtual void FillBuffer(int numBytes)
Fills the internal buffer with the specified number of bytes read from the stream.
virtual string ReadString()
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer...
virtual long ReadInt64()
Reads an 8-byte signed integer from the current stream and advances the current position of the strea...
abstract int GetMaxByteCount(int charCount)
When overridden in a derived class, calculates the maximum number of bytes produced by encoding the s...
internal int Read7BitEncodedInt()
Reads in a 32-bit integer in compressed format.
virtual int PeekChar()
Returns the next available character and does not advance the byte or character position.
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....