Package com.identity4j.util.expect
Class Expect
- java.lang.Object
-
- com.identity4j.util.expect.Expect
-
public class Expect extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected BufferedInputStreaminprotected List<ExpectMatcher>matchers
-
Constructor Summary
Constructors Constructor Description Expect()Expect(ExpectMatcher matcher)Expect(ExpectMatcher matcher, InputStream in, OutputStream out)Expect(ExpectMatcher matcher, InputStream in, OutputStream out, String eol)Expect(InputStream in, OutputStream out)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcarriageReturn()Send a carriage return to the remote shell.Stringchat(String pattern, boolean consumeRemainingLine, long timeout, long maxLines, boolean ignoreEmptyLines)Consume the output of the command until the pattern matches.booleanexpect(String pattern)Consume the output of the command until the pattern matches.booleanexpect(String pattern, boolean consumeRemainingLine)Consume the output of the command until the pattern matches.booleanexpect(String pattern, boolean consumeRemainingLine, long timeout)Consume the output of the command until the pattern matches.booleanexpect(String pattern, boolean consumeRemainingLine, long timeout, long maxLines)Consume the output of the command until the pattern matches.booleanexpect(String pattern, long timeout)Consume the output of the command until the pattern matches.booleanexpectNextLine(String pattern)Perform expect on the next line of output onlybooleanexpectNextLine(String pattern, boolean consumeRemainingLine)Perform expect on the next line of output onlybooleanexpectNextLine(String pattern, boolean consumeRemainingLine, long timeout)Perform expect on the next line of output onlyStringgetEol()InputStreamgetIn()OutputStreamgetOut()voidinterrupt()protected booleanisOpen()static voidmain(String[] args)protected booleanmatches(String line, String pattern)booleanmaybeExpect(String pattern)booleanmaybeExpect(String pattern, boolean consumeRemainingLine)booleanmaybeExpect(String pattern, boolean consumeRemainingLine, long timeout)booleanmaybeExpect(String pattern, boolean consumeRemainingLine, long timeout, long maxLines)booleanmaybeExpect(String pattern, long timeout)booleanmaybeExpectNextLine(String pattern)booleanmaybeExpectNextLine(String pattern, boolean consumeRemainingLine)booleanmaybeExpectNextLine(String pattern, boolean consumeRemainingLine, long timeout)protected intread(long timeout)StringreadLine()StringreadLine(long timeout)voidsetEol(String eol)voidsetIn(InputStream in)voidsetOut(OutputStream out)voidtype(int b)Write a byte of data as input on the remote shell.voidtype(String string)Type some characters as input on the remote shell.voidtypeAndReturn(String string)Type some characters followed by a carriage return on the remote shell.voidwrite(byte[] bytes)Write some data as input on the remote shell.
-
-
-
Field Detail
-
matchers
protected List<ExpectMatcher> matchers
-
in
protected BufferedInputStream in
-
-
Constructor Detail
-
Expect
public Expect()
-
Expect
public Expect(ExpectMatcher matcher)
-
Expect
public Expect(InputStream in, OutputStream out)
-
Expect
public Expect(ExpectMatcher matcher, InputStream in, OutputStream out)
-
Expect
public Expect(ExpectMatcher matcher, InputStream in, OutputStream out, String eol)
-
-
Method Detail
-
isOpen
protected boolean isOpen()
-
interrupt
public void interrupt() throws IOException- Throws:
IOException
-
type
public void type(String string) throws IOException
Type some characters as input on the remote shell.- Parameters:
string- String- Throws:
IOException
-
expect
public boolean expect(String pattern) throws ExpectTimeoutException, IOException
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:
ShellTimeoutExceptionSshExceptionExpectTimeoutExceptionIOException
-
expect
public boolean expect(String pattern, boolean consumeRemainingLine) throws ExpectTimeoutException, IOException
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:
ShellTimeoutExceptionSshExceptionExpectTimeoutExceptionIOException
-
expect
public boolean expect(String pattern, long timeout) throws ExpectTimeoutException, IOException
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:
ShellTimeoutExceptionSshExceptionExpectTimeoutExceptionIOException
-
expect
public boolean expect(String pattern, boolean consumeRemainingLine, long timeout) throws ExpectTimeoutException, IOException
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:
ShellTimeoutExceptionSshExceptionExpectTimeoutExceptionIOException
-
expectNextLine
public boolean expectNextLine(String pattern) throws ExpectTimeoutException, IOException
Perform expect on the next line of output only- Parameters:
pattern-- Returns:
- Throws:
ShellTimeoutExceptionSshExceptionExpectTimeoutExceptionIOException
-
expectNextLine
public boolean expectNextLine(String pattern, boolean consumeRemainingLine) throws ExpectTimeoutException, IOException
Perform expect on the next line of output only- Parameters:
pattern-consumeRemainingLine-- Returns:
- Throws:
ShellTimeoutExceptionSshExceptionExpectTimeoutExceptionIOException
-
expectNextLine
public boolean expectNextLine(String pattern, boolean consumeRemainingLine, long timeout) throws ExpectTimeoutException, IOException
Perform expect on the next line of output only- Parameters:
pattern-consumeRemainingLine-timeout-- Returns:
- Throws:
ExpectTimeoutExceptionSshExceptionIOException
-
expect
public boolean expect(String pattern, boolean consumeRemainingLine, long timeout, long maxLines) throws ExpectTimeoutException, IOException
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:
ExpectTimeoutExceptionIOException
-
maybeExpectNextLine
public boolean maybeExpectNextLine(String pattern, boolean consumeRemainingLine, long timeout) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpectNextLine
public boolean maybeExpectNextLine(String pattern, boolean consumeRemainingLine) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpectNextLine
public boolean maybeExpectNextLine(String pattern) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpect
public boolean maybeExpect(String pattern, boolean consumeRemainingLine, long timeout) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpect
public boolean maybeExpect(String pattern, long timeout) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpect
public boolean maybeExpect(String pattern, boolean consumeRemainingLine) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpect
public boolean maybeExpect(String pattern) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
maybeExpect
public boolean maybeExpect(String pattern, boolean consumeRemainingLine, long timeout, long maxLines) throws ExpectTimeoutException, IOException
- Throws:
ExpectTimeoutExceptionIOException
-
chat
public String chat(String pattern, boolean consumeRemainingLine, long timeout, long maxLines, boolean ignoreEmptyLines) throws ExpectTimeoutException, IOException
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-ignoreEmptyLines- blank lines are not counted- Returns:
- Throws:
ExpectTimeoutExceptionIOException
-
read
protected int read(long timeout) throws IOException, ExpectTimeoutException- Throws:
IOExceptionExpectTimeoutException
-
readLine
public String readLine() throws IOException, ExpectTimeoutException
- Throws:
IOExceptionExpectTimeoutException
-
readLine
public String readLine(long timeout) throws IOException, ExpectTimeoutException
- Throws:
IOExceptionExpectTimeoutException
-
main
public static void main(String[] args)
-
getIn
public final InputStream getIn()
-
setIn
public final void setIn(InputStream in)
-
getOut
public final OutputStream getOut()
-
setOut
public final void setOut(OutputStream out)
-
getEol
public final String getEol()
-
setEol
public final void setEol(String eol)
-
typeAndReturn
public void typeAndReturn(String string) throws IOException
Type some characters followed by a carriage return on the remote shell.- Parameters:
string- String- Throws:
IOException
-
write
public void write(byte[] bytes) throws IOExceptionWrite some data as input on the remote shell.- Parameters:
bytes-- Throws:
IOException
-
type
public void type(int b) throws IOExceptionWrite a byte of data as input on the remote shell.- Parameters:
b-- Throws:
IOException
-
carriageReturn
public void carriageReturn() throws IOExceptionSend a carriage return to the remote shell.- Throws:
IOException
-
-