static Shell createTelnetConsoleShell ( String prompt , String appName , ShellCommandHandler mainHandler , InputStream input , OutputStream output ) { try { // Set up nvt4j; ignore the initial clear & reposition final nvt4j . impl . Terminal nvt4jTerminal = new nvt4j . impl . Terminal ( input , output ) { private boolean cleared ; private boolean moved ; @ Override public void clear ( ) throws IOException { if ( this . cleared ) super . clear ( ) ; this . cleared = true ; } @ Override public void move ( int row , int col ) throws IOException { if ( this . moved ) super . move ( row , col ) ; this . moved = true ; } } ; nvt4jTerminal . put ( nvt4j . impl . Terminal . AUTO_WRAP_ON ) ; nvt4jTerminal . setCursor ( true ) ; // Have JLine do input & output through telnet terminal final InputStream jlineInput = new InputStream ( ) { @ Override public int read ( ) throws IOException { return nvt4jTerminal . get ( ) ; } } ; final OutputStream jlineOutput = new OutputStream ( ) { @ Override public void write ( int value ) throws IOException { nvt4jTerminal . put ( value ) ; } } ; return createTerminalConsoleShell ( prompt , appName , mainHandler , jlineInput , jlineOutput ) ; } catch ( Exception e ) { // Failover: use default shell BufferedReader in = new BufferedReader ( new InputStreamReader ( input ) ) ; PrintStream out = new PrintStream ( output ) ; return createConsoleShell ( prompt , appName , mainHandler , in , out , out , null ) ; } }
Facade method for operating the Telnet Shell supporting line editing and command history over a socket .