Android InputStream to String Convert inputStream2String(InputStream in)

Here you can find the source of inputStream2String(InputStream in)

Description

input Stream String

Declaration

public static String inputStream2String(InputStream in) 

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 {
    public static String inputStream2String(InputStream in) {

        StringBuffer sb = new StringBuffer();
        InputStreamReader isr = new InputStreamReader(in);
        BufferedReader reader = new BufferedReader(isr);

        try {//from   w w w .  j av  a2s.  c o m
            String line;
            line = reader.readLine();
            while (line != null) {
                sb.append(line);
                line = reader.readLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (null != reader) {
                    reader.close();
                    reader = null;
                }
                if (null != isr) {
                    isr.close();
                    isr = null;
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return sb.toString();
    }
}

Related

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