Java InputStream Copy copyStream(InputStream is)

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

Description

copy Stream

License

Apache License

Declaration

public static byte[] copyStream(InputStream is) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static byte[] copyStream(InputStream is) throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        int nRead;
        byte[] data = new byte[64 * 1024];
        while ((nRead = is.read(data, 0, data.length)) != -1) {
            buffer.write(data, 0, nRead);
        }/*from  ww w.java  2s.c o  m*/
        buffer.flush();

        return buffer.toByteArray();
    }
}

Related

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