private int ReadByteSlow()
{
Debug.Assert(_readPos == _readLen);
// We want to check for whether the underlying stream has been closed and whether
// it's readable, but we only need to do so if we don't have data in our buffer,
// as any data we have came from reading it from an open stream, and we don't
// care if the stream has been closed or become unreadable since. Further, if
// the stream is closed, its read buffer is flushed, so we'll take this slow path.
EnsureNotClosed();
EnsureCanRead();
if (_writePos > 0)
FlushWrite();
EnsureBufferAllocated();
_readLen = _stream.Read(_buffer, 0, _bufferSize);
if (_readLen == 0)
return -1;
_readPos = 0;
return _buffer[_readPos++];
}