|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
org.gjt.lindfors.util.StreamReaderThread
Generalized reader thread for input streams. This thread can be extended
for implementation of input stream readers. It contains three methods
(cleanup
, handleIOException
and
handleInput
) which are left to be overridden by the
subclass to introduce thread specific behaviour.
Cleanup
should be overridden if there exists any resources
which need to be freed when the thread terminates.
HandleIOException
can be overridden to add thread specific
implementation to situations where the thread has been interrupted by an
I/O exception. Finally, handleInput
should be overridden to
process all the input this thread reads.
For more detailed documentation, refer to the Util Library Tutorial .
Field Summary | |
protected int |
timeToLive
Wait this many milliseconds for the thread to exit gracefully when stopReading has been called. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
StreamReaderThread()
Constructs a new daemon thread. |
|
StreamReaderThread(java.io.Reader input)
Constructs a new daemon thread with default buffer size. |
|
StreamReaderThread(java.io.Reader input,
boolean isDaemon)
Constructs a new thread with default buffer size. |
|
StreamReaderThread(java.io.Reader input,
int bufSize)
Constructs a new daemon thread with a given buffer size. |
Method Summary | |
void |
cleanup()
Override to perform necessary cleanup. |
int |
getBufferSize()
Returns the size of the buffer used by this thread. |
java.io.Reader |
getInputStream()
Returns the input stream of this thread. |
void |
handleInput(char[] c,
int len)
Override to handle the input data read form the stream. |
void |
handleIOException(java.io.IOException e)
Override to handle the IO Exceptions thrown by the read operation. |
void |
run()
The thread implementation. |
void |
setBufferSize(int bufferSize)
Sets the buffer size for this thread. |
void |
setExitOnError(boolean exitOnError)
Sets the thread behaviour for error handling. |
void |
setInputStream(java.io.Reader input)
Sets the input stream for this thread. |
void |
stopReading()
Stops the reader thread. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected int timeToLive
stopReading
has been called. If the thread is
unable to stop by this time, force it to interrupt.
Constructor Detail |
public StreamReaderThread(java.io.Reader input, int bufSize)
handleInput
method.
input
- the stream used for readingpublic StreamReaderThread(java.io.Reader input)
handleInput
method.
input
- the stream used for readingpublic StreamReaderThread(java.io.Reader input, boolean isDaemon)
input
- the stream used for readingisDaemon
- true for creating daemon thread, false for user
threadpublic StreamReaderThread()
Method Detail |
public void stopReading()
public void setExitOnError(boolean exitOnError)
handleIOException
method to ensure that any
errors received from the stream are corrected and the input stream is
ready to be used again.
exitOnError
- true to exit when errors occur, false to attempt
to continue readinghandleIOException
public void setBufferSize(int bufferSize)
bufferSize
- the size of the buffer in charspublic int getBufferSize()
public void setInputStream(java.io.Reader input)
input
- the stream used for readingpublic java.io.Reader getInputStream()
public void run()
HandleInput
is called to process all the data received from
the input stream. HandleIOException
is called if any errors
occur during the read operations. Cleanup
gets called after
the thread has finished reading the stream.
public void cleanup()
public void handleIOException(java.io.IOException e)
e
- the exception that was caughtpublic void handleInput(char[] c, int len)
c
- character array containing the data from the input streamlen
- length of the data read
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |