EDIT: , , , . DataInput (, DataInputStream) readFully, . , , InputStream.
, InputStream , , . - , , ByteArrayInputStream. ( , , , , .)
, :
byte[] data = new byte[messageSize];
int totalRead = 0;
while (totalRead < messageSize) {
int bytesRead = stream.read(data, totalRead, messageSize - totalRead);
if (bytesRead < 0) {
throw new IOException("Data stream ended prematurely");
}
totalRead += bytesRead;
}