Here you can find the source of getBytesFromStream(InputStream is)
public static byte[] getBytesFromStream(InputStream is) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w ww . jav a 2 s . c o m * Matthew Hatem, IBM Corporation - initial API and implementation * Boris Bokowski, IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] getBytesFromStream(InputStream is) throws IOException { int BUFFER_SIZE = 8192; byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream os = new ByteArrayOutputStream(); int numRead = 0; while ((numRead = is.read(buffer)) > 0) { os.write(buffer, 0, numRead); } return os.toByteArray(); } }