public static String fromStream ( InputStream stream ) throws IOException { if ( stream != null ) { try { Writer writer = new StringWriter ( ) ; Reader reader = new BufferedReader ( new InputStreamReader ( stream ) ) ; int read ; while ( ( read = reader . read ( ) ) != - 1 ) { writer . write ( read ) ; } return writer . toString ( ) ; } finally { try { stream . close ( ) ; } catch ( IOException e ) { logger . warn ( "error closing the input stream" , e ) ; } } } return null ; }
Reads from the given input stream into a String and returns it .