public void SetStream(HttpContentStream stream)
            {
                Debug.Assert(stream != null);
                Debug.Assert(stream.CanRead);

                _stream = stream;
            }
Esempio n. 2
0
            internal sealed override async Task SerializeToStreamAsync(Stream stream, TransportContext context, CancellationToken cancellationToken)
            {
                Debug.Assert(stream != null);

                using (HttpContentStream contentStream = ConsumeStream())
                {
                    const int BufferSize = 8192;
                    await contentStream.CopyToAsync(stream, BufferSize, cancellationToken).ConfigureAwait(false);
                }
            }
            private HttpContentStream ConsumeStream()
            {
                if (_stream == null)
                {
                    throw new InvalidOperationException(SR.net_http_content_stream_already_read);
                }

                HttpContentStream stream = _stream;

                _stream = null;
                return(stream);
            }
Esempio n. 4
0
            protected sealed override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (_stream != null)
                    {
                        _stream.Dispose();
                        _stream = null;
                    }
                }

                base.Dispose(disposing);
            }