Java ByteArrayOutputStream Write readAll(InputStream aInputStream)

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

Description

read All

License

Open Source License

Declaration

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

Method Source Code

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

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

public class Main {
    public static byte[] readAll(InputStream aInputStream)
            throws IOException {
        try (InputStream in = aInputStream) {
            byte[] buffer = new byte[4096];
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            for (;;) {
                int len = in.read(buffer);

                if (len <= 0) {
                    break;
                }/*from  w  w  w. j av a2  s  .co  m*/

                baos.write(buffer, 0, len);
            }

            return baos.toByteArray();
        }
    }
}

Related

  1. loadIfileAsBytes(final IFile ifile)
  2. loadIntoMemory(InputStream is)
  3. loadProbe(InputStream in, int buffSize)
  4. loadStream(InputStream in, String encoding)
  5. readAll(File file)
  6. readAll(InputStream bytes)
  7. readAll(InputStream bytes, int bufferSize)
  8. readAll(InputStream in)
  9. readAll(InputStream in)