|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--uk.ac.starlink.util.ReaderThread
Thread which reads data from a pipe.
The doReading(java.io.InputStream)
method of this abstract class should be implemented
to do something with the bytes in an input stream.
Here is an example of using the class to count the bytes written down a stream:
PipedOutputStream dataOut = new PipedOutputStream(); ReaderThread reader = new ReaderThread( dataOut ) { public void doReading( InputStream dataIn ) throws IOException { int i; while ( dataIn.read() >= 0 ) i++; System.out.println( i ); } }; reader.start(); // ... write bytes down dataOut ... dataOut.close(); reader.finishReading();Other uses will look pretty similar, but just override doReading in different ways. Note that any exceptions thrown by doReading are caught and eventually thrown in the caller thread by finishReading.
Field Summary |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
ReaderThread(PipedOutputStream dataOut)
Constructs a new reader thread. |
Method Summary | |
protected abstract void |
doReading(InputStream dataIn)
This method should be implemented to consume all the bytes in the given input stream. |
void |
finishReading()
Waits until the doReading method has finished reading the bytes written down the output stream, and returns. |
void |
run()
Implements the thread's run method to invoke doReading, catching and saving IOExceptions. |
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 |
Constructor Detail |
public ReaderThread(PipedOutputStream dataOut) throws IOException
dataOut
- stream down which bytes will be writtenMethod Detail |
public void run()
run
in interface Runnable
run
in class Thread
protected abstract void doReading(InputStream dataIn) throws IOException
dataIn
- stream which will supply bytes
IOException
- if any I/O error occurs; this exception will
be saved and thrown later by the finishReading methodpublic void finishReading() throws IOException
IOException
|
Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |