2
0

DelegatingStream.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. namespace FastGithub.FlowAnalyze
  6. {
  7. abstract class DelegatingStream : Stream
  8. {
  9. protected Stream Inner { get; }
  10. public DelegatingStream(Stream inner)
  11. {
  12. this.Inner = inner;
  13. }
  14. public override bool CanRead
  15. {
  16. get
  17. {
  18. return this.Inner.CanRead;
  19. }
  20. }
  21. public override bool CanSeek
  22. {
  23. get
  24. {
  25. return this.Inner.CanSeek;
  26. }
  27. }
  28. public override bool CanWrite
  29. {
  30. get
  31. {
  32. return this.Inner.CanWrite;
  33. }
  34. }
  35. public override long Length
  36. {
  37. get
  38. {
  39. return this.Inner.Length;
  40. }
  41. }
  42. public override long Position
  43. {
  44. get
  45. {
  46. return this.Inner.Position;
  47. }
  48. set
  49. {
  50. this.Inner.Position = value;
  51. }
  52. }
  53. public override void Flush()
  54. {
  55. this.Inner.Flush();
  56. }
  57. public override Task FlushAsync(CancellationToken cancellationToken)
  58. {
  59. return this.Inner.FlushAsync(cancellationToken);
  60. }
  61. public override int Read(byte[] buffer, int offset, int count)
  62. {
  63. return this.Inner.Read(buffer, offset, count);
  64. }
  65. public override int Read(Span<byte> destination)
  66. {
  67. return this.Inner.Read(destination);
  68. }
  69. public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
  70. {
  71. return this.Inner.ReadAsync(buffer, offset, count, cancellationToken);
  72. }
  73. public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
  74. {
  75. return this.Inner.ReadAsync(destination, cancellationToken);
  76. }
  77. public override long Seek(long offset, SeekOrigin origin)
  78. {
  79. return this.Inner.Seek(offset, origin);
  80. }
  81. public override void SetLength(long value)
  82. {
  83. this.Inner.SetLength(value);
  84. }
  85. public override void Write(byte[] buffer, int offset, int count)
  86. {
  87. this.Inner.Write(buffer, offset, count);
  88. }
  89. public override void Write(ReadOnlySpan<byte> source)
  90. {
  91. this.Inner.Write(source);
  92. }
  93. public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
  94. {
  95. return this.Inner.WriteAsync(buffer, offset, count, cancellationToken);
  96. }
  97. public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
  98. {
  99. return this.Inner.WriteAsync(source, cancellationToken);
  100. }
  101. public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
  102. {
  103. return TaskToApm.Begin(ReadAsync(buffer, offset, count), callback, state);
  104. }
  105. public override int EndRead(IAsyncResult asyncResult)
  106. {
  107. return TaskToApm.End<int>(asyncResult);
  108. }
  109. public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
  110. {
  111. return TaskToApm.Begin(WriteAsync(buffer, offset, count), callback, state);
  112. }
  113. public override void EndWrite(IAsyncResult asyncResult)
  114. {
  115. TaskToApm.End(asyncResult);
  116. }
  117. }
  118. }