Here you can find the source of getStreamContents(final InputStream is)
public static String getStreamContents(final InputStream is) throws IllegalArgumentException
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { private static final String DEFAULT_ENCODING = "UTF-8"; public static String getStreamContents(final InputStream is) throws IllegalArgumentException { return getStreamContents(is, DEFAULT_ENCODING); }/* w ww .j av a 2 s . c om*/ public static String getStreamContents(final InputStream is, final String enc) throws IllegalArgumentException { String content; try (Scanner scanner = new Scanner(is, enc).useDelimiter("\\Z")) { content = getScannerContents(scanner); } catch (NoSuchElementException | IllegalStateException e) { throw e; } return content; } public static String getScannerContents(final Scanner scanner) throws IllegalArgumentException { String content; if (scanner.hasNext()) { // will be false if file size == 0 content = scanner.next(); } else { content = ""; } return content; } }