Write() public method

Writes a sequence of bytes to the stream and advances the current position within this stream by the number of bytes written.
Writes a sequence of bytes to the stream and advances the current position within this stream by the number of bytes written.
/// is null. /// /// is less than zero or greater than the length of . /// -or- /// The is not large enough to contain bytes strting /// at the specified . /// /// The stream has been disposed. /// /// The stream does not support writing. /// /// An I/O error occurred. ///
public Write ( byte buffer, int offset, int count ) : void
buffer byte The buffer to write.
offset int The offset of the first byte to write.
count int The number of bytes to write.
return void
Beispiel #1
0
        /// <summary>
        /// Write the literal to the specified stream.
        /// </summary>
        /// <remarks>
        /// Writes the literal to the specified stream.
        /// </remarks>
        /// <param name="stream">The stream.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public void WriteTo(ImapStream stream, CancellationToken cancellationToken)
        {
            if (Type == ImapLiteralType.String)
            {
                var bytes = (byte[])Literal;
                stream.Write(bytes, 0, bytes.Length, cancellationToken);
                stream.Flush(cancellationToken);
                return;
            }

            if (Type == ImapLiteralType.MimeMessage)
            {
                var message = (MimeMessage)Literal;

                message.WriteTo(format, stream, cancellationToken);
                stream.Flush(cancellationToken);
                return;
            }

            var literal = (Stream)Literal;
            var buf     = new byte[4096];
            int nread;

            while ((nread = literal.Read(buf, 0, buf.Length)) > 0)
            {
                stream.Write(buf, 0, nread, cancellationToken);
            }

            stream.Flush(cancellationToken);
        }
        /// <summary>
        /// Write the literal to the specified stream.
        /// </summary>
        /// <remarks>
        /// Writes the literal to the specified stream.
        /// </remarks>
        /// <param name="stream">The stream.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public void WriteTo(ImapStream stream, CancellationToken cancellationToken)
        {
            if (Type == ImapLiteralType.String)
            {
                var bytes = (byte[])Literal;

                stream.Write(bytes, 0, bytes.Length, cancellationToken);
                stream.Flush(cancellationToken);
                return;
            }

            //if (Type == ImapLiteralType.Stream) {
            //	var literal = (Stream) Literal;
            //	var buf = new byte[4096];
            //	int nread;

            //	while ((nread = literal.Read (buf, 0, buf.Length)) > 0)
            //		stream.Write (buf, 0, nread, cancellationToken);

            //	stream.Flush (cancellationToken);
            //	return;
            //}

            var message = (MimeMessage)Literal;

            using (var s = new ProgressStream(stream, update)) {
                message.WriteTo(format, s, cancellationToken);
                s.Flush(cancellationToken);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Write the literal to the specified stream.
        /// </summary>
        /// <remarks>
        /// Writes the literal to the specified stream.
        /// </remarks>
        /// <param name="stream">The stream.</param>
        /// <param name="doAsync">Whether the literal should be written asynchronously or not.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public async Task WriteToAsync(ImapStream stream, bool doAsync, CancellationToken cancellationToken)
        {
            if (Type == ImapLiteralType.String)
            {
                var bytes = (byte[])Literal;

                if (doAsync)
                {
                    await stream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false);

                    await stream.FlushAsync(cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    stream.Write(bytes, 0, bytes.Length, cancellationToken);
                    stream.Flush(cancellationToken);
                }
                return;
            }

            //if (Type == ImapLiteralType.Stream) {
            //	var literal = (Stream) Literal;
            //	var buf = new byte[4096];
            //	int nread;

            //	if (doAsync) {
            //		while ((nread = await literal.ReadAsync (buf, 0, buf.Length, cancellationToken).ConfigureAwait (false)) > 0)
            //			await stream.WriteAsync (buf, 0, nread, cancellationToken).ConfigureAwait (false);

            //		await stream.FlushAsync (cancellationToken).ConfigureAwait (false);
            //	} else {
            //		while ((nread = literal.Read (buf, 0, buf.Length)) > 0)
            //			stream.Write (buf, 0, nread, cancellationToken);

            //		stream.Flush (cancellationToken);
            //	}
            //	return;
            //}

            var message = (MimeMessage)Literal;

            using (var s = new ProgressStream(stream, update)) {
                if (doAsync)
                {
                    await message.WriteToAsync(format, s, cancellationToken).ConfigureAwait(false);

                    await s.FlushAsync(cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    message.WriteTo(format, s, cancellationToken);
                    s.Flush(cancellationToken);
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Writes the literal to the specified stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        public void WriteTo(ImapStream stream, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (Type == ImapLiteralType.String)
            {
                var bytes = (byte[])Literal;
                stream.Write(bytes, 0, bytes.Length);
                stream.Flush();
                return;
            }

            if (Type == ImapLiteralType.MimeMessage)
            {
                var options = FormatOptions.Default.Clone();
                options.NewLineFormat = NewLineFormat.Dos;

                var message = (MimeMessage)Literal;

                message.WriteTo(options, stream, cancellationToken);
                stream.Flush();
                return;
            }

            var literal = (Stream)Literal;
            var buf     = new byte[4096];
            int nread   = 0;

            while ((nread = literal.Read(buf, 0, buf.Length)) > 0)
            {
                cancellationToken.ThrowIfCancellationRequested();
                stream.Write(buf, 0, nread);
            }

            stream.Flush();
        }
Beispiel #5
0
		/// <summary>
		/// Write the literal to the specified stream.
		/// </summary>
		/// <remarks>
		/// Writes the literal to the specified stream.
		/// </remarks>
		/// <param name="stream">The stream.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		public void WriteTo (ImapStream stream, CancellationToken cancellationToken)
		{
			if (Type == ImapLiteralType.String) {
				var bytes = (byte[]) Literal;
				stream.Write (bytes, 0, bytes.Length, cancellationToken);
				stream.Flush (cancellationToken);
				return;
			}

			if (Type == ImapLiteralType.MimeMessage) {
				var message = (MimeMessage) Literal;

				using (var s = new ProgressStream (stream, update)) {
					message.WriteTo (format, s, cancellationToken);
					s.Flush (cancellationToken);
					return;
				}
			}

			var literal = (Stream) Literal;
			var buf = new byte[4096];
			int nread;

			while ((nread = literal.Read (buf, 0, buf.Length)) > 0)
				stream.Write (buf, 0, nread, cancellationToken);

			stream.Flush (cancellationToken);
		}
Beispiel #6
0
		/// <summary>
		/// Writes the literal to the specified stream.
		/// </summary>
		/// <param name="stream">The stream.</param>
		/// <param name="cancellationToken">The cancellation token.</param>
		public void WriteTo (ImapStream stream, CancellationToken cancellationToken)
		{
			cancellationToken.ThrowIfCancellationRequested ();

			if (Type == ImapLiteralType.String) {
				var bytes = (byte[]) Literal;
				stream.Write (bytes, 0, bytes.Length);
				stream.Flush ();
				return;
			}

			if (Type == ImapLiteralType.MimeMessage) {
				var options = FormatOptions.Default.Clone ();
				options.NewLineFormat = NewLineFormat.Dos;

				var message = (MimeMessage) Literal;

				message.WriteTo (options, stream, cancellationToken);
				stream.Flush ();
				return;
			}

			var literal = (Stream) Literal;
			var buf = new byte[4096];
			int nread = 0;

			while ((nread = literal.Read (buf, 0, buf.Length)) > 0) {
				cancellationToken.ThrowIfCancellationRequested ();
				stream.Write (buf, 0, nread);
			}

			stream.Flush ();
		}