Class ShellController

java.lang.Object
com.sshtools.client.shell.ShellController
All Implemented Interfaces:
ShellReader, ShellWriter
Direct Known Subclasses:
ShellProcessController

public class ShellController extends Object implements ShellReader, ShellWriter
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected InputStream
     
    protected ShellMatcher
     
    protected int
     
    protected ExpectShell
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Send a carriage return to the remote command.
    boolean
    expect(String pattern)
    Consume the output of the command until the pattern matches.
    boolean
    expect(String pattern, boolean consumeRemainingLine)
    Consume the output of the command until the pattern matches.
    boolean
    expect(String pattern, boolean consumeRemainingLine, long timeout)
    Consume the output of the command until the pattern matches.
    boolean
    expect(String pattern, boolean consumeRemainingLine, long timeout, long maxLines)
    Consume the output of the command until the pattern matches.
    boolean
    expect(String pattern, long timeout)
    Consume the output of the command until the pattern matches.
    boolean
    Perform expect on the next line of output only
    boolean
    expectNextLine(String pattern, boolean consumeRemainingLine)
    Perform expect on the next line of output only
    boolean
    expectNextLine(String pattern, boolean consumeRemainingLine, long timeout)
    Perform expect on the next line of output only
    int
     
    void
    Interrupt the process by sending a Ctrl+C to the process.
    boolean
     
    boolean
     
    Read a line of output from the process.
    readLine(long timeout)
    Read a line of output from the process.
    void
     
    void
    setReadlimit(int readlimit)
     
    void
    type(String string)
    Send data to the remote command just like the user had typed it.
    void
    Send data to the remote command and finish with a carriage return.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • setMatcher

      public void setMatcher(ShellMatcher matcher)
    • interrupt

      public void interrupt() throws IOException
      Description copied from interface: ShellWriter
      Interrupt the process by sending a Ctrl+C to the process.
      Specified by:
      interrupt in interface ShellWriter
      Throws:
      IOException
    • type

      public void type(String string) throws IOException
      Description copied from interface: ShellWriter
      Send data to the remote command just like the user had typed it.
      Specified by:
      type in interface ShellWriter
      Parameters:
      string - the typed key data
      Throws:
      IOException
    • carriageReturn

      public void carriageReturn() throws IOException
      Description copied from interface: ShellWriter
      Send a carriage return to the remote command.
      Specified by:
      carriageReturn in interface ShellWriter
      Throws:
      IOException
    • typeAndReturn

      public void typeAndReturn(String string) throws IOException
      Description copied from interface: ShellWriter
      Send data to the remote command and finish with a carriage return.
      Specified by:
      typeAndReturn in interface ShellWriter
      Parameters:
      string - String
      Throws:
      IOException
    • expect

      public boolean expect(String pattern) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Consume the output of the command until the pattern matches. This version of expect will return with the output at the end of the matched pattern.
      Parameters:
      pattern -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expect

      public boolean expect(String pattern, boolean consumeRemainingLine) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Consume the output of the command until the pattern matches. Use the consumeRemainingLine variable to indicate if output should start at the end of the matched pattern (consumeRemainingLine=false) or at the begninng of the next line (consumeRemainingLine=true)
      Parameters:
      pattern -
      consumeRemainingLine -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expect

      public boolean expect(String pattern, long timeout) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Consume the output of the command until the pattern matches. Use the consumeRemainingLine variable to indicate if output should start at the end of the matched pattern (consumeRemainingLine=false) or at the begninng of the next line (consumeRemainingLine=true)
      Parameters:
      pattern -
      timeout -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expect

      public boolean expect(String pattern, boolean consumeRemainingLine, long timeout) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Consume the output of the command until the pattern matches. This version of expect will not consume the whole line and will return with the output at the end of the matched pattern.
      Parameters:
      pattern -
      consumeRemainingLine -
      timeout -
      maxLines -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expectNextLine

      public boolean expectNextLine(String pattern) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Perform expect on the next line of output only
      Parameters:
      pattern -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expectNextLine

      public boolean expectNextLine(String pattern, boolean consumeRemainingLine) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Perform expect on the next line of output only
      Parameters:
      pattern -
      consumeRemainingLine -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expectNextLine

      public boolean expectNextLine(String pattern, boolean consumeRemainingLine, long timeout) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Perform expect on the next line of output only
      Parameters:
      pattern -
      consumeRemainingLine -
      timeout -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • expect

      public boolean expect(String pattern, boolean consumeRemainingLine, long timeout, long maxLines) throws ShellTimeoutException, com.sshtools.common.ssh.SshException
      Consume the output of the command until the pattern matches. This version of expect will not consume the whole line and will return with the output at the end of the matched pattern.
      Parameters:
      pattern -
      consumeRemainingLine -
      timeout -
      maxLines -
      Returns:
      Throws:
      ShellTimeoutException
      com.sshtools.common.ssh.SshException
    • isEOF

      public boolean isEOF()
    • isActive

      public boolean isActive()
    • readLine

      public String readLine() throws com.sshtools.common.ssh.SshException, ShellTimeoutException
      Description copied from interface: ShellReader
      Read a line of output from the process.
      Specified by:
      readLine in interface ShellReader
      Returns:
      Throws:
      com.sshtools.common.ssh.SshException
      ShellTimeoutException
    • readLine

      public String readLine(long timeout) throws com.sshtools.common.ssh.SshException, ShellTimeoutException
      Description copied from interface: ShellReader
      Read a line of output from the process.
      Specified by:
      readLine in interface ShellReader
      Returns:
      Throws:
      com.sshtools.common.ssh.SshException
      ShellTimeoutException
    • getReadlimit

      public int getReadlimit()
    • setReadlimit

      public void setReadlimit(int readlimit)