SocketInputWrapper (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.net, class: SocketInputWrapper

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`

@LimitedPrivate("HDFS") @Unstable 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.

- ## Field Summary

  ### Fields inherited from class java.io.FilterInputStream

  `in`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ReadableByteChannel`
  `getReadableByteChannel()`
  `void`
  `setTimeout(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, skip`

  ### Methods inherited from class java.io.InputStream

  `nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### 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