Check if DataInputStream has content

Pwnie2012 picture Pwnie2012 · Jan 19, 2014 · Viewed 7.9k times · Source

Is there a way to ask a DataInputStream, if it has content to read? .readByte() will just hang it, waiting for a byte to be read :( Or do I always have to send a Dummy-Byte, to make sure it always sees something?

Answer

Tomas Bisciak picture Tomas Bisciak · Jan 19, 2014
dis.available();

Returns: an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Is this what you looking for?

also check answers here. You might get even more informations. "available" of DataInputStream from Socket