Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
StreamContent.cs
Go to the documentation of this file.
2using System.IO;
5
6namespace System.Net.Http;
7
9{
10 private sealed class ReadOnlyStream : DelegatingStream
11 {
12 public override bool CanWrite => false;
13
14 public override int WriteTimeout
15 {
16 get
17 {
19 }
20 set
21 {
23 }
24 }
25
26 public ReadOnlyStream(Stream innerStream)
27 : base(innerStream)
28 {
29 }
30
31 public override void Flush()
32 {
34 }
35
40
41 public override void SetLength(long value)
42 {
44 }
45
46 public override void Write(byte[] buffer, int offset, int count)
47 {
49 }
50
55
56 public override void WriteByte(byte value)
57 {
59 }
60
65
70 }
71
73
74 private int _bufferSize;
75
76 private bool _contentConsumed;
77
78 private long _start;
79
80 internal override bool AllowDuplex => false;
81
82 public StreamContent(Stream content)
83 {
84 if (content == null)
85 {
86 throw new ArgumentNullException("content");
87 }
88 InitializeContent(content, 0);
89 }
90
91 public StreamContent(Stream content, int bufferSize)
92 {
93 if (content == null)
94 {
95 throw new ArgumentNullException("content");
96 }
97 if (bufferSize <= 0)
98 {
99 throw new ArgumentOutOfRangeException("bufferSize");
100 }
101 InitializeContent(content, bufferSize);
102 }
103
104 [MemberNotNull("_content")]
105 private void InitializeContent(Stream content, int bufferSize)
106 {
107 _content = content;
108 _bufferSize = bufferSize;
109 if (content.CanSeek)
110 {
111 _start = content.Position;
112 }
113 if (System.Net.NetEventSource.Log.IsEnabled())
114 {
115 System.Net.NetEventSource.Associate(this, content, "InitializeContent");
116 }
117 }
118
124
126 {
128 }
129
131 {
132 if (!(GetType() == typeof(StreamContent)))
133 {
134 return base.SerializeToStreamAsync(stream, context, cancellationToken);
135 }
137 }
138
144
145 protected internal override bool TryComputeLength(out long length)
146 {
147 if (_content.CanSeek)
148 {
149 length = _content.Length - _start;
150 return true;
151 }
152 length = 0L;
153 return false;
154 }
155
156 protected override void Dispose(bool disposing)
157 {
158 if (disposing)
159 {
161 }
162 base.Dispose(disposing);
163 }
164
169
171 {
172 return Task.FromResult((Stream)new ReadOnlyStream(_content));
173 }
174
176 {
177 if (!(GetType() == typeof(StreamContent)))
178 {
179 return null;
180 }
181 return new ReadOnlyStream(_content);
182 }
183
184 private void PrepareContent()
185 {
187 {
188 if (!_content.CanSeek)
189 {
191 }
192 _content.Position = _start;
193 }
194 _contentConsumed = true;
195 }
196}
void Dispose()
Definition Stream.cs:639
override void Write(byte[] buffer, int offset, int count)
override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
override ValueTask WriteAsync(ReadOnlyMemory< byte > buffer, CancellationToken cancellationToken=default(CancellationToken))
override Task FlushAsync(CancellationToken cancellationToken)
override void Write(ReadOnlySpan< byte > buffer)
void InitializeContent(Stream content, int bufferSize)
override void SerializeToStream(Stream stream, TransportContext? context, CancellationToken cancellationToken)
override Task< Stream > CreateContentReadStreamAsync()
override Task SerializeToStreamAsync(Stream stream, TransportContext? context)
override bool TryComputeLength(out long length)
override void Dispose(bool disposing)
override Stream TryCreateContentReadStream()
override Stream CreateContentReadStream(CancellationToken cancellationToken)
StreamContent(Stream content, int bufferSize)
Task SerializeToStreamAsyncCore(Stream stream, CancellationToken cancellationToken)
override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
static Task CopyAsync(Stream source, Stream destination, int bufferSize, bool disposeSource, CancellationToken cancellationToken=default(CancellationToken))
static void Copy(Stream source, Stream destination, int bufferSize, bool disposeSource)
static readonly System.Net.NetEventSource Log
static void Associate(object first, object second, [CallerMemberName] string memberName=null)
static string net_http_content_stream_already_read
Definition SR.cs:42
static string net_http_content_readonly_stream
Definition SR.cs:44
Definition SR.cs:7