Here you can find the source of copyAllBytes(InputStream in, OutputStream out)
public static int copyAllBytes(InputStream in, OutputStream out) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class Main { public static int copyAllBytes(InputStream in, OutputStream out) throws IOException { int byteCount = 0; byte[] buffer = new byte[4096]; while (true) { int read = in.read(buffer); if (read == -1) { break; }//from ww w. ja v a 2s. c o m out.write(buffer, 0, read); byteCount += read; } return byteCount; } }