Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
WebFileStream.cs
Go to the documentation of this file.
1using System.IO;
4
5namespace System.Net;
6
7internal sealed class WebFileStream : FileStream
8{
9 private readonly FileWebRequest _request;
10
11 public WebFileStream(FileWebRequest request, string path, FileMode mode, FileAccess access, FileShare sharing)
12 : base(path, mode, access, sharing)
13 {
14 _request = request;
15 }
16
17 public WebFileStream(FileWebRequest request, string path, FileMode mode, FileAccess access, FileShare sharing, int length, bool async)
18 : base(path, mode, access, sharing, length, async)
19 {
20 _request = request;
21 }
22
23 protected override void Dispose(bool disposing)
24 {
25 try
26 {
27 if (disposing)
28 {
30 }
31 }
32 finally
33 {
34 base.Dispose(disposing);
35 }
36 }
37
38 internal void Abort()
39 {
40 SafeFileHandle.Close();
41 }
42
43 public override int Read(byte[] buffer, int offset, int size)
44 {
46 try
47 {
48 return base.Read(buffer, offset, size);
49 }
50 catch
51 {
53 throw;
54 }
55 }
56
57 public override void Write(byte[] buffer, int offset, int size)
58 {
60 try
61 {
62 base.Write(buffer, offset, size);
63 }
64 catch
65 {
67 throw;
68 }
69 }
70
71 public override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
72 {
74 try
75 {
76 return base.BeginRead(buffer, offset, size, callback, state);
77 }
78 catch
79 {
81 throw;
82 }
83 }
84
85 public override int EndRead(IAsyncResult ar)
86 {
87 try
88 {
89 return base.EndRead(ar);
90 }
91 catch
92 {
94 throw;
95 }
96 }
97
98 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
99 {
100 CheckAborted();
101 try
102 {
103 return base.BeginWrite(buffer, offset, size, callback, state);
104 }
105 catch
106 {
107 CheckAborted();
108 throw;
109 }
110 }
111
112 public override void EndWrite(IAsyncResult ar)
113 {
114 try
115 {
116 base.EndWrite(ar);
117 }
118 catch
119 {
120 CheckAborted();
121 throw;
122 }
123 }
124
126 {
127 CheckAborted();
128 try
129 {
130 return base.ReadAsync(buffer, offset, count, cancellationToken);
131 }
132 catch
133 {
134 CheckAborted();
135 throw;
136 }
137 }
138
140 {
141 CheckAborted();
142 try
143 {
144 return base.WriteAsync(buffer, offset, count, cancellationToken);
145 }
146 catch
147 {
148 CheckAborted();
149 throw;
150 }
151 }
152
154 {
155 CheckAborted();
156 try
157 {
158 return base.CopyToAsync(destination, bufferSize, cancellationToken);
159 }
160 catch
161 {
162 CheckAborted();
163 throw;
164 }
165 }
166
167 private void CheckAborted()
168 {
169 if (_request.Aborted)
170 {
171 throw new WebException(System.SR.Format(System.SR.net_requestaborted, WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
172 }
173 }
174}
virtual SafeFileHandle SafeFileHandle
Definition FileStream.cs:21
override void Write(byte[] buffer, int offset, int size)
WebFileStream(FileWebRequest request, string path, FileMode mode, FileAccess access, FileShare sharing, int length, bool async)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override IAsyncResult BeginWrite(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
override int EndRead(IAsyncResult ar)
WebFileStream(FileWebRequest request, string path, FileMode mode, FileAccess access, FileShare sharing)
override IAsyncResult BeginRead(byte[] buffer, int offset, int size, AsyncCallback callback, object state)
override void EndWrite(IAsyncResult ar)
override Task< int > ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override void Dispose(bool disposing)
readonly FileWebRequest _request
override int Read(byte[] buffer, int offset, int size)
override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_requestaborted
Definition SR.cs:42
Definition SR.cs:7