Here you can find the source of copyStream(InputStream is)
public static InputStream copyStream(InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import java.io.OutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { public static InputStream copyStream(InputStream is) throws IOException { byte[] entity = new byte[4096]; int entitySize = 0; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((entitySize = is.read(entity)) != -1) baos.write(entity, 0, entitySize); InputStream cpis = new ByteArrayInputStream(baos.toByteArray()); baos.close();/*w w w. j av a 2 s. c o m*/ return cpis; } public static void copyStream(InputStream is, OutputStream os) throws IOException { byte[] entity = new byte[4096]; int entitySize = 0; while ((entitySize = is.read(entity)) != -1) os.write(entity, 0, entitySize); } }