コード例 #1
0
 public sealed override void Write(byte[] array, int offset, int count)
 {
     this.AssertOpen();
     if (!this.CanWrite)
     {
         throw new NotSupportedException(EncodersStrings.EncStrCannotWrite);
     }
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     if (count + offset > array.Length)
     {
         throw new ArgumentException(EncodersStrings.EncStrLengthExceeded(offset + count, array.Length), "array");
     }
     if (0 > offset || 0 > count)
     {
         throw new ArgumentOutOfRangeException((offset < 0) ? "offset" : "count");
     }
     while (count != 0)
     {
         int  num;
         int  count2;
         bool flag;
         this.encoder.Convert(array, offset, count, this.buffer, 0, this.buffer.Length, false, out num, out count2, out flag);
         count         -= num;
         offset        += num;
         this.position += (long)num;
         this.stream.Write(this.buffer, 0, count2);
     }
 }
コード例 #2
0
        public sealed override int Read(byte[] array, int offset, int count)
        {
            this.AssertOpen();
            if (!this.CanRead)
            {
                throw new NotSupportedException(EncodersStrings.EncStrCannotRead);
            }
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (offset + count > array.Length)
            {
                throw new ArgumentOutOfRangeException("offset, count", EncodersStrings.EncStrLengthExceeded(offset + count, array.Length));
            }
            if (0 > offset || 0 > count)
            {
                throw new ArgumentOutOfRangeException((offset < 0) ? "offset" : "count");
            }
            int num = 0;

            while (!this.endOfFile && count != 0)
            {
                if (this.bufferCount == 0)
                {
                    this.bufferPos   = 0;
                    this.bufferCount = this.stream.Read(this.buffer, 0, 4096);
                }
                int  num2;
                int  num3;
                bool flag;
                this.encoder.Convert(this.buffer, this.bufferPos, this.bufferCount, array, offset, count, this.bufferCount == 0, out num2, out num3, out flag);
                if (this.bufferCount == 0 && flag)
                {
                    this.endOfFile = true;
                }
                count            -= num3;
                offset           += num3;
                num              += num3;
                this.position    += (long)num3;
                this.bufferPos   += num2;
                this.bufferCount -= num2;
            }
            return(num);
        }