Class SttySupport


  • public final class SttySupport
    extends java.lang.Object
    Support for stty command on unix
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private SttySupport()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int copyStream​(java.io.InputStream in, java.io.OutputStream bout)  
      static java.lang.String exec​(java.lang.String cmd)
      Execute the specified command and return the output (both stdout and stderr).
      private static java.lang.String exec​(java.lang.String... cmd)
      Execute the specified command and return the output (both stdout and stderr).
      private static int findChar​(java.lang.String stty, java.lang.String name)  
      private static int findFlag​(java.lang.String stty, java.lang.String name)  
      static java.lang.String getSttyCommand()  
      static int getTerminalHeight()
      Returns the value of "stty size" height param.
      static int getTerminalProperty​(java.lang.String prop)  
      static int getTerminalWidth()
      Returns the value of "stty size" width param.
      static java.lang.String getTtyProps()  
      static java.util.Map<PtyMode,​java.lang.Integer> getUnixPtyModes()  
      static java.util.Map<PtyMode,​java.lang.Integer> parsePtyModes​(java.lang.String stty)  
      static void setSttyCommand​(java.lang.String cmd)  
      static java.lang.String stty​(java.lang.String args)
      Execute the stty command with the specified arguments against the current active terminal.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_TERMINAL_HEIGHT

        public static final int DEFAULT_TERMINAL_HEIGHT
        See Also:
        Constant Field Values
      • SSHD_STTY_COMMAND_PROP

        public static final java.lang.String SSHD_STTY_COMMAND_PROP
        See Also:
        Constant Field Values
      • DEFAULT_SSHD_STTY_COMMAND

        public static final java.lang.String DEFAULT_SSHD_STTY_COMMAND
        See Also:
        Constant Field Values
      • STTY_COMMAND_HOLDER

        private static final java.util.concurrent.atomic.AtomicReference<java.lang.String> STTY_COMMAND_HOLDER
      • TTY_PROPS_HOLDER

        private static final java.util.concurrent.atomic.AtomicReference<java.lang.String> TTY_PROPS_HOLDER
      • TTY_PROPS_LAST_FETCHED_HOLDER

        private static final java.util.concurrent.atomic.AtomicLong TTY_PROPS_LAST_FETCHED_HOLDER
    • Constructor Detail

      • SttySupport

        private SttySupport()
    • Method Detail

      • getUnixPtyModes

        public static java.util.Map<PtyMode,​java.lang.Integer> getUnixPtyModes()
                                                                              throws java.io.IOException,
                                                                                     java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • parsePtyModes

        public static java.util.Map<PtyMode,​java.lang.Integer> parsePtyModes​(java.lang.String stty)
      • findFlag

        private static int findFlag​(java.lang.String stty,
                                    java.lang.String name)
      • findChar

        private static int findChar​(java.lang.String stty,
                                    java.lang.String name)
      • getTerminalWidth

        public static int getTerminalWidth()

        Returns the value of "stty size" width param.

        Note: this method caches the value from the first time it is called in order to increase speed, which means that changing to size of the terminal will not be reflected in the console.

        Returns:
        The terminal width
      • getTerminalHeight

        public static int getTerminalHeight()

        Returns the value of "stty size" height param.

        Note: this method caches the value from the first time it is called in order to increase speed, which means that changing to size of the terminal will not be reflected in the console.

        Returns:
        The terminal height
      • getTerminalProperty

        public static int getTerminalProperty​(java.lang.String prop)
                                       throws java.io.IOException,
                                              java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • getTtyProps

        public static java.lang.String getTtyProps()
                                            throws java.io.IOException,
                                                   java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • stty

        public static java.lang.String stty​(java.lang.String args)
                                     throws java.io.IOException,
                                            java.lang.InterruptedException
        Execute the stty command with the specified arguments against the current active terminal.
        Parameters:
        args - The command arguments
        Returns:
        The execution result
        Throws:
        java.io.IOException - If failed to execute the command
        java.lang.InterruptedException - If interrupted while awaiting command execution
        See Also:
        exec(String)
      • exec

        public static java.lang.String exec​(java.lang.String cmd)
                                     throws java.io.IOException,
                                            java.lang.InterruptedException
        Execute the specified command and return the output (both stdout and stderr).
        Parameters:
        cmd - The command to execute
        Returns:
        The execution result
        Throws:
        java.io.IOException - If failed to execute the command
        java.lang.InterruptedException - If interrupted while awaiting command execution
        See Also:
        exec(String[])
      • exec

        private static java.lang.String exec​(java.lang.String... cmd)
                                      throws java.io.IOException,
                                             java.lang.InterruptedException
        Execute the specified command and return the output (both stdout and stderr).
        Parameters:
        cmd - The command components
        Returns:
        The execution result
        Throws:
        java.io.IOException - If failed to execute the command
        java.lang.InterruptedException - If interrupted while awaiting command execution
      • copyStream

        private static int copyStream​(java.io.InputStream in,
                                      java.io.OutputStream bout)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getSttyCommand

        public static java.lang.String getSttyCommand()
        Returns:
        The command to use to set the terminal options.
        See Also:
        setSttyCommand(String)
      • setSttyCommand

        public static void setSttyCommand​(java.lang.String cmd)
        Parameters:
        cmd - The command to use to set the terminal options. Defaults to DEFAULT_SSHD_STTY_COMMAND, or the value of the SSHD_STTY_COMMAND_PROP system property if not set via this method