read Stream as byte array - Android File Input Output

Android examples for File Input Output:InputStream

Description

read Stream as byte array

Demo Code


//package com.java2s;
import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static byte[] readStream(InputStream paramInputStream)
            throws IOException {
        ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
        byte[] arrayOfByte = new byte[1024];
        while (true) {
            int i = paramInputStream.read(arrayOfByte);
            if (i == -1) {
                localByteArrayOutputStream.close();
                paramInputStream.close();
                return localByteArrayOutputStream.toByteArray();
            }//from  ww  w.j av a 2s  .  c  o m
            localByteArrayOutputStream.write(arrayOfByte, 0, i);
        }
    }
}

Related Tutorials