Java InputStream to String inputStreamToString(InputStream is)

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

Description

input Stream To String

License

LGPL

Declaration

public static String inputStreamToString(InputStream is) throws IOException 

Method Source Code


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

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

public class Main {
    protected static final int STREAM_BUFFER_SIZE = 1024;

    public static String inputStreamToString(InputStream is) throws IOException {
        StringBuilder sb = new StringBuilder();

        Reader reader = new InputStreamReader(is);

        char[] buffer = new char[STREAM_BUFFER_SIZE];
        int count;
        while ((count = reader.read(buffer)) > 0) {
            sb.append(buffer, 0, count);
        }/* w  w  w  . java  2  s.  c  o m*/

        return sb.toString();
    }
}

Related

  1. inputStreamToString(InputStream is)
  2. inputStreamToString(InputStream is)
  3. inputStreamToString(InputStream is)
  4. inputStreamToString(InputStream is)
  5. inputStreamToString(InputStream is)
  6. inputStreamToString(InputStream s)
  7. inputStreamToString(InputStream stream)
  8. InputStreamToStringArray(InputStream input_stream)
  9. inputStreamToStringBuffer(InputStream stream)