Java InputStream Read by Charset consume(InputStream stream, Charset encoding)

Here you can find the source of consume(InputStream stream, Charset encoding)

Description

consume

License

LGPL

Declaration

public static String consume(InputStream stream, 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 consume(InputStream stream, Charset encoding) throws IOException {
        final char[] buffer = new char[0x10000];
        final StringBuilder out = new StringBuilder();
        final Reader in = new InputStreamReader(stream, encoding);

        int read;
        do {/*www.  j  a  v  a  2 s . c om*/
            read = in.read(buffer, 0, buffer.length);
            if (read > 0)
                out.append(buffer, 0, read);
        } while (read >= 0);

        return out.toString();
    }
}

Related

  1. asString(final InputStream is, Charset charset)
  2. collectStream(InputStream stream, Charset charset)
  3. convertEncoding(Charset output_charset, String input_string)
  4. convertFromUnicode(String input, String targetCharset)
  5. convertStreamToString(final InputStream is, final Charset charset)
  6. convertToCharacterSet(byte[] input, Charset fromCharset, Charset toCharSet)