Android InputStream to String Convert toString(InputStream is)

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

Description

to String

License

Open Source License

Declaration

public static String toString(InputStream is) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.http.util.ByteArrayBuffer;

public class Main {
    public static String toString(InputStream is) throws IOException {
        int char_ = 0;
        ByteArrayBuffer total = new ByteArrayBuffer(0);

        // Wrap a BufferedReader around the InputStream
        BufferedReader rd = new BufferedReader(new InputStreamReader(is));

        // Read response until the end
        while ((char_ = rd.read()) != -1) {
            total.append(char_);
        }/*from  ww w .j  av  a  2s .c  o  m*/

        // Return full string
        String output = new String(total.toByteArray());
        return output;
    }
}

Related

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