public override void Write(byte[] buffer, int offset, int count)
{
// Basic checks.
if(null == buffer) throw new ArgumentNullException("buffer", "Buffer cannot be null.");
if(offset < 0) throw new ArgumentOutOfRangeException("offset", "Non-negative number required.");
if(count < 0) throw new ArgumentOutOfRangeException("count", "Non-negative number required.");
if((buffer.Length - offset) < count) {
throw new ArgumentException("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
}
if(!this._isOpen) throw new ObjectDisposedException("Stream is closed.");
if(0 == count)
{ // Nothing to do.
return;
}
// Determine new position (post write).
int endPos = _position + count;
// Check for overflow
if(endPos < 0) throw new IOException("Stream was too long.");
// Ensure there are enough blocks ready to write all of the provided data into.
EnsureCapacity(endPos);
// Write the bytes into the stream.
int blockIdx = _position / _blockSize;
int blockOffset = _position % _blockSize;
WriteInner(buffer, offset, count, blockIdx, blockOffset);
}