1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.net.telnet;
17
18 /**
19 * The TelnetCommand class cannot be instantiated and only serves as a
20 * storehouse for telnet command constants.
21 * @author Daniel F. Savarese
22 * @see org.apache.commons.net.telnet.Telnet
23 * @see org.apache.commons.net.telnet.TelnetClient
24 */
25
26 public final class TelnetCommand
27 {
28 /*** The maximum value a command code can have. This value is 255. ***/
29 public static final int MAX_COMMAND_VALUE = 255;
30
31 /*** Interpret As Command code. Value is 255 according to RFC 854. ***/
32 public static final int IAC = 255;
33
34 /*** Don't use option code. Value is 254 according to RFC 854. ***/
35 public static final int DONT = 254;
36
37 /*** Request to use option code. Value is 253 according to RFC 854. ***/
38 public static final int DO = 253;
39
40 /*** Refuse to use option code. Value is 252 according to RFC 854. ***/
41 public static final int WONT = 252;
42
43 /*** Agree to use option code. Value is 251 according to RFC 854. ***/
44 public static final int WILL = 251;
45
46 /*** Start subnegotiation code. Value is 250 according to RFC 854. ***/
47 public static final int SB = 250;
48
49 /*** Go Ahead code. Value is 249 according to RFC 854. ***/
50 public static final int GA = 249;
51
52 /*** Erase Line code. Value is 248 according to RFC 854. ***/
53 public static final int EL = 248;
54
55 /*** Erase Character code. Value is 247 according to RFC 854. ***/
56 public static final int EC = 247;
57
58 /*** Are You There code. Value is 246 according to RFC 854. ***/
59 public static final int AYT = 246;
60
61 /*** Abort Output code. Value is 245 according to RFC 854. ***/
62 public static final int AO = 245;
63
64 /*** Interrupt Process code. Value is 244 according to RFC 854. ***/
65 public static final int IP = 244;
66
67 /*** Break code. Value is 243 according to RFC 854. ***/
68 public static final int BREAK = 243;
69
70 /*** Data mark code. Value is 242 according to RFC 854. ***/
71 public static final int DM = 242;
72
73 /*** No Operation code. Value is 241 according to RFC 854. ***/
74 public static final int NOP = 241;
75
76 /*** End subnegotiation code. Value is 240 according to RFC 854. ***/
77 public static final int SE = 240;
78
79 /*** End of record code. Value is 239. ***/
80 public static final int EOR = 239;
81
82 /*** Abort code. Value is 238. ***/
83 public static final int ABORT = 238;
84
85 /*** Suspend process code. Value is 237. ***/
86 public static final int SUSP = 237;
87
88 /*** End of file code. Value is 236. ***/
89 public static final int EOF = 236;
90
91 /*** Synchronize code. Value is 242. ***/
92 public static final int SYNCH = 242;
93
94 /*** String representations of commands. ***/
95 private static final String __commandString[] = {
96 "IAC", "DONT", "DO", "WONT", "WILL", "SB", "GA", "EL", "EC", "AYT",
97 "AO", "IP", "BRK", "DMARK", "NOP", "SE", "EOR", "ABORT", "SUSP", "EOF"
98 };
99
100 private static final int __FIRST_COMMAND = IAC;
101 private static final int __LAST_COMMAND = EOF;
102
103 /***
104 * Returns the string representation of the telnet protocol command
105 * corresponding to the given command code.
106 * <p>
107 * @param code The command code of the telnet protocol command.
108 * @return The string representation of the telnet protocol command.
109 ***/
110 public static final String getCommand(int code)
111 {
112 return __commandString[__FIRST_COMMAND - code];
113 }
114
115 /***
116 * Determines if a given command code is valid. Returns true if valid,
117 * false if not.
118 * <p>
119 * @param code The command code to test.
120 * @return True if the command code is valid, false if not.
121 **/
122 public static final boolean isValidCommand(int code)
123 {
124 return (code <= __FIRST_COMMAND && code >= __LAST_COMMAND);
125 }
126
127
128 private TelnetCommand()
129 { }
130 }