Java InputStream to String getInputStreamAsString(InputStream inStream)

Here you can find the source of getInputStreamAsString(InputStream inStream)

Description

get Input Stream As String

License

Apache License

Declaration

public static String getInputStreamAsString(InputStream inStream) throws IOException 

Method Source Code

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

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

public class Main {

    public static String getInputStreamAsString(InputStream inStream) throws IOException {
        // todo: should i wrap inputStream in BufferedInputStream?
        StringBuffer text = new StringBuffer();

        InputStreamReader in = new InputStreamReader(inStream, "Unicode");
        char buffer[] = new char[4096];
        int bytes_read;
        while ((bytes_read = in.read(buffer)) != -1)
            text.append(new String(buffer, 0, bytes_read));

        return text.toString();
    }//from   w w w .  j a v a  2s. c  om
}

Related

  1. asArrayString(InputStream response)
  2. getInputStreamAsString(final InputStream is, final String encoding)
  3. getInputStreamAsString(InputStream stream)
  4. getInputStreamContent(InputStream i, String encoding)
  5. getInputStreamContent(InputStream inputStream)
  6. getInputStreamContents(InputStream inputStream)