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
Example #1
0
        async Task SendCommandAsync(Pop3Command pc, bool doAsync, CancellationToken cancellationToken)
        {
            var buf = pc.Encoding.GetBytes(pc.Command + "\r\n");

            if (doAsync)
            {
                await stream.WriteAsync(buf, 0, buf.Length, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                stream.Write(buf, 0, buf.Length, cancellationToken);
            }
        }
Example #2
0
        void ProcessCommand(Pop3Command pc)
        {
            string response, text;

            byte[] buf;

            buf = Encoding.UTF8.GetBytes(pc.Command + "\r\n");
            stream.Write(buf, 0, buf.Length);

            try {
                response = ReadLine(pc.CancellationToken).TrimEnd();
            } catch {
                pc.Status = Pop3CommandStatus.ProtocolError;
                Disconnect();
                throw;
            }

            pc.Status = GetCommandStatus(response, out text);
            switch (pc.Status)
            {
            case Pop3CommandStatus.ProtocolError:
                Disconnect();
                throw new Pop3ProtocolException(string.Format("Unexpected response from server: {0}", response));

            case Pop3CommandStatus.Continue:
            case Pop3CommandStatus.Ok:
                if (pc.Handler != null)
                {
                    try {
                        pc.Handler(this, pc, text);
                    } catch {
                        pc.Status = Pop3CommandStatus.ProtocolError;
                        Disconnect();
                        throw;
                    }
                }
                break;
            }
        }
Example #3
0
        void SendCommand(Pop3Command pc)
        {
            var buf = Encoding.UTF8.GetBytes(pc.Command + "\r\n");

            stream.Write(buf, 0, buf.Length);
        }