-1

In my application I use socket to communication with another device how I can check if inputStream is empty ? In this line I have a java.net.SocketTimeoutException

while ((bytesRead = inputStream.read(content)) != -1) {
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Krzysztof Pokrywka
  • 1,356
  • 4
  • 27
  • 50
  • Define 'empty'. The timeout has already told you there is no data available *now*, but that doesn't mean there never will be. There's generally no need to move beyond read timeouts. – user207421 Nov 08 '17 at 09:21

1 Answers1

1

Try inputstream.available(). It returns an estimate of the number of bytes that can be read from this input stream without blocking by the next invocation of a method for this input stream.

RonTLV
  • 2,376
  • 2
  • 24
  • 38