<h2>org.das2.util.Expect</h2><p>Provides similar functions as the Unix Expect tool.<br> There are two ways to create an Expect object: a constructor that takes an {@link InputStream} handle and {@link OutputStream} handle; or spawning a process by providing a command String. <br> <br> The API is loosely based on Perl Expect library:<br> <a href="http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod"> http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod</a> <br> If you are not familiar with the Tcl version of Expect, take a look at:<br> <a href="http://oreilly.com/catalog/expect/chapter/ch03.html"> http://oreilly.com/catalog/expect/chapter/ch03.html</a> <br> <br> Expect uses a thread to convert InputStream to a SelectableChannel; other than this, no multi-threading is used.<br> A call to expect() will block for at most timeout seconds. Expect is not designed to be thread-safe, in other words, do not call methods of the same Expect object in different threads.</p> <h2>Expect( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/InputStream.html'>java.io.InputStream</a> input, <a href='https://docs.oracle.com/javase/8/docs/api/java/io/OutputStream.html'>java.io.OutputStream</a> output )</h2> <p></p> <hr> <a name="before"></a> <h2>before</h2> <p>String before the last match(if there was a match), updated after each expect() call</p> <hr> <a name="match"></a> <h2>match</h2> <p>String representing the last match(if there was a match), updated after each expect() call</p> <hr> <a name="isSuccess"></a> <h2>isSuccess</h2> <p>Whether the last match was successful, updated after each expect() call</p> <hr> <a name="RETV_TIMEOUT"></a> <h2>RETV_TIMEOUT</h2> <p></p> <hr> <a name="RETV_EOF"></a> <h2>RETV_EOF</h2> <p></p> <hr> <a name="RETV_IOEXCEPTION"></a> <h2>RETV_IOEXCEPTION</h2> <p></p> <hr> <a name="byteToPrintableString"></a> <h2>byteToPrintableString</h2> byteToPrintableString( byte b ) → <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> <p></p> <h3>Parameters</h3> b - a byte <h3>Returns:</h3> java.lang.String <br><br> <a href="https://github.com/autoplot/dev/search?q=byteToPrintableString&unscoped_q=byteToPrintableString">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#byteToPrintableString">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="bytesToPrintableString"></a> <h2>bytesToPrintableString</h2> bytesToPrintableString( byte[] bytes ) → <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> <p>Static method used for convert byte array to string, each byte is converted to an ASCII character, if the byte represents a control character, it is replaced by a printable caret notation <a href="http://en.wikipedia.org/wiki/ASCII"> http://en.wikipedia.org/wiki/ASCII </a>, or an escape code if possible.</p> <h3>Parameters</h3> bytes - bytes to be printed <h3>Returns:</h3> String representation of the byte array <br><br> <a href="https://github.com/autoplot/dev/search?q=bytesToPrintableString&unscoped_q=bytesToPrintableString">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#bytesToPrintableString">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="close"></a> <h2>close</h2> close( ) → void <p>The OutputStream passed to Expect constructor is closed; the InputStream is not closed (there is no need to close the InputStream).<br> It is suggested that this method be called after the InputStream has come to EOF. For example, when you connect through SSH, send an "exit" command first, and then call this method.<br> <br> When this method is called, the thread which write to the sink of the pipe will end.</p> <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=close&unscoped_q=close">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#close">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="expect"></a> <h2>expect</h2> expect( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html'>Object[]</a> patterns ) → int <p>Convenience method, same as calling {@link #expect(int, Object...) expect(default_timeout, patterns)}</p> <h3>Parameters</h3> patterns - a java.lang.Object[] <h3>Returns:</h3> an int <br><br> <a href="https://github.com/autoplot/dev/search?q=expect&unscoped_q=expect">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#expect">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> expect( int timeout, <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html'>Object[]</a> patterns ) → int<br> expect( int timeout, <a href='https://docs.oracle.com/javase/8/docs/api/java/util/List.html'>java.util.List</a> list ) → int<br> <hr> <a name="expectEOF"></a> <h2>expectEOF</h2> expectEOF( int timeout ) → int <p>Convenience method, internally it calls {@link #expect(int, List) expect(timeout, new ArrayList<Pattern>())}. Given an empty list, {@link #expect(int, List)} will not perform any regex matching, therefore the only conditions for it to return is EOF or timeout (or IOException). If EOF is detected, {@link #isSuccess} and {@link #before} are properly set.</p> <h3>Parameters</h3> timeout - an int <h3>Returns:</h3> same as return value of {@link #expect(int, List)} <br><br> <a href="https://github.com/autoplot/dev/search?q=expectEOF&unscoped_q=expectEOF">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#expectEOF">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> expectEOF( ) → int<br> <hr> <a name="expectEOFOrThrow"></a> <h2>expectEOFOrThrow</h2> expectEOFOrThrow( int timeout ) → int <p>Throws checked exceptions when expectEOF was not successful.</p> <h3>Parameters</h3> timeout - timeout in seconds <h3>Returns:</h3> same as return value of {@link #expect(int, List)} <br><br> <a href="https://github.com/autoplot/dev/search?q=expectEOFOrThrow&unscoped_q=expectEOFOrThrow">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#expectEOFOrThrow">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> expectEOFOrThrow( ) → int<br> <hr> <a name="expectOrThrow"></a> <h2>expectOrThrow</h2> expectOrThrow( int timeout, <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html'>Object[]</a> patterns ) → int <p>This method calls {@link #expect(int, Object...) expect(timeout, patterns)}, and throws checked exceptions when expect was not successful. Useful when you want to simplify error handling: for example, when you send a series of commands to an SSH server, you expect a prompt after each send, however the server may die or the prompt may take forever to appear, you would want to skip the following commands if those occurred. In such a case this method will be handy.</p> <h3>Parameters</h3> timeout - an int <br> patterns - a java.lang.Object[] <h3>Returns:</h3> same as {@link #expect(int, Object...) expect(timeout, patterns)} <br><br> <a href="https://github.com/autoplot/dev/search?q=expectOrThrow&unscoped_q=expectOrThrow">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#expectOrThrow">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> expectOrThrow( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html'>Object[]</a> patterns ) → int<br> <hr> <a name="forwardInputStreamTo"></a> <h2>forwardInputStreamTo</h2> forwardInputStreamTo( <a href='https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html'>java.io.PrintStream</a> duplicatedTo ) → void <p>While performing expect operations on the InputStream provided, duplicate the contents obtained from InputStream to a PrintStream (you can use System.err or System.out). <b>DO NOT</b> call this function while there are live Expect objects as this may cause the piping thread to end due to unsynchronized code; if you need this feature, add the following to both {@link #inputStreamToSelectableChannel(InputStream)} and {@link #forwardInputStreamTo(PrintStream)}: <pre> synchronized(Expect.duplicatedTo) {... } </pre></p> <h3>Parameters</h3> duplicatedTo - call with null if you want to turn off <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=forwardInputStreamTo&unscoped_q=forwardInputStreamTo">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#forwardInputStreamTo">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="getDefault_timeout"></a> <h2>getDefault_timeout</h2> getDefault_timeout( ) → int <p></p> <h3>Returns:</h3> int <br><br> <a href="https://github.com/autoplot/dev/search?q=getDefault_timeout&unscoped_q=getDefault_timeout">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#getDefault_timeout">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="getProcess"></a> <h2>getProcess</h2> getProcess( ) → <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html'>java.lang.Process</a> <p></p> <h3>Returns:</h3> the spawned process, if this {@link Expect} object is created by spawning a process <br><br> <a href="https://github.com/autoplot/dev/search?q=getProcess&unscoped_q=getProcess">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#getProcess">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="isNotransfer"></a> <h2>isNotransfer</h2> isNotransfer( ) → boolean <p></p> <h3>Returns:</h3> boolean <br><br> <a href="https://github.com/autoplot/dev/search?q=isNotransfer&unscoped_q=isNotransfer">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#isNotransfer">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="isRestart_timeout_upon_receive"></a> <h2>isRestart_timeout_upon_receive</h2> isRestart_timeout_upon_receive( ) → boolean <p></p> <h3>Returns:</h3> boolean <br><br> <a href="https://github.com/autoplot/dev/search?q=isRestart_timeout_upon_receive&unscoped_q=isRestart_timeout_upon_receive">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#isRestart_timeout_upon_receive">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="printDebugInfo"></a> <h2>printDebugInfo</h2> printDebugInfo( ) → void <p>print internal debug information to stderr.</p> <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=printDebugInfo&unscoped_q=printDebugInfo">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#printDebugInfo">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="send"></a> <h2>send</h2> send( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> str ) → void <p></p> <h3>Parameters</h3> str - Convenience method to send a string to output handle <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=send&unscoped_q=send">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#send">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> send( byte[] toWrite ) → void<br> <hr> <a name="setDefault_timeout"></a> <h2>setDefault_timeout</h2> setDefault_timeout( int default_timeout ) → void <p></p> <h3>Parameters</h3> default_timeout - an int <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=setDefault_timeout&unscoped_q=setDefault_timeout">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#setDefault_timeout">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="setNotransfer"></a> <h2>setNotransfer</h2> setNotransfer( boolean notransfer ) → void <p></p> <h3>Parameters</h3> notransfer - a boolean <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=setNotransfer&unscoped_q=setNotransfer">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#setNotransfer">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="setRestart_timeout_upon_receive"></a> <h2>setRestart_timeout_upon_receive</h2> setRestart_timeout_upon_receive( boolean restart_timeout_upon_receive ) → void <p></p> <h3>Parameters</h3> restart_timeout_upon_receive - a boolean <h3>Returns:</h3> void (returns nothing) <br><br> <a href="https://github.com/autoplot/dev/search?q=setRestart_timeout_upon_receive&unscoped_q=setRestart_timeout_upon_receive">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#setRestart_timeout_upon_receive">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br> <hr> <a name="spawn"></a> <h2>spawn</h2> spawn( <a href='https://docs.oracle.com/javase/8/docs/api/java/lang/String.html'>String</a> command ) → <a href='http://www-pw.physics.uiowa.edu/~jbf/autoplot/doc/org/das2/util/Expect.html'>org.das2.util.Expect</a> <p>Creates an Expect object by spawning a command.<br> To Linux users, perhaps you need to use "bash -i" if you want to spawn Bash.<br> Note: error stream of the process is redirected to output stream.</p> <h3>Parameters</h3> command - a String <h3>Returns:</h3> Expect object created using the input and output handles from the spawned process <br><br> <a href="https://github.com/autoplot/dev/search?q=spawn&unscoped_q=spawn">[search for examples]</a> <a href="https://github.com/autoplot/documentation/tree/master/javadoc/org/das2/util/Expect.md">[view on GitHub]</a> <a href="http://www-pw.physics.uiowa.edu/~jbf/autoplot/javadoc2018/org/das2/util/Expect.html#spawn">[view on old javadoc]</a> <a href="https://saturn.physics.uiowa.edu/svn/das2/dasCore/community/autoplot2011/trunk/dasCoreUtil/src/org/das2/util/Expect.java">[view source]</a> <br> <br>