1 package expectj; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.io.OutputStream; 6 7 /*** 8 * Implementors of this interface can be spawned by {@link expectj.ExpectJ}. 9 * 10 * @author Johan Walles 11 */ 12 public interface Spawnable 13 { 14 /*** 15 * This method launches the {@link Spawn}. It starts the 16 * {@link StreamPiper}s that enable copying of process stream contents to 17 * standard streams. 18 * @throws IOException on trouble. 19 */ 20 public void start() throws IOException; 21 22 /*** 23 * Get a stream from which the {@link Spawn}'s stdout can be read. 24 * @return A stream that represents stdout of a spawned process. 25 * @see Process#getInputStream() 26 */ 27 public InputStream getStdout(); 28 29 /*** 30 * Get a stream through which the {@link Spawn}'s stdin can be written to. 31 * @return A stream that represents stdin of a spawned process. 32 * @see Process#getOutputStream() 33 */ 34 public OutputStream getStdin(); 35 36 /*** 37 * Get a stream from which the {@link Spawn}'s stderr can be read. 38 * @return A stream that represents stderr of a spawned process, or null if there is 39 * no stderr. 40 * @see Process#getErrorStream() 41 */ 42 public InputStream getStderr(); 43 44 /*** 45 * Find out whether the {@link Spawn} has finished. 46 * @return true if a spawned process has finished. 47 */ 48 public boolean isClosed(); 49 50 /*** 51 * If the {@link Spawn} has exited, its exit code is returned. 52 * @return The exit code of the finished spawn. 53 * @throws ExpectJException if the spawn is still running. 54 * @see #isClosed() 55 * @see System#exit(int) 56 */ 57 public int getExitValue() throws ExpectJException; 58 59 /*** 60 * Stops a running {@link Spawn}. After this method returns, 61 * {@link #isClosed()} must return true. 62 */ 63 public void stop(); 64 65 /*** 66 * Register a listener that will be called when this spawnable closes. 67 * 68 * @param closeListener The listener that will be notified when this 69 * spawnable closes. 70 */ 71 public void setCloseListener(CloseListener closeListener); 72 73 /*** 74 * Will be notified when a {@link Spawnable} closes. 75 * 76 * @see #setCloseListener 77 */ 78 public interface CloseListener { 79 /*** 80 * Will be called when a {@link Spawnable} closes. 81 */ 82 public void onClose(); 83 } 84 }