Java InputStream to Byte Array getBytesFromInputStream(InputStream is)

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

Description

get Bytes From Input Stream

License

Open Source License

Declaration

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

Method Source Code

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

import java.io.*;

public class Main {
    public static byte[] getBytesFromInputStream(InputStream is) throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        int nRead;
        byte[] data = new byte[16384];

        while ((nRead = is.read(data, 0, data.length)) != -1) {
            buffer.write(data, 0, nRead);
        }/*from  w w w .  j  a v a 2  s  . co  m*/

        buffer.flush();

        return buffer.toByteArray();
    }
}

Related

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