Here you can find the source of readBytes(InputStream is)
public static byte[] readBytes(InputStream is) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readBytes(InputStream is) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); try {//from www. jav a2 s .c o m byte[] transfer = new byte[1024]; int read = -1; while ((read = is.read(transfer)) > 0) { bytesOut.write(transfer, 0, read); } } finally { safeClose(is); } return bytesOut.toByteArray(); } public static void safeClose(Closeable closeable) { try { closeable.close(); } catch (IOException ignored) { } } }