public override void Write(byte[] buffer, int offset, int count)
{
if (rwMode != RwMode.Write)
{
_exceptionPending = true;
throw new InvalidOperationException("Stream Error: Cannot Write.");
}
if (ContiguousWrite)
{
// enough space for a contiguous write?
if (_innerStream.Position + count > _maxSegmentSize)
_SetWriteStream(1);
}
else
{
while (_innerStream.Position + count > _maxSegmentSize)
{
int c = unchecked(_maxSegmentSize - (int)_innerStream.Position);
_innerStream.Write(buffer, offset, c);
_SetWriteStream(1);
count -= c;
offset += c;
}
}
_innerStream.Write(buffer, offset, count);
}