Here you can find the source of copyStream(ByteArrayOutputStream source, ByteArrayOutputStream target)
Parameter | Description |
---|---|
source | The source. |
target | The target. |
protected static void copyStream(ByteArrayOutputStream source, ByteArrayOutputStream target) throws Exception
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; public class Main { /** /*from w w w .j a v a2 s . c om*/ *Copies source stream to target. * *@param source The source. *@param target The target. **/ protected static void copyStream(ByteArrayOutputStream source, ByteArrayOutputStream target) throws Exception { // See if this is a MemoryStream -- we can use WriteTo. /* InputStream inputStream = new FileInputStream ("D:\\EWS ManagedAPI sp2\\Rp\\xml\\useravailrequest.xml"); byte buf[]=new byte[1024]; int len; while((len=inputStream.read(buf))>0) { target.write(buf,0, len); } */ /*PrintWriter pw = new PrintWriter(source,true); PrintWriter pw1 = new PrintWriter(target,true); pw1.println(pw.toString());*/ ByteArrayOutputStream memContentStream = source; if (memContentStream != null) { memContentStream.writeTo(target); memContentStream.flush(); } else { // Otherwise, copy data through a buffer int c; ByteArrayInputStream inStream = new ByteArrayInputStream( source.toByteArray()); while ((c = inStream.read()) != -1) { target.write((char) c); } } } }