private void ClearReadBufferBeforeWrite()
{
Debug.Assert(_readPos <= _readLen, "_readPos <= _readLen [" + _readPos + " <= " + _readLen + "]");
// No read data in the buffer:
if (_readPos == _readLen)
{
_readPos = _readLen = 0;
return;
}
// Must have read data.
Debug.Assert(_readPos < _readLen);
// If the underlying stream cannot seek, FlushRead would end up throwing NotSupported.
// However, since the user did not call a method that is intuitively expected to seek, a better message is in order.
// Ideally, we would throw an InvalidOperation here, but for backward compat we have to stick with NotSupported.
if (!_stream.CanSeek)
throw new NotSupportedException(SR.NotSupported_CannotWriteToBufferedStreamIfReadBufferCannotBeFlushed);
FlushRead();
}