Example #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);
     }
 }
Example #2
0
        public Stream Clone()
        {
            this.AssertOpen();
            if (EncoderStreamAccess.Write == this.access)
            {
                throw new NotSupportedException(EncodersStrings.EncStrCannotCloneWriteableStream);
            }
            ICloneableStream cloneableStream = this.stream as ICloneableStream;

            if (cloneableStream == null && this.stream.CanSeek)
            {
                this.stream     = new AutoPositionReadOnlyStream(this.stream, this.ownsStream);
                this.ownsStream = true;
                cloneableStream = (this.stream as ICloneableStream);
            }
            if (cloneableStream != null)
            {
                EncoderStream encoderStream = base.MemberwiseClone() as EncoderStream;
                encoderStream.buffer  = (this.buffer.Clone() as byte[]);
                encoderStream.stream  = cloneableStream.Clone();
                encoderStream.encoder = this.encoder.Clone();
                return(encoderStream);
            }
            throw new NotSupportedException(EncodersStrings.EncStrCannotCloneChildStream(this.stream.GetType().ToString()));
        }
Example #3
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);
        }
Example #4
0
 public virtual ByteEncoder Clone()
 {
     throw new NotSupportedException(EncodersStrings.ThisEncoderDoesNotSupportCloning(base.GetType().ToString()));
 }