Convert InputStream to Byte Array - Android android.view.inputmethod

Android examples for android.view.inputmethod:KeyBoard

Description

Convert InputStream to Byte Array

Demo Code

import android.annotation.SuppressLint;
import android.util.Log;
import java.io.*;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.regex.Pattern;

public class Main{

    public static byte[] toByteArray(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output);/*from  ww w. j a  v a2s  .c  o  m*/
        return output.toByteArray();
    }
    public static void copy(InputStream in, OutputStream out)
            throws IOException {
        byte[] buffer = new byte[1024 * 32];
        int read;
        while ((read = in.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
    }

}

Related Tutorials