Java InputStream Read by Charset streamToString(InputStream inputStream, Charset encoding)

Here you can find the source of streamToString(InputStream inputStream, Charset encoding)

Description

stream To String

License

LGPL

Declaration

public static String streamToString(InputStream inputStream, Charset encoding) 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;
import java.nio.charset.Charset;

public class Main {
    public static String streamToString(InputStream inputStream, Charset encoding) throws IOException {
        final int bufferSize = 1024;
        final char[] buffer = new char[bufferSize];
        final StringBuilder out = new StringBuilder();

        Reader in = new InputStreamReader(inputStream, encoding);
        for (;;) {
            int rsz = in.read(buffer, 0, buffer.length);
            if (rsz < 0)
                break;
            out.append(buffer, 0, rsz);/*from w  w w.  jav  a  2 s . c o  m*/
        }
        return out.toString();
    }
}

Related

  1. loadInputStream(InputStream in, Charset cs)
  2. processSubstitute(CharBuffer cb, String replacement, boolean endOfInput, String outputCharset, OutputStream os)
  3. stream2Bytes(InputStream is, Charset charset)
  4. streamString(InputStream in, boolean closeIn, String charset)
  5. streamToString(final InputStream is, final Charset charset)
  6. stringFromStream(InputStream in, Charset cs)
  7. toInputStream(final String string, final Charset charset)
  8. toInputStream(String input, Charset charset)
  9. toInputStream(String input, Charset cs)