java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel@LimitedPrivate("HDFS")
public class SocketInputStream
extends java.io.InputStream
implements java.nio.channels.ReadableByteChannel
Socket.getInputStream() and write() on
Socket.getOutputStream() for the associated socket will throw
IllegalBlockingModeException.
Please use SocketOutputStream for writing.| Constructor | Description |
|---|---|
SocketInputStream(java.net.Socket socket) |
Same as SocketInputStream(socket.getChannel(), socket.getSoTimeout())
:
Create a new input stream with the given timeout. |
SocketInputStream(java.net.Socket socket,
long timeout) |
Same as SocketInputStream(socket.getChannel(), timeout):
Create a new input stream with the given timeout. |
SocketInputStream(java.nio.channels.ReadableByteChannel channel,
long timeout) |
Create a new input stream with the given timeout.
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
close() |
|
java.nio.channels.ReadableByteChannel |
getChannel() |
|
boolean |
isOpen() |
|
int |
read() |
|
int |
read(byte[] b,
int off,
int len) |
|
int |
read(java.nio.ByteBuffer dst) |
|
void |
setTimeout(long timeoutMs) |
|
void |
waitForReadable() |
waits for the underlying channel to be ready for reading.
|
public SocketInputStream(java.nio.channels.ReadableByteChannel channel,
long timeout)
throws java.io.IOException
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.java.io.IOException - raised on errors performing I/O.public SocketInputStream(java.net.Socket socket,
long timeout)
throws java.io.IOException
socket - should have a channel associated with it.timeout - timeout timeout in milliseconds. must not be negative.java.io.IOException - raised on errors performing I/O.SocketInputStream(ReadableByteChannel, long)public SocketInputStream(java.net.Socket socket)
throws java.io.IOException
socket - should have a channel associated with it.java.io.IOException - raised on errors performing I/O.SocketInputStream(ReadableByteChannel, long)public int read()
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic int read(byte[] b,
int off,
int len)
throws java.io.IOException
read in class java.io.InputStreamjava.io.IOExceptionpublic void close()
throws java.io.IOException
close in interface java.lang.AutoCloseableclose in interface java.nio.channels.Channelclose in interface java.io.Closeableclose in class java.io.InputStreamjava.io.IOExceptionpublic java.nio.channels.ReadableByteChannel getChannel()
FileChannel.transferFrom(ReadableByteChannel, long, long).public boolean isOpen()
isOpen in interface java.nio.channels.Channelpublic int read(java.nio.ByteBuffer dst)
throws java.io.IOException
read in interface java.nio.channels.ReadableByteChanneljava.io.IOExceptionpublic void waitForReadable()
throws java.io.IOException
java.net.SocketTimeoutException - if select on the channel times out.java.io.IOException - if any other I/O error occurs.public void setTimeout(long timeoutMs)
Copyright © 2008–2025 Apache Software Foundation. All rights reserved.