Here you can find the source of readFromInputStream(InputStream stream, Charset charset)
public static String readFromInputStream(InputStream stream, Charset charset) throws IOException
//package com.java2s; //License from project: Creative Commons License import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.LinkedList; import java.util.List; public class Main { public static String readFromInputStream(InputStream stream, Charset charset) throws IOException { List<Byte> bytes = new LinkedList<>(); byte[] buffer = new byte[128]; int read; while ((read = stream.read(buffer)) != -1) { for (int i = 0; i < read; i++) { bytes.add(buffer[i]);//from w w w. j av a2s. co m } } int total = bytes.size(); buffer = new byte[total]; for (int i = 0; i < total; i++) { buffer[i] = bytes.remove(0); } if (charset == null) { return new String(buffer); } else { return new String(buffer, charset); } } public static String readFromInputStream(InputStream stream) throws IOException { return readFromInputStream(stream, null); } }