BaseInputStream.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.IO
  6. {
  7. public abstract class BaseInputStream
  8. : Stream
  9. {
  10. public sealed override bool CanRead { get { return true; } }
  11. public sealed override bool CanSeek { get { return false; } }
  12. public sealed override bool CanWrite { get { return false; } }
  13. public sealed override void Flush() {}
  14. public sealed override long Length { get { throw new NotSupportedException(); } }
  15. public sealed override long Position
  16. {
  17. get { throw new NotSupportedException(); }
  18. set { throw new NotSupportedException(); }
  19. }
  20. public override int Read(byte[] buffer, int offset, int count)
  21. {
  22. Streams.ValidateBufferArguments(buffer, offset, count);
  23. int pos = 0;
  24. try
  25. {
  26. while (pos < count)
  27. {
  28. int b = ReadByte();
  29. if (b < 0)
  30. break;
  31. buffer[offset + pos++] = (byte)b;
  32. }
  33. }
  34. catch (IOException)
  35. {
  36. if (pos == 0)
  37. throw;
  38. }
  39. return pos;
  40. }
  41. public sealed override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); }
  42. public sealed override void SetLength(long value) { throw new NotSupportedException(); }
  43. public sealed override void Write(byte[] buffer, int offset, int count) { throw new NotSupportedException(); }
  44. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  45. public override void Write(ReadOnlySpan<byte> buffer) { throw new NotSupportedException(); }
  46. #endif
  47. }
  48. }
  49. #pragma warning restore
  50. #endif