1 16 package org.apache.commons.net.telnet; 17 18 import java.io.BufferedInputStream ; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import org.apache.commons.net.io.FromNetASCIIInputStream; 23 import org.apache.commons.net.io.ToNetASCIIOutputStream; 24 25 47 48 public class TelnetClient extends Telnet 49 { 50 private InputStream __input; 51 private OutputStream __output; 52 protected boolean readerThread = true; 53 54 57 public TelnetClient() 58 { 59 60 super ("VT100"); 61 62 __input = null; 63 __output = null; 64 } 65 66 67 public TelnetClient(String termtype) 68 { 69 super (termtype); 70 __input = null; 71 __output = null; 72 } 73 74 75 void _flushOutputStream() throws IOException 76 { 77 _output_.flush(); 78 } 79 void _closeOutputStream() throws IOException 80 { 81 _output_.close(); 82 } 83 84 89 protected void _connectAction_() throws IOException 90 { 91 super._connectAction_(); 92 InputStream input; 93 TelnetInputStream tmp; 94 95 if (FromNetASCIIInputStream.isConversionRequired()) 96 input = new FromNetASCIIInputStream(_input_); 97 else 98 input = _input_; 99 100 101 tmp = new TelnetInputStream(input, this, readerThread); 102 if(readerThread) 103 { 104 tmp._start(); 105 } 106 __input = new BufferedInputStream (tmp); 113 __output = new ToNetASCIIOutputStream(new TelnetOutputStream(this)); 114 } 115 116 123 public void disconnect() throws IOException 124 { 125 __input.close(); 126 __output.close(); 127 super.disconnect(); 128 } 129 130 137 public OutputStream getOutputStream() 138 { 139 return __output; 140 } 141 142 149 public InputStream getInputStream() 150 { 151 return __input; 152 } 153 154 161 public boolean getLocalOptionState(int option) 162 { 163 164 return (_stateIsWill(option) && _requestedWill(option)); 165 166 } 167 168 175 public boolean getRemoteOptionState(int option) 176 { 177 178 return (_stateIsDo(option) && _requestedDo(option)); 179 180 } 181 182 183 184 185 196 public boolean sendAYT(long timeout) 197 throws IOException , IllegalArgumentException , InterruptedException 198 { 199 return (_sendAYT(timeout)); 200 } 201 202 203 204 205 212 public void addOptionHandler(TelnetOptionHandler opthand) 213 throws InvalidTelnetOptionException 214 { 215 super.addOptionHandler(opthand); 216 } 217 218 219 226 public void deleteOptionHandler(int optcode) 227 throws InvalidTelnetOptionException 228 { 229 super.deleteOptionHandler(optcode); 230 } 231 232 233 240 public void registerSpyStream(OutputStream spystream) 241 { 242 super._registerSpyStream(spystream); 243 } 244 245 249 public void stopSpyStream() 250 { 251 super._stopSpyStream(); 252 } 253 254 255 261 public void registerNotifHandler(TelnetNotificationHandler notifhand) 262 { 263 super.registerNotifHandler(notifhand); 264 } 265 266 270 public void unregisterNotifHandler() 271 { 272 super.unregisterNotifHandler(); 273 } 274 275 281 public void setReaderThread(boolean flag) 282 { 283 readerThread = flag; 284 } 285 286 291 public boolean getReaderThread() 292 { 293 return (readerThread); 294 } 295 } 296 | Popular Tags |