12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
- #pragma warning disable
- using System;
- using System.Diagnostics;
- using System.IO;
- namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
- {
- public class TeeInputStream
- : BaseInputStream
- {
- private readonly Stream input, tee;
- public TeeInputStream(Stream input, Stream tee)
- {
- Debug.Assert(input.CanRead);
- Debug.Assert(tee.CanWrite);
- this.input = input;
- this.tee = tee;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- input.Dispose();
- tee.Dispose();
- }
- base.Dispose(disposing);
- }
- public override int Read(byte[] buffer, int offset, int count)
- {
- int i = input.Read(buffer, offset, count);
- if (i > 0)
- {
- tee.Write(buffer, offset, i);
- }
- return i;
- }
- #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
- public override int Read(Span<byte> buffer)
- {
- int i = input.Read(buffer);
- if (i > 0)
- {
- tee.Write(buffer[..i]);
- }
- return i;
- }
- #endif
- public override int ReadByte()
- {
- int i = input.ReadByte();
- if (i >= 0)
- {
- tee.WriteByte((byte)i);
- }
- return i;
- }
- }
- }
- #pragma warning restore
- #endif
|