public class TimeoutInputStream extends FilterInputStream
in
Constructor and Description |
---|
TimeoutInputStream(InputStream in,
int bufferSize,
long readTimeout,
long closeTimeout)
Creates a timeout wrapper for an input stream.
|
TimeoutInputStream(InputStream in,
int bufferSize,
long readTimeout,
long closeTimeout,
boolean growWhenFull) |
Modifier and Type | Method and Description |
---|---|
int |
available()
Returns the number of unread bytes in the buffer.
|
void |
close()
Wraps the underlying stream's method.
|
boolean |
markSupported()
Mark is not supported by the wrapper even if the underlying stream does,
returns false.
|
int |
read()
Reads a byte from the stream.
|
int |
read(byte[] buffer,
int off,
int len)
Reads multiple bytes from the stream.
|
long |
skip(long count)
Skips multiple bytes in the stream.
|
mark, read, reset
public TimeoutInputStream(InputStream in, int bufferSize, long readTimeout, long closeTimeout)
in
- the underlying input streambufferSize
- the buffer size in bytes; should be large enough to mitigate
Thread synchronization and context switching overheadreadTimeout
- the number of milliseconds to block for a read() or skip()
before throwing an InterruptedIOException; 0 blocks
indefinitelycloseTimeout
- the number of milliseconds to block for a close() before
throwing an InterruptedIOException; 0 blocks indefinitely, -1
closes the stream in the backgroundpublic TimeoutInputStream(InputStream in, int bufferSize, long readTimeout, long closeTimeout, boolean growWhenFull)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterInputStream
InterruptedIOException
- if the timeout expiredIOException
- if an i/o error occurspublic int available() throws IOException
available
in class FilterInputStream
IOException
- if an i/o error occurspublic int read() throws IOException
read
in class FilterInputStream
InterruptedIOException
- if the timeout expired and no data was received,
bytesTransferred will be zeroIOException
- if an i/o error occurspublic int read(byte[] buffer, int off, int len) throws IOException
read
in class FilterInputStream
InterruptedIOException
- if the timeout expired and no data was received,
bytesTransferred will be zeroIOException
- if an i/o error occurspublic long skip(long count) throws IOException
skip
in class FilterInputStream
InterruptedIOException
- if the timeout expired before all of the bytes specified have
been skipped, bytesTransferred may be non-zeroIOException
- if an i/o error occurspublic boolean markSupported()
markSupported
in class FilterInputStream
Copyright © 2017 Eclipse Foundation. All rights reserved.