|
org.netbeans.modules.extexecution/2 1.21.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.netbeans.api.extexecution.input.InputReaderTask
public final class InputReaderTask
Task consuming data from the certain reader, processing them with the given processor.
When exception occurs while running the task it is terminated. Task is responsive to interruption. InputReader is closed on finish (includes both cases throwing an exception and interruption).
The run() method can be executed just once.
Task is not finished implicitly by reaching the end of the reader.
The caller has to finish it either by interruption or explicit cancellation.
Cancellation is preferred in situations where the interruption could make
cleanup operations on InputProcessor impossible to happen.
Sample usage - reading standard output of the process (throwing the data away):
java.lang.Process process = ...
java.util.concurrent.ExecutorService executorService = ...
Runnable runnable = InputReaderTask.newTask(
InputReaders.forStream(process.getInputStream(), Charset.defaultCharset()));
executorService.submit(runnable);
...
executorService.shutdownNow();
Sample usage - forwarding data to standard input of the process:
java.lang.Process process = ...
java.util.concurrent.ExecutorService executorService = ...
Runnable runnable = InputReaderTask.newTask(
InputReaders.forStream(System.in, Charset.defaultCharset()),
InputProcessors.copying(new OutputStreamWriter(process.getOutputStream())));
executorService.submit(runnable);
...
executorService.shutdownNow();
| Method Summary | |
|---|---|
boolean |
cancel()
Cancels the task. |
static InputReaderTask |
newDrainingTask(InputReader reader,
InputProcessor processor)
Creates the new task. |
static InputReaderTask |
newTask(InputReader reader,
InputProcessor processor)
Creates the new task. |
void |
run()
Task repeatedly reads the data from the InputReader, passing the content to InputProcessor (if any). |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
@NonNull
public static InputReaderTask newTask(@NonNull
InputReader reader,
@NullAllowed
InputProcessor processor)
InputReader must be non blocking.
reader - data producerprocessor - processor consuming the data, may be null
@NonNull
public static InputReaderTask newDrainingTask(@NonNull
InputReader reader,
@NullAllowed
InputProcessor processor)
InputReader must be non blocking.
reader - data producerprocessor - processor consuming the data, may be null
public void run()
It is not allowed to invoke run multiple times.
run in interface Runnablepublic boolean cancel()
cancel in interface Cancellabletrue if the task was successfully cancelled
|
org.netbeans.modules.extexecution/2 1.21.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||