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.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

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

Related

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