Java InputStream to Byte Array getBytesFromStream(InputStream inputStream)

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

Description

get Bytes From Stream

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
/**//  ww w  . ja va  2 s  .  c o  m
 * License: https://github.com/votingsystem/votingsystem/wiki/Licencia
 */

import java.io.*;

public class Main {
    private static final int BUFFER_SIZE = 4096;

    public static byte[] getBytesFromStream(InputStream inputStream) throws IOException {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        byte[] buf = new byte[BUFFER_SIZE];
        int len;
        while ((len = inputStream.read(buf)) > 0) {
            outputStream.write(buf, 0, len);
        }
        outputStream.close();
        inputStream.close();
        return outputStream.toByteArray();
    }
}

Related

  1. getBytesFromInputStream(InputStream inputStream)
  2. getBytesFromInputStream(InputStream inputStream)
  3. getBytesFromInputStream(InputStream is)
  4. getBytesFromInputStream(InputStream is)
  5. getBytesFromStream(InputStream input)
  6. getBytesFromStream(InputStream is)
  7. getBytesFromStream(InputStream is)
  8. getBytesFromStream(InputStream is)
  9. getBytesFromStream(InputStream is)