Android InputStream to Byte Array Convert getBytes(InputStream inputStream)

Here you can find the source of getBytes(InputStream inputStream)

Description

get Bytes

Declaration

public static byte[] getBytes(InputStream inputStream)
            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[] getBytes(InputStream inputStream)
            throws IOException {
        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];

        int len = 0;
        while ((len = inputStream.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }// ww  w. j  av a2 s .c  o m

        return byteBuffer.toByteArray();
    }
}

Related

  1. getFileByte(InputStream inputStream)
  2. readBytes(InputStream s)
  3. readFile(InputStream in, String encoding)
  4. readFile(InputStream in, int size)