public override void WriteBase64(byte[] buffer, int offset, int count)
{
if (IsClosed)
ThrowClosed();
if (buffer == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(buffer)));
// Not checking upper bound because it will be caught by "count". This is what XmlTextWriter does.
if (offset < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(offset), SR.Format(SR.ValueMustBeNonNegative)));
if (count < 0)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.ValueMustBeNonNegative)));
if (count > buffer.Length - offset)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(count), SR.Format(SR.SizeExceedsRemainingBufferSpace, buffer.Length - offset)));
if (count > 0)
{
if (_trailByteCount > 0)
{
while (_trailByteCount < 3 && count > 0)
{
_trailBytes[_trailByteCount++] = buffer[offset++];
count--;
}
}
int totalByteCount = _trailByteCount + count;
int actualByteCount = totalByteCount - (totalByteCount % 3);
if (_trailBytes == null)
{
_trailBytes = new byte[3];
}
if (actualByteCount >= 3)
{
if (_attributeValue != null)
{
WriteAttributeText(XmlConverter.Base64Encoding.GetString(_trailBytes, 0, _trailByteCount));
WriteAttributeText(XmlConverter.Base64Encoding.GetString(buffer, offset, actualByteCount - _trailByteCount));
}
if (!_isXmlnsAttribute)
{
StartContent();
_writer.WriteBase64Text(_trailBytes, _trailByteCount, buffer, offset, actualByteCount - _trailByteCount);
EndContent();
}
_trailByteCount = (totalByteCount - actualByteCount);
if (_trailByteCount > 0)
{
int trailOffset = offset + count - _trailByteCount;
for (int i = 0; i < _trailByteCount; i++)
_trailBytes[i] = buffer[trailOffset++];
}
}
else
{
Buffer.BlockCopy(buffer, offset, _trailBytes, _trailByteCount, count);
_trailByteCount += count;
}
}
}