Here you can find the source of getBytesFromInputStream(InputStream is)
private static byte[] getBytesFromInputStream(InputStream is) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { private static byte[] getBytesFromInputStream(InputStream is) throws IOException { try (ByteArrayOutputStream os = new ByteArrayOutputStream();) { byte[] buffer = new byte[0xFFFF]; for (int len; (len = is.read(buffer)) != -1;) os.write(buffer, 0, len); os.flush();// w w w . jav a2s. co m return os.toByteArray(); } } }