Java InputStream to String getStreamAsString(InputStream input, String charset)

Here you can find the source of getStreamAsString(InputStream input, String charset)

Description

get Stream As String

License

Open Source License

Declaration

private static String getStreamAsString(InputStream input, String charset) throws IOException 

Method Source Code


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

public class Main {
    private static String getStreamAsString(InputStream input, String charset) throws IOException {
        StringBuilder sb = new StringBuilder();
        BufferedReader bf = null;
        try {//from   www .java2 s  .c  o  m
            bf = new BufferedReader(new InputStreamReader(input, charset));
            String str;
            while ((str = bf.readLine()) != null) {
                sb.append(str);
            }
            return sb.toString();
        } finally {
            if (bf != null) {
                bf.close();
                bf = null;
            }
        }

    }
}

Related

  1. getInputStreamContent(InputStream i, String encoding)
  2. getInputStreamContent(InputStream inputStream)
  3. getInputStreamContents(InputStream inputStream)
  4. getInputStreamContents(InputStream inputStream)
  5. getStreamAsString(final InputStream stream)
  6. getStreamAsString(InputStream is, String encoding)
  7. getStreamAsString(InputStream stream)
  8. getStreamAsString(InputStream stream, String charset)
  9. getStreamContent(InputStream is)