BaseOutputStream.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 abstract class BaseOutputStream : Stream
  9. {
  10. private bool closed;
  11. public sealed override bool CanRead { get { return false; } }
  12. public sealed override bool CanSeek { get { return false; } }
  13. public sealed override bool CanWrite { get { return !closed; } }
  14. #if PORTABLE || NETFX_CORE
  15. protected override void Dispose(bool disposing)
  16. {
  17. if (disposing)
  18. {
  19. closed = true;
  20. }
  21. base.Dispose(disposing);
  22. }
  23. #else
  24. public override void Close()
  25. {
  26. closed = true;
  27. base.Close();
  28. }
  29. #endif
  30. public override void Flush() { }
  31. public sealed override long Length { get { throw new NotSupportedException(); } }
  32. public sealed override long Position
  33. {
  34. get { throw new NotSupportedException(); }
  35. set { throw new NotSupportedException(); }
  36. }
  37. public sealed override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); }
  38. public sealed override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); }
  39. public sealed override void SetLength(long value) { throw new NotSupportedException(); }
  40. public override void Write(byte[] buffer, int offset, int count)
  41. {
  42. Debug.Assert(buffer != null);
  43. Debug.Assert(0 <= offset && offset <= buffer.Length);
  44. Debug.Assert(count >= 0);
  45. int end = offset + count;
  46. Debug.Assert(0 <= end && end <= buffer.Length);
  47. for (int i = offset; i < end; ++i)
  48. {
  49. this.WriteByte(buffer[i]);
  50. }
  51. }
  52. public virtual void Write(params byte[] buffer)
  53. {
  54. Write(buffer, 0, buffer.Length);
  55. }
  56. public override void WriteByte(byte b)
  57. {
  58. Write(new byte[]{ b }, 0, 1);
  59. }
  60. }
  61. }
  62. #pragma warning restore
  63. #endif