Java InputStream to String inputStreamToString(InputStream is)

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

Description

input Stream To String

License

Apache License

Declaration

public static String inputStreamToString(InputStream is) 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;
import java.io.Reader;

public class Main {
    public static String inputStreamToString(InputStream is) throws IOException {
        if (is == null) {
            throw new IllegalArgumentException("InputStream was null!");
        }//from ww  w  .j av a 2  s  .co  m
        final int bufferSize = 1024;
        final char[] buffer = new char[bufferSize];
        final StringBuilder out = new StringBuilder();
        Reader in = new InputStreamReader(is, "UTF-8");
        for (;;) {
            int rsz = in.read(buffer, 0, buffer.length);
            if (rsz < 0) {
                break;
            }
            out.append(buffer, 0, rsz);
        }
        return out.toString();
    }
}

Related

  1. inputStreamToString(InputStream inputStream, String charsetName)
  2. inputStreamToString(InputStream is)
  3. inputStreamToString(InputStream is)
  4. inputStreamToString(InputStream is)
  5. inputStreamToString(InputStream is)
  6. inputStreamToString(InputStream is)
  7. inputStreamToString(InputStream s)
  8. inputStreamToString(InputStream stream)
  9. InputStreamToStringArray(InputStream input_stream)