Class SessionOutputReader
- java.lang.Object
-
- com.sshtools.j2ssh.session.SessionOutputReader
-
public class SessionOutputReader extends java.lang.Object
This class provides a utility to read and parse the output a session, providing methods to wait for specific strings such as the prompt or command input requests.
- Since:
- 0.2.1
- Version:
- $Revision: 1.13 $
- Author:
- Lee David Painter
-
-
Constructor Summary
Constructors Constructor Description SessionOutputReader(SessionChannelClient session)
Contructs the session reader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
echoLineByLineToClose(SessionOutputEcho echo)
java.lang.String
getMarkedOutput()
Returns a string containing the session output from the current marked position to the end of the output.java.lang.String
getOutput()
Returns the output of the entire session.int
getPosition()
Returns the current position of the session input pointer.void
markCurrentPosition()
Marks the current position.void
markPosition(int mark)
Mark the postion specified for filtering session output.boolean
waitForString(java.lang.String str)
Wait for a given String in the output buffer.boolean
waitForString(java.lang.String str, int timeout)
Wait for a given String in the output buffer.boolean
waitForString(java.lang.String str, int timeout, SessionOutputEcho echo)
Wait for a given String in the output buffer.boolean
waitForString(java.lang.String str, SessionOutputEcho echo)
Wait for a given String in the output buffer.
-
-
-
Constructor Detail
-
SessionOutputReader
public SessionOutputReader(SessionChannelClient session)
Contructs the session reader.
- Parameters:
session
- the to read
-
-
Method Detail
-
getOutput
public java.lang.String getOutput()
Returns the output of the entire session.- Returns:
- a string containing the entire output of the session so far.
-
getPosition
public int getPosition()
Returns the current position of the session input pointer. This pointer is set to the position of the matched string everytime a match is found during a call by
waitForString
- Returns:
- the current input reader pointer
-
markPosition
public void markPosition(int mark)
Mark the postion specified for filtering session output.- Parameters:
mark
- output position to mark
-
markCurrentPosition
public void markCurrentPosition()
Marks the current position.
-
getMarkedOutput
public java.lang.String getMarkedOutput()
Returns a string containing the session output from the current marked position to the end of the output.
- Returns:
- a string containing the session output from the marked position to current position
-
waitForString
public boolean waitForString(java.lang.String str, SessionOutputEcho echo) throws java.lang.InterruptedException
Wait for a given String in the output buffer.
- Parameters:
str
- the string to wait forecho
- a callback interface to receive the session output whilst the no match for the string is found- Returns:
- true if the string was found, otherwise false
- Throws:
java.lang.InterruptedException
- if the thread is interrupted- See Also:
waitForString(java.lang.String,int,com.sshtools.j2ssh.session.SessionOutputEcho)
-
waitForString
public boolean waitForString(java.lang.String str) throws java.lang.InterruptedException
Wait for a given String in the output buffer. This method will block until the string is found.
- Parameters:
str
- the string to wait for- Returns:
- true if the string was found, otherwise false
- Throws:
java.lang.InterruptedException
- if the thread is interrupted- See Also:
waitForString(java.lang.String,int,com.sshtools.j2ssh.session.SessionOutputEcho)
-
waitForString
public boolean waitForString(java.lang.String str, int timeout) throws java.lang.InterruptedException
Wait for a given String in the output buffer.
- Parameters:
str
- the string to wait fortimeout
- the number of milliseconds to wait- Returns:
- true if the string was found, otherwise false
- Throws:
java.lang.InterruptedException
- if the thread is interrupted- See Also:
waitForString(java.lang.String,int,com.sshtools.j2ssh.session.SessionOutputEcho)
-
waitForString
public boolean waitForString(java.lang.String str, int timeout, SessionOutputEcho echo) throws java.lang.InterruptedException
Wait for a given String in the output buffer. When this method is called the method will block unitil either the String arrives in the input buffer or the timeout specified has elasped.
- Parameters:
str
- the string to wait fortimeout
- the number of milliseconds to wait, 0=infiniteecho
- a callback interface to receive the session output whilst the no match for the string is found- Returns:
- true if the string was found, otherwise false
- Throws:
java.lang.InterruptedException
- if the thread is interrupted
-
echoLineByLineToClose
public void echoLineByLineToClose(SessionOutputEcho echo) throws java.lang.InterruptedException
- Parameters:
echo
-- Throws:
java.lang.InterruptedException
-
-