InputReaderTask
@Deprecated public final class InputReaderTask extends Object implements Runnable, Cancellable
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 InputReaderTask.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();
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Deprecated.
Cancels the task.
|
static InputReaderTask |
newDrainingTask(InputReader reader,
InputProcessor processor)
Deprecated.
Creates the new task.
|
static InputReaderTask |
newTask(InputReader reader,
InputProcessor processor)
Deprecated.
Creates the new task.
|
void |
run()
Deprecated.
Task repeatedly reads the data from the InputReader, passing the content
to InputProcessor (if any).
|
@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.
public boolean cancel()
cancel
in interface Cancellable
true
if the task was successfully cancelled