Android InputStream to Byte Array Convert InputStram2byteArray(InputStream in)

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

Description

Input Strambyte Array

Declaration

public static byte[] InputStram2byteArray(InputStream in) 

Method Source Code

//package com.java2s;

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

public class Main {

    public static byte[] InputStram2byteArray(InputStream in) {
        try {//from  ww  w  .  j  av  a  2 s.co m
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            if (in != null) {
                byte[] buffer = new byte[1024];
                int length = 0;
                while ((length = in.read(buffer)) != -1) {
                    out.write(buffer, 0, length);
                }
                out.close();
                in.close();
                return out.toByteArray();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}

Related

  1. readFile(InputStream in, String encoding)
  2. readFile(InputStream in, int size)
  3. stream2byte(InputStream inStream)
  4. inStream2byte(InputStream inStream)
  5. inStream2byte(InputStream inStream)
  6. getBytes(InputStream is)
  7. readBytes(InputStream in)
  8. InputStreamTOByte(InputStream in)
  9. InputStreamTOByte(InputStream in)