Android InputStream to Byte Array Convert toByteArray(InputStream is)

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

Description

to Byte Array

Declaration

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

Method Source Code

//package com.java2s;

import java.io.*;

public class Main {

    public static byte[] toByteArray(InputStream is) throws IOException {
        if (null == is) {
            return null;
        }/* w  w w . j a  v  a  2  s. c  o m*/
        byte[] cache = new byte[2 * 1024];
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        for (int length; (length = is.read(cache)) != -1;) {
            buffer.write(cache, 0, length);
        }
        is.close();
        return buffer.toByteArray();
    }
}

Related

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