View Javadoc

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