Java InputStream to OutputStream copyStream(InputStream in, OutputStream out)

Here you can find the source of copyStream(InputStream in, OutputStream out)

Description

copy Stream

License

Open Source License

Declaration

public static void copyStream(InputStream in, OutputStream out) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static final int BUFSIZ = 0x2000;

    public static void copyStream(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[BUFSIZ];
        for (;;) {
            int size = in.read(buffer);
            if (size <= 0)
                break;
            out.write(buffer, 0, size);/*from  w w  w  .  j a  v  a2s .  c  o m*/
        }
    }

    public static void copyStream(InputStream src, OutputStream dst, long length) throws IOException {
        byte[] buffer = new byte[BUFSIZ];
        for (;;) {
            int size = src.read(buffer);
            if (size < 0)
                break;
            dst.write(buffer, 0, size);
            length -= size;
            if (length <= 0)
                break;
        }
    }
}

Related

  1. copyStream(InputStream in, OutputStream out)
  2. copyStream(InputStream in, OutputStream out)
  3. copyStream(InputStream in, OutputStream out)
  4. copyStream(InputStream in, OutputStream out)
  5. copyStream(InputStream in, OutputStream out)
  6. copyStream(InputStream in, OutputStream out)
  7. copyStream(InputStream in, OutputStream out)
  8. copyStream(InputStream in, OutputStream out)
  9. copyStream(InputStream in, OutputStream out)