public String inputStreamToString ( InputStream is , String charset ) throws IOException { InputStreamReader isr = null ; if ( null == charset ) { isr = new InputStreamReader ( is ) ; } else { isr = new InputStreamReader ( is , charset ) ; } StringWriter sw = new StringWriter ( ) ; int c = - 1 ; while ( ( c = isr . read ( ) ) != - 1 ) { sw . write ( c ) ; } isr . close ( ) ; return sw . getBuffer ( ) . toString ( ) ; }
Write to a string the bytes read from an input stream .