| | 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 | |
|
| 0 | 15 | | public StringRequestContent(string value) |
| | 16 | | { |
| 0 | 17 | | _bytes = Encoding.UTF8.GetBytes(value); |
| 0 | 18 | | } |
| | 19 | |
|
| | 20 | | public override async Task WriteToAsync(Stream stream, CancellationToken cancellation) |
| | 21 | | { |
| 0 | 22 | | await stream.WriteAsync(_bytes, 0, _bytes.Length, cancellation).ConfigureAwait(false); |
| 0 | 23 | | } |
| | 24 | |
|
| | 25 | | public override void WriteTo(Stream stream, CancellationToken cancellation) |
| | 26 | | { |
| 0 | 27 | | stream.Write(_bytes, 0, _bytes.Length); |
| 0 | 28 | | } |
| | 29 | |
|
| | 30 | | public override bool TryComputeLength(out long length) |
| | 31 | | { |
| 0 | 32 | | length = _bytes.Length; |
| 0 | 33 | | return true; |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public override void Dispose() |
| | 37 | | { |
| 0 | 38 | | } |
| | 39 | | } |
| | 40 | | } |