Here you can find the source of writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer)
public static int writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer) throws IOException
//package com.java2s; //License from project: LGPL import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class Main { public static int writeStream(OutputStream outputStream, InputStream inputStream, byte[] buffer) throws IOException { int totalWritten = 0; int read = 0; while ((read = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, read); totalWritten += read;//from ww w .ja v a 2 s.c om } return totalWritten; } public static int writeStream(OutputStream outputStream, InputStream inputStream) throws IOException { return writeStream(outputStream, inputStream, new byte[8192]); } public static int writeStream(OutputStream stream, String str) throws IOException { return writeStream(stream, str.getBytes("UTF-8")); } public static int writeStream(OutputStream stream, byte[] data) throws IOException { final InputStream fs = new ByteArrayInputStream(data); int totalWritten = writeStream(stream, fs); fs.close(); return totalWritten; } }