private boolean sendEmulatorCommand ( //final Launcher launcher, //final PrintStream logger, final int port , final String command ) { Callable < Boolean > task = new Callable < Boolean > ( ) { public Boolean call ( ) throws IOException { Socket socket = null ; BufferedReader in = null ; PrintWriter out = null ; try { socket = new Socket ( "127.0.0.1" , port ) ; out = new PrintWriter ( socket . getOutputStream ( ) , true ) ; in = new BufferedReader ( new InputStreamReader ( socket . getInputStream ( ) ) ) ; if ( in . readLine ( ) == null ) { return false ; } out . write ( command ) ; out . write ( "\r\n" ) ; } finally { try { out . close ( ) ; in . close ( ) ; socket . close ( ) ; } catch ( Exception e ) { // Do nothing } } return true ; } private static final long serialVersionUID = 1L ; } ; boolean result = false ; try { ExecutorService executor = Executors . newSingleThreadExecutor ( ) ; Future < Boolean > future = executor . submit ( task ) ; result = future . get ( ) ; } catch ( Exception e ) { getLog ( ) . error ( String . format ( "Failed to execute emulator command '%s': %s" , command , e ) ) ; } return result ; }
Sends a user command to the running emulator via its telnet interface .