public class StreamingCommand extends Object
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.Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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. |
public static int exec(String[] command, StreamingCommand.InputSource stdin, StreamingCommand.OutputSink stdout, StreamingCommand.OutputSink stderr) throws IOException, InterruptedException
exec(command, null, stdin, stdout, stderr)
.command
- commandstdin
- stdinstdout
- stdoutstderr
- stderrIOException
- if creating process failsInterruptedException
- if interruptedexec(String[], File, InputSource, OutputSink, OutputSink)
public static int exec(String[] command, File workingDir, StreamingCommand.InputSource stdin, StreamingCommand.OutputSink stdout, StreamingCommand.OutputSink stderr) throws IOException, InterruptedException
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.OutputSink
s. If
stdin
, stdout
, or stderr
is null
, then a
bare implemention will be used.command
- commandworkingDir
- workingDirstdin
- stdinstdout
- stdoutstderr
- stderrIOException
- if creating process failsInterruptedException
- if interruptedpublic static StreamingCommand.InputSource streamInputSource(InputStream in)
InputStream
to StreamingCommand.InputSource
adaptor.in
- input streampublic static StreamingCommand.OutputSink streamOutputSink(OutputStream out)
OutputStream
to StreamingCommand.OutputSink
adaptor.out
- output stream