Android InputStream to String Convert fromStream(InputStream stream)

Here you can find the source of fromStream(InputStream stream)

Description

Read the whole stream into a string.

Parameter

Parameter Description
stream a parameter

Declaration

public static String fromStream(InputStream stream) 

Method Source Code

//package com.java2s;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.util.Log;

public class Main {
    /**//from   www. j  av a2s  . c om
     * Read the whole stream into a string. The connection is not closed by this method.
     * @param stream
     * @return
     */
    public static String fromStream(InputStream stream) {
        if (null == stream) {
            return null;
        }

        final StringBuilder sb = new StringBuilder();
        final BufferedReader br = new BufferedReader(new InputStreamReader(
                stream), 256);
        String line;

        while (true) {
            try {
                line = br.readLine();
            } catch (IOException e) {
                Log.e("StringUtil", "Error reading stream in HTTP get", e);
                break;
            }

            if (null == line) {
                break;
            }

            sb.append(line);
        }

        return sb.toString();
    }
}

Related

  1. readStringFromStream(InputStream is)
  2. getString(InputStream is)
  3. inputStream2String(InputStream is)
  4. inputStream2String(InputStream in)
  5. stream2String(InputStream is, int maxLength)
  6. toConvertString(InputStream is)
  7. inStream2String(InputStream is)
  8. inputStream2String(InputStream is)
  9. inStream2String(InputStream is)