Here you can find the source of readBytes(DataInputStream stream, int size)
public static byte[] readBytes(DataInputStream stream, int size) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.DataInputStream; import java.io.IOException; public class Main { public static byte[] readBytes(DataInputStream stream, int size) throws IOException { byte[] buf = new byte[size]; int toRead = size; int done = 0; while (toRead > 0) { int read = stream.read(buf, done, toRead); if (read == -1) { throw new IOException(); }/*from w w w. j av a 2s . co m*/ done += read; toRead -= read; } return buf; } }