Android InputStream to String Convert convertStreamToString(InputStream is)

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

Description

convert Stream To String

License

Open Source License

Declaration

public static String convertStreamToString(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 java.io.Reader;
import java.io.StringWriter;
import java.io.Writer;

public class Main {
    public static String convertStreamToString(InputStream is)
            throws IOException {
        if (is != null) {
            Writer writer = new StringWriter();
            char[] buffer = new char[1024];
            try {
                Reader reader = new BufferedReader(new InputStreamReader(
                        is, "UTF-8"));
                int n;
                while ((n = reader.read(buffer)) != -1) {
                    writer.write(buffer, 0, n);
                }//from  w  w w. ja va 2s .c om
            } finally {
                is.close();
            }
            return writer.toString();
        } else {
            return "";
        }
    }
}

Related

  1. inStream2String(InputStream is)
  2. inputStream2String(InputStream is)
  3. inStream2String(InputStream is)
  4. fromStream(InputStream inputStream)
  5. parseString(InputStream is)
  6. readToString(final InputStream inputStream)
  7. inputStreamToString(InputStream inputstream)
  8. streamToString(InputStream is)
  9. inputStreamToString(InputStream is)