FileDocCategorySizeDatePackage
InterruptibleReader.javaAPI DocExample1417Sun Dec 07 10:44:00 GMT 2003javathreads.examples.ch12

InterruptibleReader

public abstract class InterruptibleReader extends Thread

Fields Summary
private Object
lock
private InputStream
is
private boolean
done
private int
buflen
Constructors Summary
public InterruptibleReader(InputStream is)

        this(is, 512);
    
public InterruptibleReader(InputStream is, int len)

        this.is = is;
        buflen = len;
    
Methods Summary
protected voidprocessData(byte[] b, int n)


           
public voidrun()

        ReaderClass rc = new ReaderClass();
        synchronized(lock) {
            rc.start();
            while (!done) {
                try {
                    lock.wait();
                } catch (InterruptedException ie) {
                    done = true;
		    rc.interrupt();
                    try {
                        is.close();
                    } catch (IOException ioe) {}
                }
            }
        }