Package org.apache.hadoop.net
Class SocketInputWrapper
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.hadoop.net.SocketInputWrapper
- All Implemented Interfaces:
Closeable,AutoCloseable
A wrapper stream around a socket which allows setting of its timeout. If the
socket has a channel, this uses non-blocking IO via the package-private
SocketInputStream implementation. Otherwise, timeouts are managed by
setting the underlying socket timeout itself.-
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Method Summary
Modifier and TypeMethodDescriptionvoidsetTimeout(long timeoutMs) Set the timeout for reads from this stream.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, read, reset, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Method Details
-
setTimeout
Set the timeout for reads from this stream. Note: the behavior here can differ subtly depending on whether the underlying socket has an associated Channel. In particular, if there is no channel, then this call will affect the socket timeout for all readers of this socket. If there is a channel, then this call will affect the timeout only for this stream. As such, it is recommended to only create oneSocketInputWrapperinstance per socket.- Parameters:
timeoutMs- the new timeout, 0 for no timeout- Throws:
SocketException- if the timeout cannot be set
-
getReadableByteChannel
- Returns:
- an underlying ReadableByteChannel implementation.
- Throws:
IllegalStateException- if this socket does not have a channel
-