public class InterruptableInputStream extends java.io.InputStream implements InputStreamWrapper
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.
| Modifier and Type | Field and Description |
|---|---|
private java.io.InputStream |
inputStream |
private boolean |
interrupted |
private static org.apache.commons.logging.Log |
log |
| Constructor and Description |
|---|
InterruptableInputStream(java.io.InputStream inputStream) |
| Modifier and Type | Method and Description |
|---|---|
int |
available() |
void |
close() |
java.io.InputStream |
getWrappedInputStream() |
void |
interrupt() |
boolean |
markSupported() |
private void |
maybeInterruptInputStream() |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
private static final org.apache.commons.logging.Log log
private java.io.InputStream inputStream
private boolean interrupted
public InterruptableInputStream(java.io.InputStream inputStream)
private void maybeInterruptInputStream()
throws java.io.IOException
java.io.IOExceptionpublic int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int available()
throws java.io.IOException
available in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.InputStreamjava.io.IOExceptionpublic void reset()
throws java.io.IOException
reset in class java.io.InputStreamjava.io.IOExceptionpublic boolean markSupported()
markSupported in class java.io.InputStreampublic java.io.InputStream getWrappedInputStream()
getWrappedInputStream in interface InputStreamWrapperpublic void interrupt()