using System; using System.Runtime.InteropServices; using System.Text; namespace System.IO { /// Implements a for writing characters to a stream in a particular encoding. /// 1 // Token: 0x020001D0 RID: 464 [ComVisible(true)] [Serializable] public class StreamWriter : TextWriter { /// Initializes a new instance of the class for the specified stream, using UTF-8 encoding and the default buffer size. /// The stream to write to. /// /// is not writable. /// /// is null. // Token: 0x060017C2 RID: 6082 RVA: 0x0005B840 File Offset: 0x00059A40 public StreamWriter(Stream stream) : this(stream, Encoding.UTF8Unmarked, 1024) { } /// Initializes a new instance of the class for the specified stream, using the specified encoding and the default buffer size. /// The stream to write to. /// The character encoding to use. /// /// or is null. /// /// is not writable. // Token: 0x060017C3 RID: 6083 RVA: 0x0005B854 File Offset: 0x00059A54 public StreamWriter(Stream stream, Encoding encoding) : this(stream, encoding, 1024) { } /// Initializes a new instance of the class for the specified stream, using the specified encoding and buffer size. /// The stream to write to. /// The character encoding to use. /// Sets the buffer size. /// /// or is null. /// /// is negative. /// /// is not writable. // Token: 0x060017C4 RID: 6084 RVA: 0x0005B864 File Offset: 0x00059A64 public StreamWriter(Stream stream, Encoding encoding, int bufferSize) { if (stream == null) { throw new ArgumentNullException("stream"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException("bufferSize"); } if (!stream.CanWrite) { throw new ArgumentException("Can not write to stream"); } this.internalStream = stream; this.Initialize(encoding, bufferSize); } /// Initializes a new instance of the class for the specified file on the specified path, using the default encoding and buffer size. /// The complete file path to write to. can be a file name. /// Access is denied. /// /// is an empty string(""). -or- contains the name of a system device (com1, com2, and so on). /// /// is null. /// The specified path is invalid, such as being on an unmapped drive. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// /// includes an incorrect or invalid syntax for file name, directory name, or volume label syntax. /// The caller does not have the required permission. // Token: 0x060017C5 RID: 6085 RVA: 0x0005B8D0 File Offset: 0x00059AD0 public StreamWriter(string path) : this(path, false, Encoding.UTF8Unmarked, 4096) { } /// Initializes a new instance of the class for the specified file on the specified path, using the default encoding and buffer size. If the file exists, it can be either overwritten or appended to. If the file does not exist, this constructor creates a new file. /// The complete file path to write to. /// Determines whether data is to be appended to the file. If the file exists and is false, the file is overwritten. If the file exists and is true, the data is appended to the file. Otherwise, a new file is created. /// Access is denied. /// /// is empty. -or- contains the name of a system device (com1, com2, and so on). /// /// is null. /// The specified path is invalid, such as being on an unmapped drive. /// /// includes an incorrect or invalid syntax for file name, directory name, or volume label syntax. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The caller does not have the required permission. // Token: 0x060017C6 RID: 6086 RVA: 0x0005B8E4 File Offset: 0x00059AE4 public StreamWriter(string path, bool append) : this(path, append, Encoding.UTF8Unmarked, 4096) { } /// Initializes a new instance of the class for the specified file on the specified path, using the specified encoding and default buffer size. If the file exists, it can be either overwritten or appended to. If the file does not exist, this constructor creates a new file. /// The complete file path to write to. /// Determines whether data is to be appended to the file. If the file exists and is false, the file is overwritten. If the file exists and is true, the data is appended to the file. Otherwise, a new file is created. /// The character encoding to use. /// Access is denied. /// /// is empty. -or- contains the name of a system device (com1, com2, etc). /// /// is null. /// The specified path is invalid, such as being on an unmapped drive. /// /// includes an incorrect or invalid syntax for file name, directory name, or volume label syntax. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. /// The caller does not have the required permission. // Token: 0x060017C7 RID: 6087 RVA: 0x0005B8F8 File Offset: 0x00059AF8 public StreamWriter(string path, bool append, Encoding encoding) : this(path, append, encoding, 4096) { } /// Initializes a new instance of the class for the specified file on the specified path, using the specified encoding and buffer size. If the file exists, it can be either overwritten or appended to. If the file does not exist, this constructor creates a new file. /// The complete file path to write to. /// Determines whether data is to be appended to the file. If the file exists and is false, the file is overwritten. If the file exists and is true, the data is appended to the file. Otherwise, a new file is created. /// The character encoding to use. /// Sets the buffer size. /// /// is an empty string (""). -or- contains the name of a system device (com1, com2, etc). /// /// or is null. /// /// is negative. /// /// includes an incorrect or invalid syntax for file name, directory name, or volume label syntax. /// The caller does not have the required permission. /// Access is denied. /// The specified path is invalid, such as being on an unmapped drive. /// The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters. // Token: 0x060017C8 RID: 6088 RVA: 0x0005B908 File Offset: 0x00059B08 public StreamWriter(string path, bool append, Encoding encoding, int bufferSize) { if (encoding == null) { throw new ArgumentNullException("encoding"); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException("bufferSize"); } FileMode fileMode; if (append) { fileMode = FileMode.Append; } else { fileMode = FileMode.Create; } this.internalStream = new FileStream(path, fileMode, FileAccess.Write, FileShare.Read); if (append) { this.internalStream.Position = this.internalStream.Length; } else { this.internalStream.SetLength(0L); } this.Initialize(encoding, bufferSize); } // Token: 0x060017CA RID: 6090 RVA: 0x0005B9AC File Offset: 0x00059BAC internal void Initialize(Encoding encoding, int bufferSize) { this.internalEncoding = encoding; this.decode_pos = (this.byte_pos = 0); int num = Math.Max(bufferSize, 256); this.decode_buf = new char[num]; this.byte_buf = new byte[encoding.GetMaxByteCount(num)]; if (this.internalStream.CanSeek && this.internalStream.Position > 0L) { this.preamble_done = true; } } /// Gets or sets a value indicating whether the will flush its buffer to the underlying stream after every call to . /// true to force to flush its buffer; otherwise, false. /// 1 // Token: 0x17000438 RID: 1080 // (get) Token: 0x060017CB RID: 6091 RVA: 0x0005BA24 File Offset: 0x00059C24 // (set) Token: 0x060017CC RID: 6092 RVA: 0x0005BA2C File Offset: 0x00059C2C public virtual bool AutoFlush { get { return this.iflush; } set { this.iflush = value; if (this.iflush) { this.Flush(); } } } /// Gets the underlying stream that interfaces with a backing store. /// The stream this StreamWriter is writing to. /// 2 // Token: 0x17000439 RID: 1081 // (get) Token: 0x060017CD RID: 6093 RVA: 0x0005BA48 File Offset: 0x00059C48 public virtual Stream BaseStream { get { return this.internalStream; } } /// Gets the in which the output is written. /// The specified in the constructor for the current instance, or if an encoding was not specified. /// 2 // Token: 0x1700043A RID: 1082 // (get) Token: 0x060017CE RID: 6094 RVA: 0x0005BA50 File Offset: 0x00059C50 public override Encoding Encoding { get { return this.internalEncoding; } } /// 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. /// The current encoding does not support displaying half of a Unicode surrogate pair. // Token: 0x060017CF RID: 6095 RVA: 0x0005BA58 File Offset: 0x00059C58 protected override void Dispose(bool disposing) { Exception ex = null; if (!this.DisposedAlready && disposing && this.internalStream != null) { try { this.Flush(); } catch (Exception ex2) { ex = ex2; } this.DisposedAlready = true; try { this.internalStream.Close(); } catch (Exception ex3) { if (ex == null) { ex = ex3; } } } this.internalStream = null; this.byte_buf = null; this.internalEncoding = null; this.decode_buf = null; if (ex != null) { throw ex; } } /// Clears all buffers for the current writer and causes any buffered data to be written to the underlying stream. /// The current writer is closed. /// An I/O error has occurred. /// The current encoding does not support displaying half of a Unicode surrogate pair. /// 1 // Token: 0x060017D0 RID: 6096 RVA: 0x0005BB14 File Offset: 0x00059D14 public override void Flush() { if (this.DisposedAlready) { throw new ObjectDisposedException("StreamWriter"); } this.Decode(); if (this.byte_pos > 0) { this.FlushBytes(); this.internalStream.Flush(); } } // Token: 0x060017D1 RID: 6097 RVA: 0x0005BB5C File Offset: 0x00059D5C private void FlushBytes() { if (!this.preamble_done && this.byte_pos > 0) { byte[] preamble = this.internalEncoding.GetPreamble(); if (preamble.Length > 0) { this.internalStream.Write(preamble, 0, preamble.Length); } this.preamble_done = true; } this.internalStream.Write(this.byte_buf, 0, this.byte_pos); this.byte_pos = 0; } // Token: 0x060017D2 RID: 6098 RVA: 0x0005BBCC File Offset: 0x00059DCC private void Decode() { if (this.byte_pos > 0) { this.FlushBytes(); } if (this.decode_pos > 0) { int bytes = this.internalEncoding.GetBytes(this.decode_buf, 0, this.decode_pos, this.byte_buf, this.byte_pos); this.byte_pos += bytes; this.decode_pos = 0; } } /// Writes a subarray of characters to the stream. /// A character array containing the data to write. /// The index into at which to begin writing. /// The number of characters to read from . /// /// is null. /// The buffer length minus is less than . /// /// or is negative. /// An I/O error occurs. /// /// is true or the buffer is full, and current writer is closed. /// /// is true or the buffer is full, and the contents of the buffer cannot be written to the underlying fixed size stream because the is at the end the stream. /// 1 // Token: 0x060017D3 RID: 6099 RVA: 0x0005BC34 File Offset: 0x00059E34 public override void Write(char[] buffer, int index, int count) { if (this.DisposedAlready) { throw new ObjectDisposedException("StreamWriter"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } if (index < 0) { throw new ArgumentOutOfRangeException("index", "< 0"); } if (count < 0) { throw new ArgumentOutOfRangeException("count", "< 0"); } if (index > buffer.Length - count) { throw new ArgumentException("index + count > buffer.Length"); } this.LowLevelWrite(buffer, index, count); if (this.iflush) { this.Flush(); } } // Token: 0x060017D4 RID: 6100 RVA: 0x0005BCC8 File Offset: 0x00059EC8 private void LowLevelWrite(char[] buffer, int index, int count) { while (count > 0) { int num = this.decode_buf.Length - this.decode_pos; if (num == 0) { this.Decode(); num = this.decode_buf.Length; } if (num > count) { num = count; } Buffer.BlockCopy(buffer, index * 2, this.decode_buf, this.decode_pos * 2, num * 2); count -= num; index += num; this.decode_pos += num; } } // Token: 0x060017D5 RID: 6101 RVA: 0x0005BD44 File Offset: 0x00059F44 private void LowLevelWrite(string s) { int i = s.Length; int num = 0; while (i > 0) { int num2 = this.decode_buf.Length - this.decode_pos; if (num2 == 0) { this.Decode(); num2 = this.decode_buf.Length; } if (num2 > i) { num2 = i; } for (int j = 0; j < num2; j++) { this.decode_buf[j + this.decode_pos] = s[j + num]; } i -= num2; num += num2; this.decode_pos += num2; } } /// Writes a character to the stream. /// The character to write to the text stream. /// An I/O error occurs. /// /// is true or the buffer is full, and current writer is closed. /// /// is true or the buffer is full, and the contents of the buffer cannot be written to the underlying fixed size stream because the is at the end the stream. /// 1 // Token: 0x060017D6 RID: 6102 RVA: 0x0005BDD4 File Offset: 0x00059FD4 public override void Write(char value) { if (this.DisposedAlready) { throw new ObjectDisposedException("StreamWriter"); } if (this.decode_pos >= this.decode_buf.Length) { this.Decode(); } this.decode_buf[this.decode_pos++] = value; if (this.iflush) { this.Flush(); } } /// Writes a character array to the stream. /// A character array containing the data to write. If is null, nothing is written. /// An I/O error occurs. /// /// is true or the buffer is full, and current writer is closed. /// /// is true or the buffer is full, and the contents of the buffer cannot be written to the underlying fixed size stream because the is at the end the stream. /// 1 // Token: 0x060017D7 RID: 6103 RVA: 0x0005BE3C File Offset: 0x0005A03C public override void Write(char[] buffer) { if (this.DisposedAlready) { throw new ObjectDisposedException("StreamWriter"); } if (buffer != null) { this.LowLevelWrite(buffer, 0, buffer.Length); } if (this.iflush) { this.Flush(); } } /// Writes a string to the stream. /// The string to write to the stream. If is null, nothing is written. /// /// is true or the buffer is full, and current writer is closed. /// /// is true or the buffer is full, and the contents of the buffer cannot be written to the underlying fixed size stream because the is at the end the stream. /// An I/O error occurs. /// 1 // Token: 0x060017D8 RID: 6104 RVA: 0x0005BE84 File Offset: 0x0005A084 public override void Write(string value) { if (this.DisposedAlready) { throw new ObjectDisposedException("StreamWriter"); } if (value != null) { this.LowLevelWrite(value); } if (this.iflush) { this.Flush(); } } /// Closes the current StreamWriter object and the underlying stream. /// The current encoding does not support displaying half of a Unicode surrogate pair. /// 1 // Token: 0x060017D9 RID: 6105 RVA: 0x0005BEC8 File Offset: 0x0005A0C8 public override void Close() { this.Dispose(true); } /// Frees the resources of the current before it is reclaimed by the garbage collector. // Token: 0x060017DA RID: 6106 RVA: 0x0005BED4 File Offset: 0x0005A0D4 ~StreamWriter() { this.Dispose(false); } // Token: 0x04000711 RID: 1809 private const int DefaultBufferSize = 1024; // Token: 0x04000712 RID: 1810 private const int DefaultFileBufferSize = 4096; // Token: 0x04000713 RID: 1811 private const int MinimumBufferSize = 256; // Token: 0x04000714 RID: 1812 private Encoding internalEncoding; // Token: 0x04000715 RID: 1813 private Stream internalStream; // Token: 0x04000716 RID: 1814 private bool iflush; // Token: 0x04000717 RID: 1815 private byte[] byte_buf; // Token: 0x04000718 RID: 1816 private int byte_pos; // Token: 0x04000719 RID: 1817 private char[] decode_buf; // Token: 0x0400071A RID: 1818 private int decode_pos; // Token: 0x0400071B RID: 1819 private bool DisposedAlready; // Token: 0x0400071C RID: 1820 private bool preamble_done; /// Provides a StreamWriter with no backing store that can be written to, but not read from. /// 1 // Token: 0x0400071D RID: 1821 public new static readonly StreamWriter Null = new StreamWriter(Stream.Null, Encoding.UTF8Unmarked, 1); } }