Here you can find the source of writeStream(InputStream input, OutputStream output)
public static void writeStream(InputStream input, OutputStream output)
import java.io.*; import java.nio.channels.*; public class Main{ public static void writeStream(InputStream input, OutputStream output) { try {/* w w w .j a v a2 s. c om*/ append(input, output); Closeable zCloseable = output; output = null; close(zCloseable); } finally { dispose(output); } } public static void append(InputStream input, OutputStream output) { assertNotNull("input", input); assertNotNull("output", output); byte[] buf = new byte[1024]; try { for (int len; (len = input.read(buf)) > -1;) { if (len != 0) { output.write(buf, 0, len); } } } catch (IOException e) { throw new WrappedIOException(e); } } public static void close(Closeable pCloseable) { if (pCloseable != null) { try { pCloseable.close(); } catch (IOException e) { throw new WrappedIOException(e); } } } public static Closeable dispose(Closeable pCloseable) { if (pCloseable != null) { try { pCloseable.close(); } catch (IOException ignore) { // Whatever! } pCloseable = null; } return pCloseable; } }