Here you can find the source of getBytesFromStream(InputStream input)
public static byte[] getBytesFromStream(InputStream input) throws IOException
//package com.java2s; /*/*w ww.ja v a2 s . c om*/ * Part of the CCNx Java Library. * * Copyright (C) 2008-2012 Palo Alto Research Center, Inc. * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 2.1 * as published by the Free Software Foundation. * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. You should have received * a copy of the GNU Lesser General Public License along with this library; * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, * Fifth Floor, Boston, MA 02110-1301 USA. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Read a stream (usually small) completely in to a byte array. Used to get all of the * bytes out of one or more content objects for decoding or other processing, where the * content needs to be handed to something else as a unit. */ public static byte[] getBytesFromStream(InputStream input) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int byteCount = 0; byteCount = input.read(buf); while (byteCount > 0) { baos.write(buf, 0, byteCount); byteCount = input.read(buf); } return baos.toByteArray(); } }