FileDocCategorySizeDatePackage
TelnetOutputStream.javaAPI DocApache Commons NET 1.4.1 API3945Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net.telnet

TelnetOutputStream

public final class TelnetOutputStream extends OutputStream

author
Daniel F. Savarese

Fields Summary
private TelnetClient
__client
private boolean
__convertCRtoCRLF
private boolean
__lastWasCR
Constructors Summary
TelnetOutputStream(TelnetClient client)


     
    
        __client = client;
    
Methods Summary
public voidclose()
Closes the stream.

        __client._closeOutputStream();
    
public voidflush()
Flushes the stream.

        __client._flushOutputStream();
    
public voidwrite(int ch)
Writes a byte to the stream.

param
ch The byte to write.
exception
IOException If an error occurs while writing to the underlying stream.


        synchronized (__client)
        {
            ch &= 0xff;

            if (__client._requestedWont(TelnetOption.BINARY))
            {
                if (__lastWasCR)
                {
                    if (__convertCRtoCRLF)
                    {
                        __client._sendByte('\n");
                        if (ch == '\n")
                        {
                            __lastWasCR = false;
                            return ;
                        }
                    }
                    else if (ch != '\n")
                        __client._sendByte('\0");
                }

                __lastWasCR = false;

                switch (ch)
                {
                case '\r":
                    __client._sendByte('\r");
                    __lastWasCR = true;
                    break;
                case TelnetCommand.IAC:
                    __client._sendByte(TelnetCommand.IAC);
                    __client._sendByte(TelnetCommand.IAC);
                    break;
                default:
                    __client._sendByte(ch);
                    break;
                }
            }
            else if (ch == TelnetCommand.IAC)
            {
                __client._sendByte(ch);
                __client._sendByte(TelnetCommand.IAC);
            }
            else
                __client._sendByte(ch);
        }
    
public voidwrite(byte[] buffer)
Writes a byte array to the stream.

param
buffer The byte array to write.
exception
IOException If an error occurs while writing to the underlying stream.

        write(buffer, 0, buffer.length);
    
public voidwrite(byte[] buffer, int offset, int length)
Writes a number of bytes from a byte array to the stream starting from a given offset.

param
buffer The byte array to write.
param
offset The offset into the array at which to start copying data.
param
length The number of bytes to write.
exception
IOException If an error occurs while writing to the underlying stream.

        synchronized (__client)
        {
            while (length-- > 0)
                write(buffer[offset++]);
        }