public class ForwardingProcessListener extends Object implements ListeningProcessExecutor.ProcessListener
Constructor and Description |
---|
ForwardingProcessListener(OutputStream stdout,
OutputStream stderr) |
Modifier and Type | Method and Description |
---|---|
void |
onExit(int exitCode)
Called just after the process exits.
|
void |
onStart(ListeningProcessExecutor.LaunchedProcess process)
Called just after the process starts.
|
void |
onStderr(ByteBuffer buffer,
boolean closed)
Called when the process writes bytes to stderr.
|
boolean |
onStdinReady(ByteBuffer buffer)
Called when the process is ready to receive bytes on stdin.
|
void |
onStdout(ByteBuffer buffer,
boolean closed)
Called when the process writes bytes to stdout.
|
public ForwardingProcessListener(OutputStream stdout, OutputStream stderr)
public void onStart(ListeningProcessExecutor.LaunchedProcess process)
ListeningProcessExecutor.ProcessListener
onStart
in interface ListeningProcessExecutor.ProcessListener
public void onExit(int exitCode)
ListeningProcessExecutor.ProcessListener
onExit
in interface ListeningProcessExecutor.ProcessListener
public void onStdout(ByteBuffer buffer, boolean closed)
ListeningProcessExecutor.ProcessListener
Before this method returns, you must set buffer.position()
to indicate how many
bytes you have consumed.
If you do not consume the entire buffer, any remaining bytes will be passed back to you upon the next invocation (for example, when implementing a UTF-8 decoder which might contain a byte sequence spanning multiple reads).
If closed
is true
, then stdout has been closed and no more bytes will be
received.
onStdout
in interface ListeningProcessExecutor.ProcessListener
public void onStderr(ByteBuffer buffer, boolean closed)
ListeningProcessExecutor.ProcessListener
Before this method returns, you must set buffer.position()
to indicate how many
bytes you have consumed.
If you do not consume the entire buffer, any remaining bytes will be passed back to you upon the next invocation (for example, when implementing a UTF-8 decoder which might contain a byte sequence spanning multiple reads).
If closed
is true
, then stdout has been closed and no more bytes will be
received.
onStderr
in interface ListeningProcessExecutor.ProcessListener
public boolean onStdinReady(ByteBuffer buffer)
ListeningProcessExecutor.ProcessListener
Before this method returns, you must set the buffer
's position
and limit
(for example, by invoking Buffer.flip()
) to indicate how much data is in the buffer before returning from this
method.
You must first call ListeningProcessExecutor.LaunchedProcess.wantWrite()
at least once before this method
will be invoked.
If not all of the data needed to be written will fit in buffer
, you can return
true
to indicate that you would like to write more data.
Otherwise, return false
if you have no more data to write to stdin. (You can
always invoke ListeningProcessExecutor.LaunchedProcess.wantWrite()
any time in the future.
onStdinReady
in interface ListeningProcessExecutor.ProcessListener