public class ProcessHandler extends Object
StreamGobbler instances to communicate with the out and err stream of the process.| Modifier and Type | Class and Description |
|---|---|
static interface |
ProcessHandler.ProcessListener
A listener which listens to the
ProcessHandler streams. |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_POLLING_RATE
The default polling rate.
|
| Constructor and Description |
|---|
ProcessHandler(Process process)
Constructor.
|
ProcessHandler(Process process,
boolean handleInputStream)
Constructor.The output and error streams of the proces will be handled.
|
ProcessHandler(ProcessBuilder builder)
Constructor.
|
ProcessHandler(ProcessBuilder builder,
boolean handleInputStream)
Constructor.The output and error streams of the proces will be handled.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the reading and writing of the streams.
|
void |
createProcessAndStart()
Creates the process if it does not already exist and start the handler.
|
Charset |
getCharset()
Return the charset used to communcate with the process.
|
ProcessHandler.ProcessListener |
getListener()
Return the process listener.
|
Process |
getProcess()
Return the process.
|
boolean |
isClosed()
Return true if the handler is closed.
|
boolean |
isHandlingInputStream()
Return true if the input stream of the process is started.
|
boolean |
isStarted()
Return true if the handler is started.
|
void |
setCharset(Charset charset)
Set the charset used to communcate with the process.
|
void |
setCharset(String charset)
Set the charset used to communcate with the process.
|
boolean |
setInputQueued(boolean isQueued)
Set if the input stream is queued.It will not do anything if the handler is already started.
|
boolean |
setInputQueued(boolean isQueued,
int delay)
Set if the input stream is queued.It will not do anything if the handler is already started.
|
boolean |
setInputQueued(boolean isQueued,
int delay,
int pollingRate)
Set if the input stream is queued.It will not do anything if the handler is already started.
|
void |
setListener(ProcessHandler.ProcessListener listener)
Set the process listener.
|
boolean |
setOutputQueued(boolean isQueued)
Set if the error and output streams are queued.
|
boolean |
setOutputQueued(boolean isQueued,
int delay)
Set if the error and output streams are queued.
|
boolean |
setOutputQueued(boolean isQueued,
int delay,
int pollingRate)
Set if the error and output streams are queued.It will not do anything if the handler is already started.
|
boolean |
start()
Start the handler.
|
boolean |
writeIn(String line,
boolean includeNewLine)
Write a line of text to the input stream.
|
public static final int DEFAULT_POLLING_RATE
public ProcessHandler(ProcessBuilder builder)
builder - the process builderpublic ProcessHandler(ProcessBuilder builder, boolean handleInputStream)
builder - the process builderhandleInputStream - true if the input stream will be handledpublic ProcessHandler(Process process)
process - the processpublic ProcessHandler(Process process, boolean handleInputStream)
process - the processhandleInputStream - true if the input stream will be handledpublic void setCharset(Charset charset)
charset - the charsetpublic void setCharset(String charset)
charset - the charsetpublic Charset getCharset()
public Process getProcess()
public void setListener(ProcessHandler.ProcessListener listener)
listener - the listenerpublic ProcessHandler.ProcessListener getListener()
public boolean setOutputQueued(boolean isQueued)
isQueued - true if the output streams are queuedpublic boolean setOutputQueued(boolean isQueued,
int delay)
isQueued - true if the output streams are queueddelay - the queueing delaypublic boolean setOutputQueued(boolean isQueued,
int delay,
int pollingRate)
isQueued - true if the output streams are queueddelay - the queueing delaypollingRate - the polling rate of the queuespublic boolean setInputQueued(boolean isQueued)
isQueued - true if the input stream is queuedpublic boolean setInputQueued(boolean isQueued,
int delay)
isQueued - true if the input stream is queueddelay - the queueing delaypublic boolean setInputQueued(boolean isQueued,
int delay,
int pollingRate)
isQueued - true if the input stream is queueddelay - the queueing delaypollingRate - the polling ratepublic void close()
public boolean isHandlingInputStream()
public boolean isStarted()
public boolean isClosed()
public void createProcessAndStart()
throws IOException
IOException - if an I/O error occurspublic boolean start()
public boolean writeIn(String line, boolean includeNewLine)
line - includeNewLine - true if a new lilne must be handledisHandlingInputStream() is true, and the handler is not
closed.