Here you can find the source of readAllAndClose(InputStream is)
public static String readAllAndClose(InputStream is) throws Exception
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; public class Main { public static String readAllAndClose(InputStream is) throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); try {/* ww w.jav a 2s .co m*/ int read; while ((read = is.read()) != -1) { out.write(read); } } finally { try { is.close(); } catch (Exception e) { } } return out.toString(); } }