20 package net.sf.gridarta.utils;
22 import java.io.CharArrayWriter;
23 import java.io.IOException;
24 import java.io.Reader;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
45 private final Object
sync =
new Object();
68 private final Runnable
runnable =
new Runnable() {
72 final char[] buf =
new char[1024];
73 while (!Thread.currentThread().isInterrupted()) {
75 final int len = reader.read(buf);
83 charArrayWriter.write(buf, 0, len);
85 }
catch (
final IOException ex) {
97 private final Thread
thread =
new Thread(runnable);
126 @SuppressWarnings(
"NullableProblems")
128 synchronized (
sync) {
130 if (this.failure == null) {
142 synchronized (
sync) {
155 synchronized (
sync) {
167 public void join() throws InterruptedException {
boolean stopped
Whether the worker thread was stopped.
String failure
The failure reason.
final Object sync
The synchronization object for accessing stopped, failure, and charArrayWriter.
final CharArrayWriter charArrayWriter
The CharArrayWriter collecting data read from reader.
void start()
Starts reading.
Copies a Reader into a String.
final Runnable runnable
The Runnable implementing the worker thread.
final Thread thread
The worker Thread executing runnable.
String getOutput()
Returns the reader's output.
final Reader reader
The Reader to read from.
void stop()
Stops reading.
void setFailure(@NotNull final String failure)
Sets the failure reason.
String getFailure()
Returns the failure reason.
void join()
Waits for the worker thread to terminate.
CopyReader(@NotNull final Reader reader)
Creates a new instance.