System.Data.SqlClient.SqlCachedStream.Read C# (CSharp) Méthode

Read() public méthode

public Read ( byte buffer, int offset, int count ) : int
buffer byte
offset int
count int
Résultat int
        override public int Read(byte[] buffer, int offset, int count)
        {
            int cb;
            int intCount = 0;

            if (null == _cachedBytes)
            {
                throw ADP.StreamClosed();
            }

            if (null == buffer)
            {
                throw ADP.ArgumentNull(nameof(buffer));
            }

            if ((offset < 0) || (count < 0))
            {
                throw ADP.ArgumentOutOfRange(String.Empty, (offset < 0 ? nameof(offset) : nameof(count)));
            }

            if (buffer.Length - offset < count)
            {
                throw ADP.ArgumentOutOfRange(nameof(count));
            }

            if (_cachedBytes.Count <= _currentArrayIndex)
            {
                return 0;       // Everything is read!
            }

            while (count > 0)
            {
                if (_cachedBytes[_currentArrayIndex].Length <= _currentPosition)
                {
                    _currentArrayIndex++;       // We are done reading this chunk, go to next
                    if (_cachedBytes.Count > _currentArrayIndex)
                    {
                        _currentPosition = 0;
                    }
                    else
                    {
                        break;
                    }
                }
                cb = _cachedBytes[_currentArrayIndex].Length - _currentPosition;
                if (cb > count)
                    cb = count;
                Buffer.BlockCopy(_cachedBytes[_currentArrayIndex], _currentPosition, buffer, offset, cb);

                _currentPosition += cb;
                count -= (int)cb;
                offset += (int)cb;
                intCount += (int)cb;
            }

            return intCount;
        }