Class ExpectJ


  • public class ExpectJ
    extends java.lang.Object
    This class is the starting point of the ExpectJ Utility. This class acts as factory for all Spawns.
    • Constructor Summary

      Constructors 
      Constructor Description
      ExpectJ()
      Create a new ExpectJ with an infinite timeout.
      ExpectJ​(long defaultTimeoutSeconds)
      Create a new ExpectJ with specified timeout setting.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Spawn spawn​(com.jcraft.jsch.Channel channel)
      This method creates a spawn that controls an SSH connection.
      Spawn spawn​(Executor executor)
      This method spawns a new process.
      Spawn spawn​(Spawnable spawnable)
      This method launches a Spawnable.
      Spawn spawn​(java.lang.String command)
      This method spawns a new process.
      Spawn spawn​(java.lang.String hostName, int port)
      This method spawns a telnet connection to the given host and port number.
      Spawn spawn​(java.lang.String remoteHostName, int remotePort, java.lang.String userName, java.lang.String password, java.lang.String preferredLibrary)
      This method creates a spawn that controls an SSH connection.
      • Methods inherited from class java.lang.Object

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

      • ExpectJ

        public ExpectJ​(long defaultTimeoutSeconds)
        Create a new ExpectJ with specified timeout setting.
        Parameters:
        defaultTimeoutSeconds - default time out in seconds for the expect commands on the spawned process. -1 default time out indicates indefinite timeout.
      • ExpectJ

        public ExpectJ()
        Create a new ExpectJ with an infinite timeout.
    • Method Detail

      • spawn

        public Spawn spawn​(Spawnable spawnable)
                    throws java.io.IOException
        This method launches a Spawnable. Further expect commands can be invoked on the returned Spawn object.
        Parameters:
        spawnable - spawnable to be executed
        Returns:
        The newly spawned process
        Throws:
        java.io.IOException - if the spawning fails
      • spawn

        public Spawn spawn​(java.lang.String command)
                    throws java.io.IOException
        This method spawns a new process. Further expect commands can be invoked on the returned Spawn object.
        Parameters:
        command - command to be executed
        Returns:
        The newly spawned process
        Throws:
        java.io.IOException - if the process spawning fails
        See Also:
        Runtime.exec(String)
      • spawn

        public Spawn spawn​(Executor executor)
                    throws java.io.IOException
        This method spawns a new process. Further expect commands can be invoked on the returned Spawn object.
        Parameters:
        executor - Will be called upon to start the new process
        Returns:
        The newly spawned process
        Throws:
        java.io.IOException - if the process spawning fails
        See Also:
        Runtime.exec(String[])
      • spawn

        public Spawn spawn​(java.lang.String hostName,
                           int port)
                    throws java.io.IOException
        This method spawns a telnet connection to the given host and port number. Further expect commands can be invoked on the returned Spawn object.
        Parameters:
        hostName - The name of the host to connect to.
        port - The remote port to connect to.
        Returns:
        The newly spawned telnet session.
        Throws:
        java.io.IOException - if the telnet spawning fails
        java.net.UnknownHostException - if you specify a bogus host name
        See Also:
        TelnetSpawn, #spawn(String, int, String, String), spawn(Channel)
      • spawn

        public Spawn spawn​(com.jcraft.jsch.Channel channel)
                    throws java.io.IOException
        This method creates a spawn that controls an SSH connection.
        Parameters:
        channel - The SSH channel to control.
        Returns:
        A spawn controlling the SSH channel.
        Throws:
        java.io.IOException - If taking control over the SSH channel fails.
        See Also:
        #spawn(String, int, String, String), SshSpawn(Channel)
      • spawn

        public Spawn spawn​(java.lang.String remoteHostName,
                           int remotePort,
                           java.lang.String userName,
                           java.lang.String password,
                           java.lang.String preferredLibrary)
                    throws java.io.IOException,
                           java.lang.IllegalArgumentException
        This method creates a spawn that controls an SSH connection.
        Parameters:
        remoteHostName - The remote host to connect to.
        remotePort - The remote port to connect to.
        userName - The user name with which to authenticate
        password - The password with which to authenticate
        Returns:
        A spawn controlling the SSH channel.
        Throws:
        java.io.IOException - If taking control over the SSH channel fails.
        java.lang.IllegalArgumentException - If the userName is null.
        See Also:
        spawn(Channel), SshSpawn(String, int, String, String)