Here you can find the source of readBytes(InputStream is)
public static byte[] readBytes(InputStream is)
//package com.java2s; //License from project: Apache License import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readBytes(InputStream is) { BufferedInputStream bufin = new BufferedInputStream(is); int buffSize = 1024; ByteArrayOutputStream out = new ByteArrayOutputStream(buffSize); byte[] temp = new byte[buffSize]; int size = 0; try {/*from www . jav a 2 s .c o m*/ while ((size = bufin.read(temp)) != -1) { out.write(temp, 0, size); } bufin.close(); } catch (IOException e) { e.printStackTrace(); } return out.toByteArray(); } }