Here you can find the source of getBytes(InputStream inputStream)
public static byte[] getBytes(InputStream inputStream) 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 final int BUFFER_SIZE = 1024; public static byte[] getBytes(InputStream inputStream) throws IOException { assert null != inputStream; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int numberRead; byte[] data = new byte[BUFFER_SIZE]; while ((numberRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, numberRead); }/*from www .j a v a2s. c o m*/ buffer.flush(); return buffer.toByteArray(); } }