Java ByteArrayOutputStream Write readAll(InputStream inputStream)

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

Description

read All

License

Apache License

Declaration

public static byte[] readAll(InputStream inputStream) throws IOException 

Method Source Code


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

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

public class Main {
    public static byte[] readAll(InputStream inputStream) throws IOException {
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        while (true) {
            int len = inputStream.read(buffer);
            if (len < 0) {
                break;
            }//w  ww  .j  a va 2  s.  c o m
            bout.write(buffer, 0, len);
        }

        byte[] result = bout.toByteArray();
        bout.close();
        return result;
    }
}

Related

  1. readAll(InputStream in)
  2. readAll(InputStream in)
  3. readAll(InputStream in)
  4. readAll(InputStream in)
  5. readAll(InputStream in)
  6. readAll(InputStream is)
  7. readAll(InputStream s)
  8. readAll(InputStream stream)
  9. readAllAndClose(InputStream is)