1 51 package org.apache.fop.tools; 52 53 import java.io.InputStream ; 54 import java.io.OutputStream ; 55 import java.io.ByteArrayOutputStream ; 56 import java.io.IOException ; 57 58 63 public class IOUtil { 64 65 72 public static void copyStream(InputStream in, OutputStream out) throws IOException { 73 final int bufferSize = 2048; 74 final byte[] buf = new byte[bufferSize]; 75 int bytesRead; 76 while ((bytesRead = in.read(buf)) != -1) { 77 out.write(buf, 0, bytesRead); 78 } 79 } 80 81 82 91 public static byte[] toByteArray(InputStream in, int initialTargetBufferSize) 92 throws IOException { 93 ByteArrayOutputStream baout = new ByteArrayOutputStream (initialTargetBufferSize); 94 try { 95 copyStream(in, baout); 96 } finally { 97 baout.close(); 98 } 99 return baout.toByteArray(); 100 } 101 102 } 103 | Popular Tags |