| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System.IO; |
| | 5 | | using System.Text; |
| | 6 | | using System.Threading; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | |
|
| | 9 | | namespace Azure.Core |
| | 10 | | { |
| | 11 | | internal class StringRequestContent : RequestContent |
| | 12 | | { |
| | 13 | | private readonly byte[] _bytes; |
| | 14 | |
|
| 104 | 15 | | public StringRequestContent(string value) |
| | 16 | | { |
| 104 | 17 | | _bytes = Encoding.UTF8.GetBytes(value); |
| 104 | 18 | | } |
| | 19 | |
|
| | 20 | | public override async Task WriteToAsync(Stream stream, CancellationToken cancellation) |
| | 21 | | { |
| 52 | 22 | | await stream.WriteAsync(_bytes, 0, _bytes.Length, cancellation).ConfigureAwait(false); |
| 52 | 23 | | } |
| | 24 | |
|
| | 25 | | public override void WriteTo(Stream stream, CancellationToken cancellation) |
| | 26 | | { |
| 156 | 27 | | stream.Write(_bytes, 0, _bytes.Length); |
| 156 | 28 | | } |
| | 29 | |
|
| | 30 | | public override bool TryComputeLength(out long length) |
| | 31 | | { |
| 208 | 32 | | length = _bytes.Length; |
| 208 | 33 | | return true; |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public override void Dispose() |
| | 37 | | { |
| 0 | 38 | | } |
| | 39 | | } |
| | 40 | | } |