Here you can find the source of dumpStreamAndReOffer(InputStream is)
public static InputStream dumpStreamAndReOffer(InputStream is) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Gijs de Vries aka Janoz. * 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 * //from ww w .ja v a 2s . co m * Contributors: * Gijs de Vries aka Janoz - initial API and implementation ******************************************************************************/ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { private static final int BUFF_SIZE = 1024; public static InputStream dumpStreamAndReOffer(InputStream is) throws IOException { FileOutputStream fos = null; try { ByteArrayOutputStream os = new ByteArrayOutputStream(); copyStream(is, os); byte[] data = os.toByteArray(); fos = new FileOutputStream(File.createTempFile("dump", ".bin", new File("."))); fos.write(data); return new ByteArrayInputStream(data); } finally { if (fos != null) { fos.close(); } } } private static void copyStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[BUFF_SIZE]; int len; while ((len = in.read(buffer)) >= 0) { out.write(buffer, 0, len); } in.close(); out.close(); } }