Class ClientServer.ClientServerThread.TelnetInputReader

java.lang.Object
  extended byClientServer.ClientServerThread.TelnetInputReader
Enclosing class:
ClientServer.ClientServerThread

public class ClientServer.ClientServerThread.TelnetInputReader
extends Object

This class handles the input gathering and processing functions as well as the required echoing.

In order to be able to hide the users password when they enter it to log in, the telnet client must be set up to not locally echo anything. This is done by ClientServer.negotiate(). Since the client is not echoing, we must do the echoing.

Currently, the class properly handles carriage returns and backspaces, and ignores line-feeds and arrow keys.

Telnet protocol specifies that a newline is defined as a CR LF sequence, regardless of platform. The class catches the first CR, ignores any subsequent line feeds and calls TelnetPrintWriter.println(), whose purpose is to output CR LF sequences alongside the responsibilities of PrintWriter.

Author:
Kevin Thompson [antiduh@csh.rit.edu]

Field Summary
static int A_BS
           
static int A_CR
           
static int A_DEL
           
static int A_ESC
           
static int A_LF
           
static int A_NAK
           
static int A_NUL
           
static int A_SP
           
private  BufferedInputStream in
           
private  PrintWriter out
           
static int T_IAC
           
 
Constructor Summary
ClientServer.ClientServerThread.TelnetInputReader(BufferedInputStream _in, PrintWriter _out)
          Constructs the TelnetInputReader.
 
Method Summary
 String intDump(String input)
          Takes the given string input and converts it to a decimal string in the form 100:100:90:80 so that unprinted characters will be 'visible'
 int read(boolean echo)
          Reads a single character from the input BufferedInputStream.
 String readLine(boolean echo)
          Reads a line of text using the read() method defined above.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

A_BS

public static final int A_BS
See Also:
Constant Field Values

A_LF

public static final int A_LF
See Also:
Constant Field Values

A_CR

public static final int A_CR
See Also:
Constant Field Values

A_NAK

public static final int A_NAK
See Also:
Constant Field Values

A_ESC

public static final int A_ESC
See Also:
Constant Field Values

A_SP

public static final int A_SP
See Also:
Constant Field Values

A_DEL

public static final int A_DEL
See Also:
Constant Field Values

A_NUL

public static final int A_NUL
See Also:
Constant Field Values

T_IAC

public static final int T_IAC
See Also:
Constant Field Values

in

private BufferedInputStream in

out

private PrintWriter out
Constructor Detail

ClientServer.ClientServerThread.TelnetInputReader

public ClientServer.ClientServerThread.TelnetInputReader(BufferedInputStream _in,
                                                         PrintWriter _out)
Constructs the TelnetInputReader. It just saves the arguments.

Parameters:
_in - The BufferedInputStream to read from.
_out - The printwriter to echo to
Method Detail

read

public int read(boolean echo)
         throws IOException
Reads a single character from the input BufferedInputStream.

Handles: CR, Backspace

Ignores: LF, Arrow keys

This discards all arrow keys and linefeeds. CR's are sent back to readLine(). CR's, LF's, arrows, and backspaces are not directly sent back to the client. Those are handled in readLine().

After each read(), the result must be checked. If its -1, the user disconnected and we need to throw the IOException to the rest of the program.

All single character writes need to be flushed through the buffer so that the chars appear immediately after the user types them.

Parameters:
echo - If true, 'normal' unhandled chars are sent back through the class's PrintWriter
Returns:
The integer of the character.
Throws:
IOException

readLine

public String readLine(boolean echo)
                throws IOException
Reads a line of text using the read() method defined above. Carriage returns, and linefeeds are not echoed back, instead println() is called. Backspaces delete text from the buffer, and are sent to the telnet client in the sequence 8,32,8 to whiteout the text in the previous position. If the client does not enter any text and instead just hits return, then a zero-length string "" is returned.

Parameters:
echo - Whether or not to echo unhandled characters.
Returns:
The line of text.
Throws:
IOException

intDump

public String intDump(String input)
Takes the given string input and converts it to a decimal string in the form 100:100:90:80 so that unprinted characters will be 'visible'

Parameters:
input - The input to convert to a a decimal string