Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ByteArrayContent.cs
Go to the documentation of this file.
1using System.IO;
4
5namespace System.Net.Http;
6
8{
9 private readonly byte[] _content;
10
11 private readonly int _offset;
12
13 private readonly int _count;
14
15 internal override bool AllowDuplex => false;
16
17 public ByteArrayContent(byte[] content)
18 {
19 if (content == null)
20 {
21 throw new ArgumentNullException("content");
22 }
23 _content = content;
24 _count = content.Length;
25 }
26
27 public ByteArrayContent(byte[] content, int offset, int count)
28 {
29 if (content == null)
30 {
31 throw new ArgumentNullException("content");
32 }
33 if (offset < 0 || offset > content.Length)
34 {
35 throw new ArgumentOutOfRangeException("offset");
36 }
37 if (count < 0 || count > content.Length - offset)
38 {
39 throw new ArgumentOutOfRangeException("count");
40 }
41 _content = content;
43 _count = count;
44 }
45
50
52 {
54 }
55
57 {
58 if (!(GetType() == typeof(ByteArrayContent)))
59 {
60 return base.SerializeToStreamAsync(stream, context, cancellationToken);
61 }
63 }
64
69
70 protected internal override bool TryComputeLength(out long length)
71 {
72 length = _count;
73 return true;
74 }
75
80
82 {
83 return Task.FromResult((Stream)CreateMemoryStreamForByteArray());
84 }
85
87 {
88 if (!(GetType() == typeof(ByteArrayContent)))
89 {
90 return null;
91 }
93 }
94
96 {
97 return new MemoryStream(_content, _offset, _count, writable: false);
98 }
99}
ByteArrayContent(byte[] content, int offset, int count)
override bool TryComputeLength(out long length)
override Stream TryCreateContentReadStream()
override Task SerializeToStreamAsync(Stream stream, TransportContext? context)
Task SerializeToStreamAsyncCore(Stream stream, CancellationToken cancellationToken)
override Task< Stream > CreateContentReadStreamAsync()
override Stream CreateContentReadStream(CancellationToken cancellationToken)
override Task SerializeToStreamAsync(Stream stream, TransportContext? context, CancellationToken cancellationToken)
override void SerializeToStream(Stream stream, TransportContext? context, CancellationToken cancellationToken)