Android InputStream to String Convert convertStreamToString(InputStream is)

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

Description

Converting input stream content to string

Parameter

Parameter Description
is input stream to convert

Exception

Parameter Description
IOException if problems with reading input stream

Return

String with stream content

Declaration

public static String convertStreamToString(InputStream is)
        throws IOException 

Method Source Code

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

public class Main {
    /**/*from   ww  w  .j  a va 2s  .c  om*/
     * Converting input stream content to string
     * @param is input stream to convert
     * @return String with stream content
     * @throws IOException if problems with reading input stream
     */
    public static String convertStreamToString(InputStream is)
            throws IOException {
        InputStreamReader r = new InputStreamReader(is);
        StringWriter sw = new StringWriter();
        char[] buffer = new char[1024];
        try {
            for (int n; (n = r.read(buffer)) != -1;)
                sw.write(buffer, 0, n);
        } finally {
            try {
                is.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return sw.toString();
    }
}

Related

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