Buffer.Read C# (CSharp) Method

Read() public method

public Read ( ) : int
return int
    public virtual int Read()
    {
        if (bufPos < bufLen) {
            return buf[bufPos++];
        } else if (Pos < fileLen) {
            Pos = Pos; // shift buffer start to Pos
            return buf[bufPos++];
        } else if (stream != null && !stream.CanSeek && ReadNextStreamChunk() > 0) {
            return buf[bufPos++];
        } else {
            return EOF;
        }
    }

Usage Example

        public override int Read(byte[] buffer, int offset, int count)
        {
            int read = 0;

            while (read < count)
            {
                // Ensure a buffer is available
                if (TakeBuffer())
                {
                    // Get as much as we can from the current buffer
                    read += _current.Read(buffer, offset + read, count - read);
                    if (_current.Count == 0)
                    {
                        // Used up this buffer, return to the pool if it's a pool buffer
                        if (_current.FromPool)
                        {
                            _pool.Add(_current);
                        }
                        _current = null;
                    }
                }
                else
                {
                    break;
                }
            }
            return(read);
        }
All Usage Examples Of Buffer::Read