11 [__DynamicallyInvokable]
15 [__DynamicallyInvokable]
19 [__DynamicallyInvokable]
22 private byte[] _buffer;
29 private bool _leaveOpen;
32 private char[] _tmpOneCharBuffer;
34 private byte[] _largeByteBuffer;
36 private int _maxChars;
38 private const int LargeByteBufferSize = 256;
42 [__DynamicallyInvokable]
45 [__DynamicallyInvokable]
54 [__DynamicallyInvokable]
58 _buffer =
new byte[16];
59 _encoding =
new UTF8Encoding(encoderShouldEmitUTF8Identifier:
false, throwOnInvalidBytes:
true);
68 [__DynamicallyInvokable]
70 : this(output, new
UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true), leaveOpen: false)
80 [__DynamicallyInvokable]
82 : this(output, encoding, leaveOpen: false)
94 [__DynamicallyInvokable]
101 if (encoding ==
null)
110 _buffer =
new byte[16];
111 _encoding = encoding;
113 _leaveOpen = leaveOpen;
125 [__DynamicallyInvokable]
126 protected virtual void Dispose(
bool disposing)
142 [__DynamicallyInvokable]
149 [__DynamicallyInvokable]
161 [__DynamicallyInvokable]
171 [__DynamicallyInvokable]
172 public virtual void Write(
bool value)
174 _buffer[0] = (byte)(value ? 1 : 0);
182 [__DynamicallyInvokable]
183 public virtual void Write(
byte value)
192 [CLSCompliant(
false)]
193 [__DynamicallyInvokable]
194 public virtual void Write(sbyte value)
205 [__DynamicallyInvokable]
206 public virtual void Write(
byte[] buffer)
226 [__DynamicallyInvokable]
227 public virtual void Write(
byte[] buffer,
int index,
int count)
238 [SecuritySafeCritical]
239 [__DynamicallyInvokable]
240 public unsafe
virtual void Write(
char ch)
242 if (
char.IsSurrogate(ch))
247 byte[] buffer = _buffer;
248 fixed (
byte* bytes = buffer)
250 num = _encoder.
GetBytes(&ch, 1, bytes, _buffer.Length, flush:
true);
261 [__DynamicallyInvokable]
262 public virtual void Write(
char[] chars)
268 byte[] bytes = _encoding.
GetBytes(chars, 0, chars.Length);
283 [__DynamicallyInvokable]
284 public virtual void Write(
char[] chars,
int index,
int count)
286 byte[] bytes = _encoding.
GetBytes(chars, index, count);
294 [SecuritySafeCritical]
295 [__DynamicallyInvokable]
296 public unsafe
virtual void Write(
double value)
298 ulong num = (ulong)(*(
long*)(&value));
299 _buffer[0] = (byte)num;
300 _buffer[1] = (byte)(num >> 8);
301 _buffer[2] = (byte)(num >> 16);
302 _buffer[3] = (byte)(num >> 24);
303 _buffer[4] = (byte)(num >> 32);
304 _buffer[5] = (byte)(num >> 40);
305 _buffer[6] = (byte)(num >> 48);
306 _buffer[7] = (byte)(num >> 56);
314 [__DynamicallyInvokable]
315 public virtual void Write(decimal value)
317 decimal.GetBytes(value, _buffer);
325 [__DynamicallyInvokable]
326 public virtual void Write(
short value)
328 _buffer[0] = (byte)value;
329 _buffer[1] = (byte)(value >> 8);
337 [CLSCompliant(
false)]
338 [__DynamicallyInvokable]
339 public virtual void Write(ushort value)
341 _buffer[0] = (byte)value;
342 _buffer[1] = (byte)(value >> 8);
350 [__DynamicallyInvokable]
351 public virtual void Write(
int value)
353 _buffer[0] = (byte)value;
354 _buffer[1] = (byte)(value >> 8);
355 _buffer[2] = (byte)(value >> 16);
356 _buffer[3] = (byte)(value >> 24);
364 [CLSCompliant(
false)]
365 [__DynamicallyInvokable]
366 public virtual void Write(uint value)
368 _buffer[0] = (byte)value;
369 _buffer[1] = (byte)(value >> 8);
370 _buffer[2] = (byte)(value >> 16);
371 _buffer[3] = (byte)(value >> 24);
379 [__DynamicallyInvokable]
380 public virtual void Write(
long value)
382 _buffer[0] = (byte)value;
383 _buffer[1] = (byte)(value >> 8);
384 _buffer[2] = (byte)(value >> 16);
385 _buffer[3] = (byte)(value >> 24);
386 _buffer[4] = (byte)(value >> 32);
387 _buffer[5] = (byte)(value >> 40);
388 _buffer[6] = (byte)(value >> 48);
389 _buffer[7] = (byte)(value >> 56);
397 [CLSCompliant(
false)]
398 [__DynamicallyInvokable]
399 public virtual void Write(ulong value)
401 _buffer[0] = (byte)value;
402 _buffer[1] = (byte)(value >> 8);
403 _buffer[2] = (byte)(value >> 16);
404 _buffer[3] = (byte)(value >> 24);
405 _buffer[4] = (byte)(value >> 32);
406 _buffer[5] = (byte)(value >> 40);
407 _buffer[6] = (byte)(value >> 48);
408 _buffer[7] = (byte)(value >> 56);
416 [SecuritySafeCritical]
417 [__DynamicallyInvokable]
418 public unsafe
virtual void Write(
float value)
420 uint num = *(uint*)(&value);
421 _buffer[0] = (byte)num;
422 _buffer[1] = (byte)(num >> 8);
423 _buffer[2] = (byte)(num >> 16);
424 _buffer[3] = (byte)(num >> 24);
434 [SecuritySafeCritical]
435 [__DynamicallyInvokable]
436 public unsafe
virtual void Write(
string value)
444 if (_largeByteBuffer ==
null)
446 _largeByteBuffer =
new byte[256];
449 if (byteCount <= _largeByteBuffer.Length)
451 _encoding.
GetBytes(value, 0, value.Length, _largeByteBuffer, 0);
456 int num2 = value.Length;
461 int num3 = (num2 > _maxChars) ? _maxChars : num2;
462 if (num < 0 || num3 < 0 || checked(num + num3) > value.Length)
467 fixed (
char* ptr = value)
469 byte[] largeByteBuffer = _largeByteBuffer;
470 fixed (
byte* bytes = largeByteBuffer)
472 bytes2 = _encoder.
GetBytes((
char*)checked(unchecked((ulong)ptr) + unchecked((ulong)(
UIntPtr)(
void*)checked(unchecked((
long)num) * 2
L))), num3, bytes, _largeByteBuffer.Length, num3 == num2);
490 [__DynamicallyInvokable]
494 for (num = (uint)value; num >= 128; num >>= 7)
496 Write((
byte)(num | 0x80));
Represents a character encoding.To browse the .NET Framework source code for this type,...
A platform-specific type that is used to represent a pointer or a handle.
virtual void Close()
Closes the current T:System.IO.BinaryWriter and the underlying stream.
void Dispose()
Releases all resources used by the current instance of the T:System.IO.BinaryWriter class.
virtual Stream BaseStream
Gets the underlying stream of the T:System.IO.BinaryWriter.
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...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual void Write(long value)
Writes an eight-byte signed integer to the current stream and advances the stream position by eight b...
BinaryWriter()
Initializes a new instance of the T:System.IO.BinaryWriter class that writes to a stream.
virtual unsafe void Write(float value)
Writes a four-byte floating-point value to the current stream and advances the stream position by fou...
Converts a set of characters into a sequence of bytes.
virtual byte [] GetBytes(char[] chars)
When overridden in a derived class, encodes all the characters in the specified character array into ...
virtual Encoder GetEncoder()
When overridden in a derived class, obtains an encoder that converts a sequence of Unicode characters...
abstract int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex, bool flush)
When overridden in a derived class, encodes a set of characters from the specified character array an...
virtual void Flush()
Clears all buffers for the current writer and causes any buffered data to be written to the underlyin...
virtual void Write(uint value)
Writes a four-byte unsigned integer to the current stream and advances the stream position by four by...
virtual void Write(decimal value)
Writes a decimal value to the current stream and advances the stream position by sixteen bytes.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
virtual unsafe void Write(double value)
Writes an eight-byte floating-point value to the current stream and advances the stream position by e...
virtual unsafe void Write(string value)
Writes a length-prefixed string to this stream in the current encoding of the T:System....
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...
void Write7BitEncodedInt(int value)
Writes a 32-bit integer in a compressed format.
virtual void Write(byte[] buffer)
Writes a byte array to the underlying stream.
virtual void WriteByte(byte value)
Writes a byte to the current position in the stream and advances the position within the stream by on...
virtual void Write(byte[] buffer, int index, int count)
Writes a region of a byte array to the current stream.
virtual void Write(int value)
Writes a four-byte signed integer to the current stream and advances the stream position by four byte...
virtual unsafe void Write(char ch)
Writes a Unicode character to the current stream and advances the current position of the stream in a...
SeekOrigin
Specifies the position in a stream to use for seeking.
virtual long Seek(int offset, SeekOrigin origin)
Sets the position within the current stream.
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...
static readonly Stream Null
A Stream with no backing store.
abstract void Flush()
When overridden in a derived class, clears all buffers for this stream and causes any buffered data t...
virtual void Write(ulong value)
Writes an eight-byte unsigned integer to the current stream and advances the stream position by eight...
Represents a UTF-8 encoding of Unicode characters.
virtual void Write(char[] chars, int index, int count)
Writes a section of a character array to the current stream, and advances the current position of the...
virtual void Write(byte value)
Writes an unsigned byte to the current stream and advances the stream position by one byte.
virtual void Write(bool value)
Writes a one-byte Boolean value to the current stream, with 0 representing false and 1 representing t...
abstract long Seek(long offset, SeekOrigin origin)
When overridden in a derived class, sets the position within the current stream.
BinaryWriter(Stream output, Encoding encoding, bool leaveOpen)
Initializes a new instance of the T:System.IO.BinaryWriter class based on the specified stream and ch...
static readonly BinaryWriter Null
Specifies a T:System.IO.BinaryWriter with no backing store.
BinaryWriter(Stream output, Encoding encoding)
Initializes a new instance of the T:System.IO.BinaryWriter class based on the specified stream and ch...
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual void Dispose(bool disposing)
Releases the unmanaged resources used by the T:System.IO.BinaryWriter and optionally releases the man...
virtual void Write(short value)
Writes a two-byte signed integer to the current stream and advances the stream position by two bytes.
Specifies that the class can be serialized.
BinaryWriter(Stream output)
Initializes a new instance of the T:System.IO.BinaryWriter class based on the specified stream and us...
virtual int GetByteCount(char[] chars)
When overridden in a derived class, calculates the number of bytes produced by encoding all the chara...
Stream OutStream
Holds the underlying stream.
virtual void Write(char[] chars)
Writes a character array to the current stream and advances the current position of the stream in acc...
Writes primitive types in binary to a stream and supports writing strings in a specific encoding.
virtual void Write(sbyte value)
Writes a signed byte to the current stream and advances the stream position by one byte.
virtual void Write(ushort value)
Writes a two-byte unsigned integer to the current stream and advances the stream position by two byte...
abstract int GetMaxByteCount(int charCount)
When overridden in a derived class, calculates the maximum number of bytes produced by encoding the s...
Provides a generic view of a sequence of bytes. This is an abstract class.To browse the ....