Android InputStream Read readInputStreamToString(InputStream input, String enCoding)

Here you can find the source of readInputStreamToString(InputStream input, String enCoding)

Description

read Input Stream To String

License

Apache License

Declaration

public static String readInputStreamToString(InputStream input,
        String enCoding) 

Method Source Code

//License from project: Apache License 

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class Main{
    private static LogUtil log = LogUtil.getLogger(FileUtil.class);
    /*from  www. j  a  v a  2 s. c  o m*/
    public static String readInputStreamToString(InputStream input,
            String enCoding) {
        BufferedReader reader;
        StringBuilder sb = new StringBuilder();
        String line = null;
        try {
            reader = new BufferedReader(new InputStreamReader(input,
                    enCoding));
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\r\n");
            }
        } catch (IOException e) {
            log.error(e.getMessage());
        } finally {
            try {
                input.close();
            } catch (IOException e) {
                log.error(e.getMessage());
            }
        }
        return sb.toString();

    }
}

Related

  1. ReadInt(FileInputStream stream)
  2. ReadString(FileInputStream stream)
  3. readContents(InputStream input, String encoding)
  4. readFile(InputStream input)
  5. readFully(InputStream in)
  6. writeToStream(InputStream in, OutputStream out, boolean closeOnExit)
  7. readStream(InputStream in)
  8. readStream(InputStream in)
  9. readStream(InputStream in)