Java InputStream to Byte Array inputStream2ByteArray(InputStream input)

Here you can find the source of inputStream2ByteArray(InputStream input)

Description

input Stream Byte Array

License

Open Source License

Declaration

public static byte[] inputStream2ByteArray(InputStream input) throws IOException 

Method Source Code


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

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

public class Main {

    public static byte[] inputStream2ByteArray(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        byte[] buffer = new byte[4096];
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);//from  w w w .  ja v  a  2  s  . c om
        }
        return output.toByteArray();
    }
}

Related

  1. getStreamAsBytes(final InputStream is)
  2. getStreamBytes(InputStream is)
  3. getStreamContent(InputStream stream)
  4. getStreamContentAsBytes(InputStream is)
  5. getStreamToBytes(InputStream stream)
  6. inputStream2ByteArray(InputStream is)
  7. inputStreamAsBytes(InputStream stream)
  8. inputStreamToArray(InputStream is)
  9. InputStreamTOByte(InputStream in)