Android InputStream to Byte Array Convert InputStreamTOByte(InputStream in)

Here you can find the source of InputStreamTOByte(InputStream in)

Description

InputStream to byte array

Parameter

Parameter Description
in InputStream

Exception

Parameter Description
IOException an exception

Return

byte[]

Declaration

public static byte[] InputStreamTOByte(InputStream in)
        throws IOException 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

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

public class Main {
    final static int BUFFER_SIZE = 4096;

    /**/* ww  w . ja v  a2 s .c om*/
     * InputStream to byte array
     * 
     * @param in
     *            InputStream
     * @return byte[]
     * @throws IOException
     */
    public static byte[] InputStreamTOByte(InputStream in)
            throws IOException {

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[BUFFER_SIZE];
        int count = -1;
        while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
            outStream.write(data, 0, count);
        }

        data = null;
        return outStream.toByteArray();
    }
}

Related

  1. InputStreamTOByte(InputStream in)
  2. InputStreamTOByte(InputStream in)
  3. InputStreamTOByte(InputStream in)
  4. InputStreamTOByte(InputStream in)
  5. InputStreamTOByte(InputStream in)
  6. toByteArray(InputStream is)
  7. toByteArray(InputStream is)
  8. toByteArray(InputStream is)
  9. inputStreamToByte(InputStream is)