Example #1
0
        /// <summary>
        /// Writes a sequence of bytes to the stream and advances the current
        /// position within this stream by the number of bytes written.
        /// </summary>
        /// <remarks>
        /// Increments the <see cref="Position"/> property by the number of bytes written.
        /// If the updated position is greater than the current length of the stream, then
        /// the <see cref="Length"/> property will be updated to be identical to the
        /// position.
        /// </remarks>
        /// <param name="buffer">The buffer to write.</param>
        /// <param name="offset">The offset of the first byte to write.</param>
        /// <param name="count">The number of bytes to write.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="buffer"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <para><paramref name="offset"/> is less than zero or greater than the length of <paramref name="buffer"/>.</para>
        /// <para>-or-</para>
        /// <para>The <paramref name="buffer"/> is not large enough to contain <paramref name="count"/> bytes starting
        /// at the specified <paramref name="offset"/>.</para>
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The stream has been disposed.
        /// </exception>
        /// <exception cref="System.NotSupportedException">
        /// The stream does not support writing.
        /// </exception>
        /// <exception cref="System.IO.IOException">
        /// An I/O error occurred.
        /// </exception>
        public override void Write(byte[] buffer, int offset, int count)
        {
            CheckDisposed();

            ValidateArguments(buffer, offset, count);

            int n = max >= 0 && length + count > max ? max - length : count;

#if ENABLE_NATIVE_DKIM
            digest.TransformBlock(buffer, offset, count, null, 0);
#else
            digest.BlockUpdate(buffer, offset, n);
#endif

            length += n;
        }