Generally not. Input streams do not provide timeout functionality.
However, in your particular case, that is, reading data from the socket, yes. What you need to do is set SO_TIMEOUT on your socket to a non-zero value (timeout in milliseconds). Any read operations that are blocked for the specified time will raise a SocketTimeoutException .
Beware though, even though your socket connection is still valid after that, reading from it may produce unexpected results, since you have already consumed your data halfway. The easiest way to handle this is to close the connection, but if you keep track of how much you have already read, you can restore and continue reading.
source share