Here you can find the source of copyBytesToStream(ByteArrayOutputStream from, OutputStream to)
public static void copyBytesToStream(ByteArrayOutputStream from, OutputStream to) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static void copyBytesToStream(ByteArrayOutputStream from, OutputStream to) throws IOException { OutputStream out = new BufferedOutputStream(to); try {/*w w w .j ava 2 s .com*/ from.writeTo(out); } finally { out.flush(); } } public static void copyBytesToStream(byte[] bytes, OutputStream to) throws IOException { to.write(bytes); } }