/// <inheritdoc />
        public int BufferNext(int count)
        {
            IBufferedArrayContracts.BufferNext(count);

            if (count == 0)
            {
                return(0);
            }

            int countToBuffer = this.GetTotalRemainingLength().ClampUpper(count);

            this.buffer.EnsureCapacity(countToBuffer);

            int countBuffered;

            for (countBuffered = 0; countBuffered < countToBuffer; countBuffered++)
            {
                if (!this.source.MoveNext())
                {
                    break;
                }

                this.buffer.Array[countBuffered] = this.source.Current;
            }

            this.totalCountBuffered += countBuffered;
            return(countBuffered);
        }
        /// <inheritdoc />
        public int BufferNext(int count)
        {
            IBufferedArrayContracts.BufferNext(count);

            this.buffer.EnsureCapacity(count);
            int countBuffered = 0;

            while (countBuffered < count)
            {
                int read = this.stream.Read(this.buffer.Array, countBuffered, count - countBuffered);
                if (read == 0)
                {
                    this.HasNext = false;
                    break;
                }
                else
                {
                    countBuffered += read;
                }
            }

            return(countBuffered);
        }