Android InputStream to String Convert toString(InputStream is)

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

Description

to String

Declaration

public static String toString(InputStream is) throws IOException 

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 toString(InputStream is) throws IOException {
        if (null == is)
            return null;
        return toStringBuffer(is).toString();
    }/*from   w ww .ja  v a  2 s  .  co m*/

    public static StringBuilder toStringBuffer(InputStream is)
            throws IOException {
        if (null == is)
            return null;
        BufferedReader in = new BufferedReader(new InputStreamReader(is));
        StringBuilder buffer = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            buffer.append(line).append("\n");
        }
        is.close();
        return buffer;
    }
}

Related

  1. InputStreamTOString(InputStream in, String encoding)
  2. InputStreamTOString(InputStream in, String encoding)
  3. InputStreamTOString(InputStream in, String encoding)
  4. InputStreamTOString(InputStream in, String encoding)
  5. InputStreamTOStringUTF8(InputStream in)
  6. toString(InputStream is)
  7. toString(InputStream is)
  8. toString(InputStream is)
  9. toStringBuffer(InputStream is)