| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.IO; |
| | | 6 | | using System.Threading; |
| | | 7 | | using System.Threading.Tasks; |
| | | 8 | | |
| | | 9 | | namespace System.IO |
| | | 10 | | { |
| | | 11 | | // Forwards all calls to an inner stream except where overridden in a derived class. |
| | | 12 | | internal abstract class DelegatingStream : Stream |
| | | 13 | | { |
| | | 14 | | private readonly Stream _innerStream; |
| | | 15 | | |
| | | 16 | | #region Properties |
| | | 17 | | |
| | | 18 | | public override bool CanRead |
| | | 19 | | { |
| | 0 | 20 | | get { return _innerStream.CanRead; } |
| | | 21 | | } |
| | | 22 | | |
| | | 23 | | public override bool CanSeek |
| | | 24 | | { |
| | 0 | 25 | | get { return _innerStream.CanSeek; } |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | public override bool CanWrite |
| | | 29 | | { |
| | 0 | 30 | | get { return _innerStream.CanWrite; } |
| | | 31 | | } |
| | | 32 | | |
| | | 33 | | public override long Length |
| | | 34 | | { |
| | 0 | 35 | | get { return _innerStream.Length; } |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public override long Position |
| | | 39 | | { |
| | 0 | 40 | | get { return _innerStream.Position; } |
| | 0 | 41 | | set { _innerStream.Position = value; } |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public override int ReadTimeout |
| | | 45 | | { |
| | 0 | 46 | | get { return _innerStream.ReadTimeout; } |
| | 0 | 47 | | set { _innerStream.ReadTimeout = value; } |
| | | 48 | | } |
| | | 49 | | |
| | | 50 | | public override bool CanTimeout |
| | | 51 | | { |
| | 0 | 52 | | get { return _innerStream.CanTimeout; } |
| | | 53 | | } |
| | | 54 | | |
| | | 55 | | public override int WriteTimeout |
| | | 56 | | { |
| | 0 | 57 | | get { return _innerStream.WriteTimeout; } |
| | 0 | 58 | | set { _innerStream.WriteTimeout = value; } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | #endregion Properties |
| | | 62 | | |
| | 0 | 63 | | protected DelegatingStream(Stream innerStream) |
| | 0 | 64 | | { |
| | 0 | 65 | | Debug.Assert(innerStream != null); |
| | 0 | 66 | | _innerStream = innerStream; |
| | 0 | 67 | | } |
| | | 68 | | |
| | | 69 | | protected override void Dispose(bool disposing) |
| | 0 | 70 | | { |
| | 0 | 71 | | if (disposing) |
| | 0 | 72 | | { |
| | 0 | 73 | | _innerStream.Dispose(); |
| | 0 | 74 | | } |
| | 0 | 75 | | base.Dispose(disposing); |
| | 0 | 76 | | } |
| | | 77 | | |
| | | 78 | | public override ValueTask DisposeAsync() |
| | 0 | 79 | | { |
| | 0 | 80 | | return _innerStream.DisposeAsync(); |
| | 0 | 81 | | } |
| | | 82 | | |
| | | 83 | | #region Read |
| | | 84 | | |
| | | 85 | | public override long Seek(long offset, SeekOrigin origin) |
| | 0 | 86 | | { |
| | 0 | 87 | | return _innerStream.Seek(offset, origin); |
| | 0 | 88 | | } |
| | | 89 | | |
| | | 90 | | public override int Read(byte[] buffer, int offset, int count) |
| | 0 | 91 | | { |
| | 0 | 92 | | return _innerStream.Read(buffer, offset, count); |
| | 0 | 93 | | } |
| | | 94 | | |
| | | 95 | | public override int Read(Span<byte> buffer) |
| | 0 | 96 | | { |
| | 0 | 97 | | return _innerStream.Read(buffer); |
| | 0 | 98 | | } |
| | | 99 | | |
| | | 100 | | public override int ReadByte() |
| | 0 | 101 | | { |
| | 0 | 102 | | return _innerStream.ReadByte(); |
| | 0 | 103 | | } |
| | | 104 | | |
| | | 105 | | public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) |
| | 0 | 106 | | { |
| | 0 | 107 | | return _innerStream.ReadAsync(buffer, offset, count, cancellationToken); |
| | 0 | 108 | | } |
| | | 109 | | |
| | | 110 | | public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) |
| | 0 | 111 | | { |
| | 0 | 112 | | return _innerStream.ReadAsync(buffer, cancellationToken); |
| | 0 | 113 | | } |
| | | 114 | | |
| | | 115 | | public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? st |
| | 0 | 116 | | { |
| | 0 | 117 | | return _innerStream.BeginRead(buffer, offset, count, callback, state); |
| | 0 | 118 | | } |
| | | 119 | | |
| | | 120 | | public override int EndRead(IAsyncResult asyncResult) |
| | 0 | 121 | | { |
| | 0 | 122 | | return _innerStream.EndRead(asyncResult); |
| | 0 | 123 | | } |
| | | 124 | | |
| | | 125 | | public override void CopyTo(Stream destination, int bufferSize) |
| | 0 | 126 | | { |
| | 0 | 127 | | _innerStream.CopyTo(destination, bufferSize); |
| | 0 | 128 | | } |
| | | 129 | | |
| | | 130 | | public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) |
| | 0 | 131 | | { |
| | 0 | 132 | | return _innerStream.CopyToAsync(destination, bufferSize, cancellationToken); |
| | 0 | 133 | | } |
| | | 134 | | |
| | | 135 | | #endregion Read |
| | | 136 | | |
| | | 137 | | #region Write |
| | | 138 | | |
| | | 139 | | public override void Flush() |
| | 0 | 140 | | { |
| | 0 | 141 | | _innerStream.Flush(); |
| | 0 | 142 | | } |
| | | 143 | | |
| | | 144 | | public override Task FlushAsync(CancellationToken cancellationToken) |
| | 0 | 145 | | { |
| | 0 | 146 | | return _innerStream.FlushAsync(cancellationToken); |
| | 0 | 147 | | } |
| | | 148 | | |
| | | 149 | | public override void SetLength(long value) |
| | 0 | 150 | | { |
| | 0 | 151 | | _innerStream.SetLength(value); |
| | 0 | 152 | | } |
| | | 153 | | |
| | | 154 | | public override void Write(byte[] buffer, int offset, int count) |
| | 0 | 155 | | { |
| | 0 | 156 | | _innerStream.Write(buffer, offset, count); |
| | 0 | 157 | | } |
| | | 158 | | |
| | | 159 | | public override void Write(ReadOnlySpan<byte> buffer) |
| | 0 | 160 | | { |
| | 0 | 161 | | _innerStream.Write(buffer); |
| | 0 | 162 | | } |
| | | 163 | | |
| | | 164 | | public override void WriteByte(byte value) |
| | 0 | 165 | | { |
| | 0 | 166 | | _innerStream.WriteByte(value); |
| | 0 | 167 | | } |
| | | 168 | | |
| | | 169 | | public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) |
| | 0 | 170 | | { |
| | 0 | 171 | | return _innerStream.WriteAsync(buffer, offset, count, cancellationToken); |
| | 0 | 172 | | } |
| | | 173 | | |
| | | 174 | | public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) |
| | 0 | 175 | | { |
| | 0 | 176 | | return _innerStream.WriteAsync(buffer, cancellationToken); |
| | 0 | 177 | | } |
| | | 178 | | |
| | | 179 | | public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? s |
| | 0 | 180 | | { |
| | 0 | 181 | | return _innerStream.BeginWrite(buffer, offset, count, callback, state); |
| | 0 | 182 | | } |
| | | 183 | | |
| | | 184 | | public override void EndWrite(IAsyncResult asyncResult) |
| | 0 | 185 | | { |
| | 0 | 186 | | _innerStream.EndWrite(asyncResult); |
| | 0 | 187 | | } |
| | | 188 | | #endregion Write |
| | | 189 | | } |
| | | 190 | | } |