Here you can find the source of inputStream2String(InputStream source)
public static String inputStream2String(InputStream source) throws IOException
//package com.java2s; //License from project: LGPL import java.io.*; public class Main { private static final int BUFFER_SIZE = 16384; /** Read String from InputStream. */ public static String inputStream2String(InputStream source) throws IOException { StringWriter writer = new StringWriter(); BufferedReader reader = new BufferedReader(new InputStreamReader(source)); try {//w w w . ja v a 2 s . co m char[] buffer = new char[BUFFER_SIZE]; int charactersRead = reader.read(buffer, 0, buffer.length); while (charactersRead != -1) { writer.write(buffer, 0, charactersRead); charactersRead = reader.read(buffer, 0, buffer.length); } } finally { reader.close(); } return writer.toString(); } }