public static String readStreamAsString ( InputStream stream ) throws IOException { try ( Scanner sc = new Scanner ( stream , Charset . defaultCharset ( ) . name ( ) ) ) { sc . useDelimiter ( "\\A" ) ; return sc . next ( ) ; } }
Reads whole content of input stream to String