org.apache.hadoop.net
Class SocketInputWrapper
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
org.apache.hadoop.net.SocketInputWrapper
- All Implemented Interfaces:
- Closeable
public class SocketInputWrapper
- extends FilterInputStream
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.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
setTimeout
public void setTimeout(long timeoutMs)
throws SocketException
- 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 one
SocketInputWrapper
instance per socket.
- Parameters:
timeoutMs
- the new timeout, 0 for no timeout
- Throws:
SocketException
- if the timeout cannot be set
getReadableByteChannel
public ReadableByteChannel getReadableByteChannel()
- Returns:
- an underlying ReadableByteChannel implementation.
- Throws:
IllegalStateException
- if this socket does not have a channel
Copyright © 2009 The Apache Software Foundation