Shared.MutableMemoryStream.Write C# (CSharp) Method

Write() public method

public Write ( byte buffer, int offset, int count ) : void
buffer byte
offset int
count int
return void
        public override void Write(byte[] buffer, int offset, int count)
        {
            if (buffer == null)
                throw new ArgumentNullException("buffer");

            if (offset < 0)
                throw new ArgumentOutOfRangeException("offset");

            if (count < 0)
                throw new ArgumentOutOfRangeException("count");

            if (buffer.Length - offset < count)
                throw new ArgumentException();

            if (!_isOpen)
                throw new InvalidOperationException();

            if (!CanWrite)
                throw new InvalidOperationException();

            var i = _position + count;
            if (i < 0)
                throw new IOException();

            if (i > _length)
            {
                var mustZero = _position > _length;
                if (i > _capacity)
                {
                    var allocatedNewArray = EnsureCapacity(i);
                    if (allocatedNewArray)
                        mustZero = false;
                }
                if (mustZero)
                    Array.Clear(_buffer, _length, i - _length);
                _length = i;
            }
            if ((count <= 8) && (buffer != _buffer))
            {
                var byteCount = count;
                while (--byteCount >= 0)
                    _buffer[_position + byteCount] = buffer[offset + byteCount];
            }
            else
                System.Buffer.BlockCopy(buffer, offset, _buffer, _position, count);

            _position = i;
        }