package at.gv.egiz.pdfas.utils; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class StreamUtils { public static void writeInputStreamToOutputStream (InputStream is, OutputStream os) throws IOException { byte [] buffer = new byte [2048]; int read = -1; while ((read = is.read(buffer)) > 0) { os.write(buffer, 0, read); } is.close(); os.close(); } // The InputStream should be self- delimited. // public static void writeInputStreamToOutputStream(InputStream is, OutputStream os, int length) throws IOException // { // byte [] buffer = new byte [2048]; // // int bytes_to_write = length; // // int read = -1; // while ((read = is.read(buffer, 0, (bytes_to_write >= buffer.length) ? buffer.length : bytes_to_write)) > 0) // { // os.write(buffer, 0, read); // bytes_to_write -= read; // } // is.close(); // os.close(); // // assert bytes_to_write == 0; // } }