Android InputStream to String Convert inputStreamToString(InputStream is)

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

Description

Gets the string representation of the InputStream

Parameter

Parameter Description
is InputStream

Return

The string representation of the InputStream

Declaration

public static String inputStreamToString(InputStream is) 

Method Source Code

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

public class Main {
    /** Gets the string representation of the InputStream
     * @param is InputStream//from w w w  .ja  v a 2  s  .  c  o m
     * @return The string representation of the InputStream
     */
    public static String inputStreamToString(InputStream is) {
        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");
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return sb.toString();
        }

        return "";
    }
}

Related

  1. parseString(InputStream is)
  2. convertStreamToString(InputStream is)
  3. readToString(final InputStream inputStream)
  4. inputStreamToString(InputStream inputstream)
  5. streamToString(InputStream is)
  6. inputStreamToString(InputStream stream)
  7. streamToString(InputStream in, String charset)
  8. InputStreamToString(InputStream in)
  9. inputToString(InputStream inputStream, String encoding)