Java InputStream Copy copyStream(InputStream is)

Here you can find the source of copyStream(InputStream is)

Description

copy Stream

License

Open Source License

Declaration

public static InputStream copyStream(InputStream is) throws IOException 

Method Source Code


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

import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class Main {
    public static InputStream copyStream(InputStream is) throws IOException {
        byte[] entity = new byte[4096];
        int entitySize = 0;
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while ((entitySize = is.read(entity)) != -1)
            baos.write(entity, 0, entitySize);
        InputStream cpis = new ByteArrayInputStream(baos.toByteArray());
        baos.close();/*w  w w. j av  a  2 s. c  o  m*/
        return cpis;
    }

    public static void copyStream(InputStream is, OutputStream os) throws IOException {
        byte[] entity = new byte[4096];
        int entitySize = 0;
        while ((entitySize = is.read(entity)) != -1)
            os.write(entity, 0, entitySize);
    }
}

Related

  1. copyLarge(InputStream input, OutputStream output, byte[] buffer)
  2. copyLarge(InputStream input, OutputStream output, final long inputOffset, final long length, byte[] buffer)
  3. copyLarge(InputStream input, OutputStream output, final long inputOffset, final long length, byte[] buffer)
  4. copyLarge(InputStream input, OutputStream output, long limit)
  5. copyStream(final BufferedReader in, final PrintWriter out, final String[] mapFrom, String[] mapTo)
  6. copyStream(InputStream is)
  7. copyStream(InputStream iss)
  8. copyStream(Reader in, Writer out)
  9. copyStream(Reader in, Writer out)