Here you can find the source of getStreamContent(InputStream stream)
public static byte[] getStreamContent(InputStream stream) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2009, 2014 Xored Software Inc 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 .j a va 2 s. c om * Xored Software Inc - initial API and implementation and/or initial documentation *******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] getStreamContent(InputStream stream) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); try { byte[] buffer = new byte[4096]; int len = 0; while ((len = stream.read(buffer)) > 0) { output.write(buffer, 0, len); } } finally { safeClose(stream); } return output.toByteArray(); } public static void safeClose(Closeable closeable) { try { closeable.close(); } catch (Exception e) { } } }