|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
com.mindbright.util.ExpectOutputStream
This class implements an ouput stream which captures data until a
certain expected string has been encountered. To use it the caller
should first have a class which implements
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
Nested Class Summary | |
static interface |
ExpectOutputStream.Expector
Interface to be implemented by classes interested when the event ExpectOutputStream waits for happens. |
Constructor Summary | |
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. |
Method Summary | |
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 |
Methods inherited from class java.io.OutputStream |
flush, write |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
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 arrayMethod Detail |
public 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
public void write(byte[] b, int off, int len)
java.io.OutputStream
public void close()
java.io.OutputStream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |