Android InputStream to String Convert inputStreamToString(final InputStream is)

Here you can find the source of inputStreamToString(final InputStream is)

Description

input Stream To String

Declaration

public static final String inputStreamToString(final InputStream is)
            throws IOException 

Method Source Code

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

public class Main {
    public static final String inputStreamToString(final InputStream is)
            throws IOException {
        final char[] buffer = new char[0x10000];
        final StringBuilder sb = new StringBuilder();
        final Reader in = new InputStreamReader(is, "utf-8");
        try {/* w ww.j a  va2 s  .  c o m*/
            int read;
            do {
                read = in.read(buffer, 0, buffer.length);
                if (read > 0) {
                    sb.append(buffer, 0, read);
                }
            } while (read >= 0);
        } finally {
            closeSilently(in);
        }
        return sb.toString();
    }

    public static void closeSilently(final Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Exception exc) {
                // Do nothing
            }
        }
    }
}

Related

  1. toString(InputStream is)
  2. toString(InputStream is)
  3. toStringBuffer(InputStream is)
  4. toStringBuffer(InputStream is)
  5. toStringBuffer(InputStream is)
  6. convertStreamToString(InputStream is)
  7. convertStreamToString(InputStream is)
  8. convertStreamToString(InputStream is)
  9. convertStreamToString(InputStream is)