Class SocketInputStream

java.lang.Object
java.io.InputStream
org.apache.hadoop.net.SocketInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel

@LimitedPrivate("HDFS") public class SocketInputStream extends InputStream implements ReadableByteChannel
This implements an input stream that can have a timeout while reading. This sets non-blocking flag on the socket channel. So after create this object, read() on Socket.getInputStream() and write() on Socket.getOutputStream() for the associated socket will throw IllegalBlockingModeException. Please use SocketOutputStream for writing.
  • Constructor Details

    • SocketInputStream

      public SocketInputStream(ReadableByteChannel channel, long timeout) throws IOException
      Create a new input stream with the given timeout. If the timeout is zero, it will be treated as infinite timeout. The socket's channel will be configured to be non-blocking.
      Parameters:
      channel - Channel for reading, should also be a SelectableChannel. The channel will be configured to be non-blocking.
      timeout - timeout in milliseconds. must not be negative.
      Throws:
      IOException - raised on errors performing I/O.
    • SocketInputStream

      public SocketInputStream(Socket socket, long timeout) throws IOException
      Same as SocketInputStream(socket.getChannel(), timeout):

      Create a new input stream with the given timeout. If the timeout is zero, it will be treated as infinite timeout. The socket's channel will be configured to be non-blocking.
      Parameters:
      socket - should have a channel associated with it.
      timeout - timeout timeout in milliseconds. must not be negative.
      Throws:
      IOException - raised on errors performing I/O.
      See Also:
    • SocketInputStream

      public SocketInputStream(Socket socket) throws IOException
      Same as SocketInputStream(socket.getChannel(), socket.getSoTimeout()) :

      Create a new input stream with the given timeout. If the timeout is zero, it will be treated as infinite timeout. The socket's channel will be configured to be non-blocking.
      Parameters:
      socket - should have a channel associated with it.
      Throws:
      IOException - raised on errors performing I/O.
      See Also:
  • Method Details