com.mindbright.util
public final class ExpectOutputStream extends java.io.OutputStream
Expector
. For example:
class MyClass implements ExpectOutputStream.Expector { public void reached(ExpectOutputStream out, byte[] buf, int len) { System.out.println("Before this we got " + len + " bytes"); } public void closed(ExpectOutputStream out, byte[] buf, int len) { System.out.println("Stream closed"); }MyClass can then create an instance of
ExpectOutputStream
which waits for the desired string,
which in this example is END_OF_OUTPUT
:
outputStream = new ExpectOutputStream(this, "END_OF_OUTPUT"); // Attach to remote console SSH2ConsoleRemote console = ... console.changeStdOut(outputStream);And that is it. The
reached
function will be called
when the string END_OF_OUTPUT
is output from the
console. The buffer passed will contain all text up until that
point.
For a full usage example see the RemoteShellScript
example.
SSH2ConsoleRemote
,
RemoteShellScript
Modifier and Type | Class and Description |
---|---|
static interface |
ExpectOutputStream.Expector
Interface to be implemented by classes interested when the
event
ExpectOutputStream waits for happens. |
Constructor and Description |
---|
ExpectOutputStream(ExpectOutputStream.Expector expector)
Creates an expecting output stream which does not expect
anything.
|
ExpectOutputStream(ExpectOutputStream.Expector expector,
byte[] buf,
int off,
int len)
Creates an expecting output stream which waits for a specified string.
|
ExpectOutputStream(ExpectOutputStream.Expector expector,
java.lang.String boundary)
Creates an expecting output stream which waits for a specified string.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
See
java.io.OutputStream |
void |
expect(byte[] boundary)
Changes the string this instance is waiting for.
|
void |
expect(java.lang.String boundary)
Changes the string this instance is waiting for.
|
void |
write(byte[] b,
int off,
int len)
See
java.io.OutputStream |
void |
write(int b)
See
java.io.OutputStream |
public ExpectOutputStream(ExpectOutputStream.Expector expector)
expector
- class interested in when the expected string
occurspublic ExpectOutputStream(ExpectOutputStream.Expector expector, java.lang.String boundary)
expector
- class interested in when the expected string
occursboundary
- the string to wait forpublic ExpectOutputStream(ExpectOutputStream.Expector expector, byte[] buf, int off, int len)
expector
- class interested in when the expected string
occursbuf
- array holding the string it should wait foroff
- offset in array where the string startslen
- length of string in arraypublic void expect(java.lang.String boundary)
boundary
- the string to wait forpublic void expect(byte[] boundary)
boundary
- the string to wait forpublic void write(int b)
java.io.OutputStream
write
in class java.io.OutputStream
public void write(byte[] b, int off, int len)
java.io.OutputStream
write
in class java.io.OutputStream
public void close()
java.io.OutputStream
close
in interface java.io.Closeable
close
in class java.io.OutputStream