Android Utililty Methods InputStream to Byte Array Convert

List of utility methods to do InputStream to Byte Array Convert

Description

The list of methods to do InputStream to Byte Array Convert are organized into topic(s).

Method

byte[]readBytes(InputStream in)
read Bytes
byte[] ret = new byte[0];
byte[] buf = new byte[2048];
int len;
for (;;) {
    len = in.read(buf);
    if (len > 0) {
        ret = Arrays.copyOf(ret, ret.length + len);
        System.arraycopy(buf, 0, ret, ret.length - len, len);
...
byte[]InputStreamTOByte(InputStream in)
Input Stream TO Byte
try {
    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;
    in.close();
...
byte[]InputStreamTOByte(InputStream in)
Input Stream TO Byte
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();
byte[]InputStreamTOByte(InputStream in)
Input Stream TO Byte
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();
byte[]InputStreamTOByte(InputStream in)
Input Stream TO Byte
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();
byte[]InputStreamTOByte(InputStream in)
Input Stream TO Byte
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();
byte[]InputStreamTOByte(InputStream in)
InputStream to byte array
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();
...
byte[]toByteArray(InputStream is)
to Byte Array
if (is == null) {
    return null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
    byte[] buf = new byte[1024];
    int count = 0;
    while ((count = is.read(buf)) != -1) {
...
byte[]toByteArray(InputStream is)
to Byte Array
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);
is.close();
...
byte[]toByteArray(InputStream is)
to Byte Array
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);
is.close();
return buffer.toByteArray();