TeeOutputStream.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 BestHTTP.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. #if PORTABLE || NETFX_CORE
  20. protected override void Dispose(bool disposing)
  21. {
  22. if (disposing)
  23. {
  24. BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(output);
  25. BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(tee);
  26. }
  27. base.Dispose(disposing);
  28. }
  29. #else
  30. public override void Close()
  31. {
  32. BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(output);
  33. BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.Dispose(tee);
  34. base.Close();
  35. }
  36. #endif
  37. public override void Write(byte[] buffer, int offset, int count)
  38. {
  39. output.Write(buffer, offset, count);
  40. tee.Write(buffer, offset, count);
  41. }
  42. public override void WriteByte(byte b)
  43. {
  44. output.WriteByte(b);
  45. tee.WriteByte(b);
  46. }
  47. }
  48. }
  49. #pragma warning restore
  50. #endif