Read InputStream To String via ByteArrayOutputStream - Android java.io

Android examples for java.io:ByteArrayOutputStream

Description

Read InputStream To String via ByteArrayOutputStream

Demo Code

import android.graphics.Color;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.BackgroundColorSpan;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;

public class Main{
    public static int BUFFER_SIZE = 512;

    public static String InputStreamToString(InputStream in)
            throws Exception {
        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);
        }/*from  ww w .  j av  a2  s  .c o m*/
        data = null;
        return new String(outStream.toByteArray(), "ISO-8859-1");

    }

}

Related Tutorials