Here you can find the source of inputStreamToString(InputStream s)
public static String inputStreamToString(InputStream s)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; public class Main { public static String inputStreamToString(InputStream s) { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int length; try {//from w w w. ja v a 2 s. co m while ((length = s.read(buffer)) != -1) { result.write(buffer, 0, length); } } catch (IOException e1) { e1.printStackTrace(); return null; } // StandardCharsets.UTF_8.name() > JDK 7 try { return result.toString("UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } }