Here you can find the source of inputStream2ByteArray(InputStream is)
public static ByteArrayOutputStream inputStream2ByteArray(InputStream is) throws IOException
//package com.java2s; /**// w w w . ja va 2 s.c o m * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * Copyright 2015 Chiori-chan. All Right Reserved. * * @author Chiori Greene * @email chiorigreene@gmail.com */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static ByteArrayOutputStream inputStream2ByteArray(InputStream is) throws IOException { int nRead; byte[] data = new byte[16384]; ByteArrayOutputStream bs = new ByteArrayOutputStream(); while ((nRead = is.read(data, 0, data.length)) != -1) { bs.write(data, 0, nRead); } bs.flush(); return bs; } }