DataInputStream allows you to read short and long. You must mask them with the appropriate bitmask ( 0xFFFFfor brevity, 0xFFFFFFFFfor 32 bits) to account for the difference between signed / unsigned types.
eg.
FileInputStream fis = ...;
DataInputStream stream = new DataInputStream(fis);
int short_value = 0xFFFF & stream.readShort();
long long_value = 0xFFFFFFFF & stream.readInt();
If you are sure that the data will not be sent to the upper end of the 2 byte or 4 byte field, you can refuse to mask the bits. Otherwise, you need to use a wider data type to account for the fact that unsigned values contain a larger range of values than their signed copies.
source
share