Java ByteArrayOutputStream Write readAll(InputStream in)

Here you can find the source of readAll(InputStream in)

Description

read All

License

Open Source License

Declaration

public static byte[] readAll(InputStream in) 

Method Source Code


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

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

public class Main {
    public static byte[] readAll(InputStream in) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        copyTo(in, baos);//w  ww  .j a v  a  2 s . co m
        return baos.toByteArray();
    }

    public static void copyTo(InputStream in, OutputStream out) {
        try {
            byte[] arr = new byte[1024];
            int read;

            while ((read = in.read(arr)) != -1) {
                out.write(arr, 0, read);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. readAll(InputStream bytes)
  2. readAll(InputStream bytes, int bufferSize)
  3. readAll(InputStream in)
  4. readAll(InputStream in)
  5. readAll(InputStream in)
  6. readAll(InputStream in)
  7. readAll(InputStream in)
  8. readAll(InputStream in)
  9. readAll(InputStream in)