Flush() public méthode

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
Résultat void
Exemple #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);
            }
        }
Exemple #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);
                }
            }
        }
Exemple #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();
        }
Exemple #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);
		}
Exemple #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 ();
		}