Class TimeoutInputStream
- java.lang.Object
- 
- java.io.InputStream
- 
- java.io.FilterInputStream
- 
- org.eclipse.ecf.provider.filetransfer.util.TimeoutInputStream
 
 
 
- 
- All Implemented Interfaces:
- Closeable,- AutoCloseable
 
 public class TimeoutInputStream extends FilterInputStream 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.- Since:
- 3.0
 
- 
- 
Field Summary- 
Fields inherited from class java.io.FilterInputStreamin
 
- 
 - 
Constructor SummaryConstructors Constructor 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)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Returns the number of unread bytes in the buffer.voidclose()Wraps the underlying stream's method.booleanmarkSupported()Mark is not supported by the wrapper even if the underlying stream does, returns false.intread()Reads a byte from the stream.intread(byte[] buffer, int off, int len)Reads multiple bytes from the stream.longskip(long count)Skips multiple bytes in the stream.- 
Methods inherited from class java.io.FilterInputStreammark, read, reset
 - 
Methods inherited from class java.io.InputStreamnullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
 
- 
 
- 
- 
- 
Constructor Detail- 
TimeoutInputStreampublic TimeoutInputStream(InputStream in, int bufferSize, long readTimeout, long closeTimeout) Creates a timeout wrapper for an input stream.- Parameters:
- in- the underlying input stream
- bufferSize- the buffer size in bytes; should be large enough to mitigate Thread synchronization and context switching overhead
- readTimeout- the number of milliseconds to block for a read() or skip() before throwing an InterruptedIOException; 0 blocks indefinitely
- closeTimeout- the number of milliseconds to block for a close() before throwing an InterruptedIOException; 0 blocks indefinitely, -1 closes the stream in the background
 
 - 
TimeoutInputStreampublic TimeoutInputStream(InputStream in, int bufferSize, long readTimeout, long closeTimeout, boolean growWhenFull) 
 
- 
 - 
Method Detail- 
closepublic void close() throws IOExceptionWraps the underlying stream's method. It may be important to wait for a stream to actually be closed because it holds an implicit lock on a system resoure (such as a file) while it is open. Closing a stream may take time if the underlying stream is still servicing a previous request.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- FilterInputStream
- Throws:
- InterruptedIOException- if the timeout expired
- IOException- if an i/o error occurs
 
 - 
availablepublic int available() throws IOExceptionReturns the number of unread bytes in the buffer.- Overrides:
- availablein class- FilterInputStream
- Throws:
- IOException- if an i/o error occurs
 
 - 
readpublic int read() throws IOExceptionReads a byte from the stream.- Overrides:
- readin class- FilterInputStream
- Throws:
- InterruptedIOException- if the timeout expired and no data was received, bytesTransferred will be zero
- IOException- if an i/o error occurs
 
 - 
readpublic int read(byte[] buffer, int off, int len) throws IOExceptionReads multiple bytes from the stream.- Overrides:
- readin class- FilterInputStream
- Throws:
- InterruptedIOException- if the timeout expired and no data was received, bytesTransferred will be zero
- IOException- if an i/o error occurs
 
 - 
skippublic long skip(long count) throws IOExceptionSkips multiple bytes in the stream.- Overrides:
- skipin class- FilterInputStream
- Throws:
- InterruptedIOException- if the timeout expired before all of the bytes specified have been skipped, bytesTransferred may be non-zero
- IOException- if an i/o error occurs
 
 - 
markSupportedpublic boolean markSupported() Mark is not supported by the wrapper even if the underlying stream does, returns false.- Overrides:
- markSupportedin class- FilterInputStream
 
 
- 
 
-