Android InputStream to String Convert convertStreamToString(InputStream is)

Here you can find the source of convertStreamToString(InputStream is)

Description

convert Stream To String

Declaration

private static String convertStreamToString(InputStream is) 

Method Source Code

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

import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    private static String convertStreamToString(InputStream is) {
        /*//from   w ww.  j  a va2 s. c o  m
         * To convert the InputStream to String we use the
         * BufferedReader.readLine() method. We iterate until the BufferedReader
         * return null which means there's no more data to read. Each line will
         * appended to a StringBuilder and returned as String.
         */
        StringBuilder sb = new StringBuilder();

        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is, "UTF-8"));

            String line = null;

            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                is.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
}

Related

  1. InputStreamToString(InputStream stream)
  2. convertInputStreamToString(InputStream inputStream)
  3. convertStreamToString(InputStream inputStream)
  4. convertStreamToString(InputStream inputStream)
  5. convertStreamToString(InputStream is)
  6. convertStreamToString(InputStream is)
  7. convertStreamToString(InputStream is)
  8. convertStreamToString(InputStream is)
  9. convertStreamToString(InputStream is)