Flush() public method

Clears all output buffers for this stream and causes any buffered data to be written to the underlying device.
Clears all output buffers for this stream and causes any buffered data to be written to the underlying device.
/// The stream has been disposed. /// /// The stream does not support writing. /// /// An I/O error occurred. ///
public Flush ( ) : void
return void
コード例 #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);
        }
コード例 #2
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.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);
            }
        }
コード例 #3
0
ファイル: ImapCommand.cs プロジェクト: todlewin/MailKit
        /// <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);
                }
            }
        }
コード例 #4
0
ファイル: ImapCommand.cs プロジェクト: yasart/MailKit
        /// <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();
        }
コード例 #5
0
ファイル: ImapCommand.cs プロジェクト: BehnamEmamian/MailKit
		/// <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);
		}
コード例 #6
0
ファイル: ImapCommand.cs プロジェクト: richard2753/MailKit
		/// <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 ();
		}