code: public static void copy(InputStream in, OutputStream out, long count,
  			int bufferSize) throws IOException {
  		byte buffer[] = new byte[bufferSize];
  		int i = bufferSize;
  		if (count >= 0) {
  			while (count > 0) {
  				if (count < bufferSize)
  					i = in.read(buffer, 0, (int) count);
  				else
  					i = in.read(buffer, 0, bufferSize);
  
  				if (i == -1)
  					break;
  
  				count -= i;
  				out.write(buffer, 0, i);
  			}
  		} else {
  			while (true) {
  				i = in.read(buffer, 0, bufferSize);
  				if (i < 0)
  					break;
  				out.write(buffer, 0, i);
  			}
  		}
  	}
docs: Copy the specified number of bytes from an input stream to an output
  stream. It is up to the caller to close the streams.
  
  @param in
  input stream
  @param out
  output stream
  @param count
  number of bytes to copy
  @param bufferSize
  buffer size
  @throws IOException
  on any error