File: NotSeekableStream.cs
Web Access
Project: src\bench\Libraries\Microsoft.Extensions.Http.Diagnostics.PerformanceTests\Microsoft.Extensions.Http.Diagnostics.PerformanceTests.csproj (Microsoft.Extensions.Http.Diagnostics.PerformanceTests)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
 
namespace Microsoft.Extensions.Http.Logging.Bench;
 
internal sealed class NotSeekableStream : Stream
{
    private readonly MemoryStream _innerStream;
 
    public NotSeekableStream(MemoryStream memoryStream)
    {
        _innerStream = memoryStream;
    }
 
    public override bool CanRead => true;
 
    public override bool CanSeek => false;
 
    public override bool CanWrite => true;
 
    public override long Length => _innerStream.Length;
 
    public override long Position { get => _innerStream.Position; set => throw new NotSupportedException("This is not a seekable stream."); }
 
    public override void Flush() => _innerStream.Flush();
 
    public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => _innerStream.ReadAsync(buffer, offset, count, cancellationToken);
 
    public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) => _innerStream.ReadAsync(buffer, cancellationToken);
 
    public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => _innerStream.WriteAsync(buffer, offset, count, cancellationToken);
 
    public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) => _innerStream.WriteAsync(buffer, cancellationToken);
 
    public override int Read(byte[] buffer, int offset, int count) => _innerStream.Read(buffer, offset, count);
 
    public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException("This is not a seekable stream.");
 
    public override void SetLength(long value) => _innerStream.SetLength(value);
 
    public override void Write(byte[] buffer, int offset, int count) => _innerStream.Write(buffer, offset, count);
}