示例#1
0
        internal void write(int b)
        {
            if (_overflow != null)
            {
                _overflow.WriteByte((byte)b);
                return;
            }

            Block s = last();
            if (s.isFull())
            {
                if (reachedInCoreLimit())
                {
                    _overflow.WriteByte((byte)b);
                    return;
                }

                s = new Block();
                _blocks.Add(s);
            }
            s.buffer[s.count++] = (byte)b;
        }
示例#2
0
        internal void write(byte[] b, int off, int len)
        {
            if (_overflow == null)
            {
                while (len > 0)
                {
                    Block s = last();
                    if (s.isFull())
                    {
                        if (reachedInCoreLimit())
                            break;

                        s = new Block();
                        _blocks.Add(s);
                    }

                    int n = Math.Min(Block.SZ - s.count, len);
                    Array.Copy(b, off, s.buffer, s.count, n);
                    s.count += n;
                    len -= n;
                    off += n;
                }
            }

            if (len > 0)
                _overflow.Write(b, off, len);
        }
示例#3
0
        /// <summary>
        /// Copy all bytes remaining on the input stream into this buffer.
        /// </summary>
        /// <param name="in">the stream to Read from, until EOF is reached.</param>
        internal void copy(Stream @in)
        {
            if (@in == null)
                throw new ArgumentNullException("in");

            if (_blocks != null)
            {
                for (; ; )
                {
                    Block s = last();
                    if (s.isFull())
                    {
                        if (reachedInCoreLimit())
                            break;
                        s = new Block();
                        _blocks.Add(s);
                    }

                    int n = @in.Read(s.buffer, s.count, Block.SZ - s.count);
                    if (n < 1)
                        return;
                    s.count += n;
                }
            }

            byte[] tmp = new byte[Block.SZ];
            int nn;
            while ((nn = @in.Read(tmp, 0, tmp.Length)) > 0)
                _overflow.Write(tmp, 0, nn);
        }