org.jets3t.service.io
Class InterruptableInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.jets3t.service.io.InterruptableInputStream
All Implemented Interfaces:
Closeable, InputStreamWrapper

public class InterruptableInputStream
extends InputStream
implements InputStreamWrapper

Input stream wrapper that allows the underlying wrapped input stream to be interrupted. Every time a blocking stream operation is invoked on this class, the interrupt flag is checked first. If this flag is set, the underlying stream is closed and an IOException "Input Stream Interrupted" is thrown.

Note: This hacky class does not really solve the problem of interrupting blocking Java input streams, as it cannot unblock a blocked read operation. It really just serves as a convenient way to interrupt streams before any potentially blocking operations.

Author:
James Murty

Constructor Summary
InterruptableInputStream(InputStream inputStream)
           
 
Method Summary
 int available()
           
 void close()
           
 InputStream getWrappedInputStream()
           
 void interrupt()
           
 int read()
           
 int read(byte[] b, int off, int len)
           
 
Methods inherited from class java.io.InputStream
mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InterruptableInputStream

public InterruptableInputStream(InputStream inputStream)
Method Detail

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

getWrappedInputStream

public InputStream getWrappedInputStream()
Specified by:
getWrappedInputStream in interface InputStreamWrapper
Returns:
the underlying input stream wrapped by this class.

interrupt

public void interrupt()