|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.InputStream java.io.FilterInputStream org.eclipse.ecf.provider.filetransfer.util.TimeoutInputStream
public class TimeoutInputStream
Wraps an input stream that blocks indefinitely to simulate timeouts on read(), skip(), and close(). The resulting input stream is buffered and supports retrying operations that failed due to an InterruptedIOException. Supports resuming partially completed operations after an InterruptedIOException REGARDLESS of whether the underlying stream does unless the underlying stream itself generates InterruptedIOExceptions in which case it must also support resuming. Check the bytesTransferred field to determine how much of the operation completed; conversely, at what point to resume.
Field Summary |
---|
Fields inherited from class java.io.FilterInputStream |
---|
in |
Constructor Summary | |
---|---|
TimeoutInputStream(java.io.InputStream in,
int bufferSize,
long readTimeout,
long closeTimeout)
Creates a timeout wrapper for an input stream. |
|
TimeoutInputStream(java.io.InputStream in,
int bufferSize,
long readTimeout,
long closeTimeout,
boolean growWhenFull)
|
Method Summary | |
---|---|
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. |
Methods inherited from class java.io.FilterInputStream |
---|
mark, read, reset |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TimeoutInputStream(java.io.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(java.io.InputStream in, int bufferSize, long readTimeout, long closeTimeout, boolean growWhenFull)
Method Detail |
---|
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in class java.io.FilterInputStream
java.io.InterruptedIOException
- if the timeout expired
java.io.IOException
- if an i/o error occurspublic int available() throws java.io.IOException
available
in class java.io.FilterInputStream
java.io.IOException
- if an i/o error occurspublic int read() throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.InterruptedIOException
- if the timeout expired and no data was received,
bytesTransferred will be zero
java.io.IOException
- if an i/o error occurspublic int read(byte[] buffer, int off, int len) throws java.io.IOException
read
in class java.io.FilterInputStream
java.io.InterruptedIOException
- if the timeout expired and no data was received,
bytesTransferred will be zero
java.io.IOException
- if an i/o error occurspublic long skip(long count) throws java.io.IOException
skip
in class java.io.FilterInputStream
java.io.InterruptedIOException
- if the timeout expired before all of the bytes specified have
been skipped, bytesTransferred may be non-zero
java.io.IOException
- if an i/o error occurspublic boolean markSupported()
markSupported
in class java.io.FilterInputStream
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |