Here you can find the source of readbytes(InputStream input, int n)
public static byte[] readbytes(InputStream input, int n) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.InputStream; public class Main { /**//from ww w . j av a 2s. co m * read a number of signed bytes */ public static byte[] readbytes(InputStream input, int n) throws IOException { byte[] buffer = new byte[n]; readbytes_into(input, buffer, 0, n); return buffer; } /** * read a number of signed bytes into the specified location in an existing byte array */ public static void readbytes_into(InputStream input, byte[] buffer, int offset, int length) throws IOException { while (length > 0) { int read = input.read(buffer, offset, length); if (read == -1) throw new IOException("expected more bytes in input stream"); offset += read; length -= read; } } }