public static String read ( InputStream in , String charset ) throws IOException { if ( in == null ) { throw new IllegalArgumentException ( "input stream cannot be null" ) ; } InputStreamReader reader = null ; try { reader = new InputStreamReader ( in , charset ) ; char [ ] buffer = new char [ 1024 ] ; StringBuilder sb = new StringBuilder ( ) ; int len ; while ( ( len = reader . read ( buffer ) ) != - 1 ) { sb . append ( buffer , 0 , len ) ; } return sb . toString ( ) ; } finally { closeQuietly ( reader ) ; } }
Reads contents of the input stream fully and returns it as String .