Android InputStream to String Convert readIt(InputStream stream)

Here you can find the source of readIt(InputStream stream)

Description

Reads an InputStream as an UTF-8 string

License

Apache License

Parameter

Parameter Description
stream The InputStream

Exception

Parameter Description
IOException If reading fails

Return

The read string

Declaration

private static String readIt(InputStream stream) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    /**//  www .ja  va 2  s .  co  m
     * Reads an InputStream as an UTF-8 string
     * 
     * @param stream
     *       The InputStream
     * @return
     *       The read string
     * @throws IOException
     *       If reading fails
     */
    private static String readIt(InputStream stream) throws IOException {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(stream));
        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }
        br.close();
        return sb.toString();
    }
}

Related

  1. inputStreamToString(InputStream inputStream)
  2. streamToString(InputStream is)
  3. slurp(InputStream in)
  4. convertStreamToString(InputStream is)
  5. inStream2Str(InputStream inputStream, String encode)
  6. inputStream2String(InputStream inputStream)
  7. InputStreamTOString(InputStream in)
  8. InputStreamTOString(InputStream in)
  9. InputStreamTOString(InputStream in)