Gridarta Editor
net.sf.gridarta.utils.CopyReader Class Reference
+ Collaboration diagram for net.sf.gridarta.utils.CopyReader:

Public Member Functions

 CopyReader (@NotNull final Reader reader)
 
String getFailure ()
 
String getOutput ()
 
void join () throws InterruptedException
 
void start ()
 
void stop ()
 

Private Member Functions

void setFailure (@NotNull final String failure)
 

Private Attributes

final CharArrayWriter charArrayWriter = new CharArrayWriter()
 
String failure
 
final Reader reader
 
final Runnable runnable
 
boolean stopped
 
final Object sync = new Object()
 
final Thread thread = new Thread(runnable)
 

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 166 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 126 of file CopyReader.java.

References net.sf.gridarta.utils.CopyReader.failure, net.sf.gridarta.utils.CopyReader.stopped, 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

◆ sync

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

◆ thread


The documentation for this class was generated from the following file:
net.sf.gridarta.utils.CopyReader.stopped
boolean stopped
Definition: CopyReader.java:56
net.sf.gridarta.utils.CopyReader.reader
final Reader reader
Definition: CopyReader.java:38
net.sf.gridarta.utils.CopyReader.sync
final Object sync
Definition: CopyReader.java:45
net.sf.gridarta.utils.CopyReader.charArrayWriter
final CharArrayWriter charArrayWriter
Definition: CopyReader.java:51
net.sf.gridarta.utils.CopyReader.setFailure
void setFailure(@NotNull final String failure)
Definition: CopyReader.java:126