Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
MimeWriter.cs
Go to the documentation of this file.
2using System.IO;
3using System.Text;
4
5namespace System.Net.Mime;
6
7internal sealed class MimeWriter : BaseWriter
8{
9 private static readonly byte[] s_DASHDASH = new byte[2] { 45, 45 };
10
11 private readonly byte[] _boundaryBytes;
12
13 private bool _writeBoundary = true;
14
15 internal MimeWriter(Stream stream, string boundary)
16 : base(stream, shouldEncodeLeadingDots: false)
17 {
18 if (boundary == null)
19 {
20 throw new ArgumentNullException("boundary");
21 }
22 _boundaryBytes = Encoding.ASCII.GetBytes(boundary);
23 }
24
25 internal override void WriteHeaders(NameValueCollection headers, bool allowUnicode)
26 {
27 if (headers == null)
28 {
29 throw new ArgumentNullException("headers");
30 }
31 foreach (string header in headers)
32 {
33 WriteHeader(header, headers[header], allowUnicode);
34 }
35 }
36
37 internal IAsyncResult BeginClose(AsyncCallback callback, object state)
38 {
39 MultiAsyncResult multiAsyncResult = new MultiAsyncResult(this, callback, state);
40 Close(multiAsyncResult);
41 multiAsyncResult.CompleteSequence();
42 return multiAsyncResult;
43 }
44
45 internal void EndClose(IAsyncResult result)
46 {
47 MultiAsyncResult.End(result);
48 _stream.Close();
49 }
50
51 internal override void Close()
52 {
53 Close(null);
54 _stream.Close();
55 }
56
57 private void Close(MultiAsyncResult multiResult)
58 {
64 Flush(multiResult);
65 }
66
67 protected override void OnClose(object sender, EventArgs args)
68 {
69 if (_contentStream == sender)
70 {
72 _contentStream = null;
73 _writeBoundary = true;
74 _isInContent = false;
75 }
76 }
77
78 protected override void CheckBoundary()
79 {
81 {
86 _writeBoundary = false;
87 }
88 }
89}
virtual void Close()
Definition Stream.cs:644
readonly Stream _stream
Definition BaseWriter.cs:16
void WriteHeader(string name, string value, bool allowUnicode)
Definition BaseWriter.cs:43
static readonly byte[] s_crlf
Definition BaseWriter.cs:12
readonly BufferBuilder _bufferBuilder
Definition BaseWriter.cs:14
void Flush(MultiAsyncResult multiResult)
readonly byte[] _boundaryBytes
Definition MimeWriter.cs:11
MimeWriter(Stream stream, string boundary)
Definition MimeWriter.cs:15
IAsyncResult BeginClose(AsyncCallback callback, object state)
Definition MimeWriter.cs:37
static readonly byte[] s_DASHDASH
Definition MimeWriter.cs:9
void Close(MultiAsyncResult multiResult)
Definition MimeWriter.cs:57
void EndClose(IAsyncResult result)
Definition MimeWriter.cs:45
override void Close()
Definition MimeWriter.cs:51
override void WriteHeaders(NameValueCollection headers, bool allowUnicode)
Definition MimeWriter.cs:25
override void CheckBoundary()
Definition MimeWriter.cs:78
override void OnClose(object sender, EventArgs args)
Definition MimeWriter.cs:67
static object End(IAsyncResult result)
static Encoding ASCII
Definition Encoding.cs:511