com.google.enterprise.adaptor.prebuilt
Class StreamingCommand

java.lang.Object
  extended by com.google.enterprise.adaptor.prebuilt.StreamingCommand

public class StreamingCommand
extends Object

Exec helper that allows easy handling of stdin, stdout, and stderr. Normally you have to worry about deadlock when dealing with those streams (as mentioned briefly in Process), so this class handles that for you. This class is very similar to Command, except it allows streaming stdin, stdout, and stderr, instead of buffering them.


Nested Class Summary
static interface StreamingCommand.InputSource
          Content source that generates content at the rate it can be consumed.
static interface StreamingCommand.OutputSink
          Content sink that consumes content as soon as it becomes available.
 
Method Summary
static int exec(String[] command, File workingDir, StreamingCommand.InputSource stdin, StreamingCommand.OutputSink stdout, StreamingCommand.OutputSink stderr)
          Create process command starting in the workingDir and providing stdin as input.
static int exec(String[] command, StreamingCommand.InputSource stdin, StreamingCommand.OutputSink stdout, StreamingCommand.OutputSink stderr)
          Same as exec(command, null, stdin, stdout, stderr).
static StreamingCommand.InputSource streamInputSource(InputStream in)
          InputStream to StreamingCommand.InputSource adaptor.
static StreamingCommand.OutputSink streamOutputSink(OutputStream out)
          OutputStream to StreamingCommand.OutputSink adaptor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

exec

public static int exec(String[] command,
                       StreamingCommand.InputSource stdin,
                       StreamingCommand.OutputSink stdout,
                       StreamingCommand.OutputSink stderr)
                throws IOException,
                       InterruptedException
Same as exec(command, null, stdin, stdout, stderr).

Throws:
IOException
InterruptedException
See Also:
exec(String[], File, InputSource, OutputSink, OutputSink)

exec

public static int exec(String[] command,
                       File workingDir,
                       StreamingCommand.InputSource stdin,
                       StreamingCommand.OutputSink stdout,
                       StreamingCommand.OutputSink stderr)
                throws IOException,
                       InterruptedException
Create process command starting in the workingDir and providing stdin as input. This method blocks until the process exits. Stdout and stderr must be consumed via the StreamingCommand.OutputSinks. If stdin, stdout, or stderr is null, then a bare implemention will be used.

Returns:
Process return code
Throws:
IOException - if creating process fails
InterruptedException

streamInputSource

public static StreamingCommand.InputSource streamInputSource(InputStream in)
InputStream to StreamingCommand.InputSource adaptor.


streamOutputSink

public static StreamingCommand.OutputSink streamOutputSink(OutputStream out)
OutputStream to StreamingCommand.OutputSink adaptor.