TeeOutputStream.cs 1.2 KB

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