I’m using a DataInputStream to read characters/data from a socket.
I want to use .readUnsignedShort(); and have it throw an exception if there isn’t 2 bytes to read. Should I subclass the DataInputStream and override the methods adding the exceptions, or is there an easier way?
If you want something quick and dirty, try inputStream.available().
If you want true non blocking reads and callbacks when data is available, I think Pablo’s answer is better.