Here you can find the source of copyBytes(InputStream inputStream, OutputStream outputStream, int size)
static public void copyBytes(InputStream inputStream, OutputStream outputStream, int size) throws IOException
//package com.java2s; /*//w w w . j av a2s .c om * Copyright 2014. * Distributed under the terms of the GPLv3 License. * * Authors: * Clemens Zeidler <czei002@aucklanduni.ac.nz> */ import java.io.*; public class Main { static public int BUFFER_SIZE = 8 * 1024; static public void copyBytes(InputStream inputStream, OutputStream outputStream, int size) throws IOException { int bufferLength = BUFFER_SIZE; byte[] buf = new byte[bufferLength]; int bytesRead = 0; while (bytesRead < size) { int requestedBunchSize = Math.min(size - bytesRead, bufferLength); int read = inputStream.read(buf, 0, requestedBunchSize); bytesRead += read; outputStream.write(buf, 0, read); } } }