123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #region Copyright notice and license
- #endregion
-
- using System;
- using System.IO;
- namespace Google.Protobuf
- {
-
-
-
-
-
- internal sealed class LimitedInputStream : Stream
- {
- private readonly Stream proxied;
- private int bytesLeft;
- internal LimitedInputStream(Stream proxied, int size)
- {
- this.proxied = proxied;
- bytesLeft = size;
- }
- public override bool CanRead
- {
- get { return true; }
- }
- public override bool CanSeek
- {
- get { return false; }
- }
- public override bool CanWrite
- {
- get { return false; }
- }
- public override void Flush()
- {
- }
- public override long Length
- {
- get { throw new NotSupportedException(); }
- }
- public override long Position
- {
- get { throw new NotSupportedException(); }
- set { throw new NotSupportedException(); }
- }
- public override int Read(byte[] buffer, int offset, int count)
- {
- if (bytesLeft > 0)
- {
- int bytesRead = proxied.Read(buffer, offset, Math.Min(bytesLeft, count));
- bytesLeft -= bytesRead;
- return bytesRead;
- }
- return 0;
- }
- public override long Seek(long offset, SeekOrigin origin)
- {
- throw new NotSupportedException();
- }
- public override void SetLength(long value)
- {
- throw new NotSupportedException();
- }
- public override void Write(byte[] buffer, int offset, int count)
- {
- throw new NotSupportedException();
- }
- }
- }
|