Gridarta Editor
net.sf.gridarta.utils.CopyReader Class Reference

Copies a Reader into a String. More...

+ Collaboration diagram for net.sf.gridarta.utils.CopyReader:

Public Member Functions

 CopyReader (@NotNull final Reader reader)
 Creates a new instance. More...
 
String getFailure ()
 Returns the failure reason. More...
 
String getOutput ()
 Returns the reader's output. More...
 
void join () throws InterruptedException
 Waits for the worker thread to terminate. More...
 
void start ()
 Starts reading. More...
 
void stop ()
 Stops reading. More...
 

Private Member Functions

void setFailure (@NotNull final String failure)
 Sets the failure reason. More...
 

Private Attributes

final CharArrayWriter charArrayWriter = new CharArrayWriter()
 The CharArrayWriter collecting data read from reader. More...
 
String failure
 The failure reason. More...
 
final Reader reader
 The Reader to read from. More...
 
final Runnable runnable
 The Runnable implementing the worker thread. More...
 
boolean stopped
 Whether the worker thread was stopped. More...
 
final Object sync = new Object()
 The synchronization object for accessing stopped, failure, and charArrayWriter. More...
 
final Thread thread = new Thread(runnable)
 The worker Thread executing runnable. More...
 

Detailed Description

Copies a Reader into a String.

Author
Andreas Kirschbaum

Definition at line 32 of file CopyReader.java.

Constructor & Destructor Documentation

◆ CopyReader()

net.sf.gridarta.utils.CopyReader.CopyReader ( @NotNull final Reader  reader)

Creates a new instance.

Parameters
readerthe reader to read from

Definition at line 103 of file CopyReader.java.

References net.sf.gridarta.utils.CopyReader.reader.

Member Function Documentation

◆ getFailure()

String net.sf.gridarta.utils.CopyReader.getFailure ( )

◆ getOutput()

◆ join()

void net.sf.gridarta.utils.CopyReader.join ( ) throws InterruptedException

Waits for the worker thread to terminate.

Exceptions
InterruptedExceptionif the current thread was interrupted waiting for the worker thread to terminate

Definition at line 167 of file CopyReader.java.

References net.sf.gridarta.utils.CopyReader.thread.

◆ setFailure()

void net.sf.gridarta.utils.CopyReader.setFailure ( @NotNull final String  failure)
private

Sets the failure reason.

Does nothing if a preceding failure reason was recorded.

Parameters
failurethe failure reason

Definition at line 127 of file CopyReader.java.

References net.sf.gridarta.utils.CopyReader.failure, and net.sf.gridarta.utils.CopyReader.sync.

◆ start()

void net.sf.gridarta.utils.CopyReader.start ( )

◆ stop()

void net.sf.gridarta.utils.CopyReader.stop ( )

Member Data Documentation

◆ charArrayWriter

final CharArrayWriter net.sf.gridarta.utils.CopyReader.charArrayWriter = new CharArrayWriter()
private

The CharArrayWriter collecting data read from reader.

Definition at line 51 of file CopyReader.java.

Referenced by net.sf.gridarta.utils.CopyReader.getOutput().

◆ failure

String net.sf.gridarta.utils.CopyReader.failure
private

The failure reason.

Set to

null

if no failure occurred.

Definition at line 62 of file CopyReader.java.

Referenced by net.sf.gridarta.utils.CopyReader.getFailure(), and net.sf.gridarta.utils.CopyReader.setFailure().

◆ reader

final Reader net.sf.gridarta.utils.CopyReader.reader
private

The Reader to read from.

Definition at line 38 of file CopyReader.java.

Referenced by net.sf.gridarta.utils.CopyReader.CopyReader().

◆ runnable

final Runnable net.sf.gridarta.utils.CopyReader.runnable
private
Initial value:
= new Runnable() {
@Override
public void run() {
final char[] buf = new char[1024];
while (!Thread.currentThread().isInterrupted()) {
try {
final int len = reader.read(buf);
if (len == -1) {
break;
}
synchronized (sync) {
if (stopped) {
break;
}
charArrayWriter.write(buf, 0, len);
}
} catch (final IOException ex) {
setFailure(ex.getMessage());
}
}
}
}

The Runnable implementing the worker thread.

Definition at line 68 of file CopyReader.java.

◆ stopped

boolean net.sf.gridarta.utils.CopyReader.stopped
private

Whether the worker thread was stopped.

Definition at line 56 of file CopyReader.java.

Referenced by net.sf.gridarta.utils.CopyReader.getFailure(), and net.sf.gridarta.utils.CopyReader.getOutput().

◆ sync

final Object net.sf.gridarta.utils.CopyReader.sync = new Object()
private

◆ thread

final Thread net.sf.gridarta.utils.CopyReader.thread = new Thread(runnable)
private

The documentation for this class was generated from the following file: