@VisibleForTesting
    protected void setSttyMode(STTYMode mode) throws IOException {
        String[] cmd;
        if (mode == STTYMode.COOKED) {
            cmd = new String[]{"/bin/sh", "-c", "stty -raw echo </dev/tty"};
        } else {
            cmd = new String[]{"/bin/sh", "-c", "stty raw -echo </dev/tty"};
        }

        Process p = runtime.exec(cmd);

        try {
            p.waitFor();
        } catch (InterruptedException ie) {
            throw new IOException(ie.getMessage(), ie);
        }

        try (InputStreamReader in = new InputStreamReader(p.getErrorStream(), UTF_8);
             BufferedReader reader = new BufferedReader(in)) {
            String err = reader.readLine();
            if (err != null) {
                throw new IOException(err);
            }
        }
    }
@ VisibleForTesting protected void setSttyMode ( STTYMode mode ) throws IOException { String [ ] cmd ; if ( mode == STTYMode . COOKED ) { cmd = new String [ ] { "/bin/sh" , "-c" , "stty -raw echo </dev/tty" } ; } else { cmd = new String [ ] { "/bin/sh" , "-c" , "stty raw -echo </dev/tty" } ; } Process p = runtime . exec ( cmd ) ; try { p . waitFor ( ) ; } catch ( InterruptedException ie ) { throw new IOException ( ie . getMessage ( ) , ie ) ; } try ( InputStreamReader in = new InputStreamReader ( p . getErrorStream ( ) , UTF_8 ) ; BufferedReader reader = new BufferedReader ( in ) ) { String err = reader . readLine ( ) ; if ( err != null ) { throw new IOException ( err ) ; } } }
Set terminal mode.

@param mode The mode to set.
@throws IOException If setting mode failed.