Android ByteArrayOutputStream Write copyStream(ByteArrayOutputStream source, ByteArrayOutputStream target)

Here you can find the source of copyStream(ByteArrayOutputStream source, ByteArrayOutputStream target)

Description

Copies source stream to target.

License

Open Source License

Parameter

Parameter Description
source The source.
name target The target.

Declaration

protected static void copyStream(ByteArrayOutputStream source,
        ByteArrayOutputStream target) throws Exception 

Method Source Code

 //package com.java2s;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;

 public class Main {
     /** //from   w ww.j a v a  2s  .  c  o  m
      *Copies source stream to target.
      * 
      *@param source The source. 
      *@param name 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);

             }
         }
     }
 }

Related

  1. writeUint32LE(ByteArrayOutputStream buffer, long value)
  2. writeUint64BE(ByteArrayOutputStream buffer, long value)
  3. writeUint64LE(ByteArrayOutputStream buffer, long value)
  4. copyTo(Context context, String fromPath, String toFile)
  5. writeInt(ByteArrayOutputStream baos, int i)