TeeOutputStream.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Diagnostics;
  5. using System.IO;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
  7. {
  8. public class TeeOutputStream
  9. : BaseOutputStream
  10. {
  11. private readonly Stream output, tee;
  12. public TeeOutputStream(Stream output, Stream tee)
  13. {
  14. Debug.Assert(output.CanWrite);
  15. Debug.Assert(tee.CanWrite);
  16. this.output = output;
  17. this.tee = tee;
  18. }
  19. protected override void Dispose(bool disposing)
  20. {
  21. if (disposing)
  22. {
  23. output.Dispose();
  24. tee.Dispose();
  25. }
  26. base.Dispose(disposing);
  27. }
  28. public override void Write(byte[] buffer, int offset, int count)
  29. {
  30. output.Write(buffer, offset, count);
  31. tee.Write(buffer, offset, count);
  32. }
  33. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  34. public override void Write(ReadOnlySpan<byte> buffer)
  35. {
  36. output.Write(buffer);
  37. tee.Write(buffer);
  38. }
  39. #endif
  40. public override void WriteByte(byte value)
  41. {
  42. output.WriteByte(value);
  43. tee.WriteByte(value);
  44. }
  45. }
  46. }
  47. #pragma warning restore
  48. #endif