BaseOutputStream.cs 2.0 KB

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