public class DefaultCommandProcess extends Object implements CommandProcess
CommandProcess
interface.
This implementation used instance of InputStream
to handle
read operation and instance of OutputStream
to handle write
operation. These streams may come from instance of Process
for instance.
Note: This implementation is not thread safe.Constructor and Description |
---|
DefaultCommandProcess(InputStream is,
OutputStream os,
InputStream err)
Create process.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush()
Flush pending write operations.
|
boolean |
isClosed()
Check if current process has been closed.
|
boolean |
isRunning()
Check if current process is still opened.
|
String |
read()
Read output until a null line is read.
|
String |
read(OutputHandler handler)
Read output until:
A null line is read.
Handler returns false when line is read.
Since command process will not be closed, a simple string
is returned (an exit status cannot be computed).
|
void |
write(Iterable<String> inputs)
Write set of inputs to the current process.
|
void |
write(String input,
String... others)
Write input string to the current process.
|
public DefaultCommandProcess(InputStream is, OutputStream os, InputStream err)
is
- Input stream.os
- Output stream.public String read() throws IOException
CommandProcess
read
in interface CommandProcess
IOException
- If an error occurred during operation.public String read(OutputHandler handler) throws IOException
CommandProcess
read
in interface CommandProcess
handler
- Output handler.IOException
- If an error occurred during operation.public void write(String input, String... others) throws IOException
CommandProcess
write
in interface CommandProcess
input
- Input.others
- Other inputs.IOException
- If an error occurred during operation.public void write(Iterable<String> inputs) throws IOException
CommandProcess
write
in interface CommandProcess
inputs
- Collection of inputs.IOException
- If an error occurred during operation.public void flush() throws IOException
CommandProcess
flush
in interface CommandProcess
IOException
public boolean isRunning()
CommandProcess
true
, then CommandProcess.isClosed()
should return false
.isRunning
in interface CommandProcess
true
if process is open, false
otherwise.public boolean isClosed()
CommandProcess
true
, then CommandProcess.isRunning()
should return false
.isClosed
in interface CommandProcess
true
if process is closed, false
otherwise.public void close() throws Exception
close
in interface AutoCloseable
Exception
Copyright © 2015. All Rights Reserved.