Here you can find the source of readBytes(InputStream is)
public static byte[] readBytes(InputStream is)
//package com.java2s; //License from project: Open Source 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) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try (InputStream bis = new BufferedInputStream(is)) { int b; while ((b = bis.read()) >= 0) { bos.write(b);/* w w w . j av a 2 s .c om*/ } } catch (IOException e) { throw new IllegalStateException(e); } return bos.toByteArray(); } }