Android Utililty Methods InputStream to String Convert

List of utility methods to do InputStream to String Convert

Description

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

Method

StringinStream2String(InputStream is)
in Stream String
ByteArrayOutputStream baos = null;
try {
    baos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int len = -1;
    while ((len = is.read(buf)) != -1) {
        baos.write(buf, 0, len);
    return new String(baos.toByteArray());
} catch (Exception e) {
    Log.e(TAG, e.getMessage(), e);
    return null;
} finally {
    if (baos != null) {
        try {
            baos.close();
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
StringinputStream2String(InputStream is)
input Stream String
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
while ((i = is.read()) != -1) {
    baos.write(i);
return baos.toString();
StringinStream2String(InputStream is)
in Stream String
ByteArrayOutputStream baos = null;
try {
    baos = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int len = -1;
    while ((len = is.read(buf)) != -1) {
        baos.write(buf, 0, len);
    return new String(baos.toByteArray());
} catch (Exception e) {
    Log.e(TAG, e.getMessage(), e);
    return null;
} finally {
    if (baos != null) {
        try {
            baos.close();
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
StringfromStream(InputStream inputStream)
from Stream
BufferedReader reader = new BufferedReader(new InputStreamReader(
        inputStream), BUFFER_SIZE);
StringBuilder stringBuilder = new StringBuilder();
String line;
try {
    while ((line = reader.readLine()) != null) {
        ALog.i(line);
        stringBuilder.append(line);
...
StringparseString(InputStream is)
parse String
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
    br = new BufferedReader(new InputStreamReader(is));
    while ((line = br.readLine()) != null) {
        sb.append(line);
} catch (IOException e) {
    e.printStackTrace();
} finally {
    if (br != null) {
        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
return sb.toString();
StringconvertStreamToString(InputStream is)
convert Stream To String
if (is != null) {
    Writer writer = new StringWriter();
    char[] buffer = new char[1024];
    try {
        Reader reader = new BufferedReader(new InputStreamReader(
                is, "UTF-8"));
        int n;
        while ((n = reader.read(buffer)) != -1) {
...
StringreadToString(final InputStream inputStream)
read To String
return new Scanner(inputStream).useDelimiter("\\A").next();
StringinputStreamToString(InputStream inputstream)
input Stream To String
InputStreamReader inputstreamreader = new InputStreamReader(
        inputstream);
BufferedReader bufferedreader = new BufferedReader(
        inputstreamreader);
StringBuilder stringbuilder = new StringBuilder();
do {
    String s = bufferedreader.readLine();
    if (s != null) {
...
StringstreamToString(InputStream is)
stream To String
String str = "";
if (is != null) {
    StringBuilder sb = new StringBuilder();
    String line;
    try {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));
        while ((line = reader.readLine()) != null) {
...
StringinputStreamToString(InputStream is)
Gets the string representation of the InputStream
if (is != null) {
    BufferedReader reader = new BufferedReader(
            new InputStreamReader(is));
    StringBuilder sb = new StringBuilder();
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
...