private static String inputStreamToString ( InputStream stream ) throws IOException { ByteArrayOutputStream result = new ByteArrayOutputStream ( ) ; byte [ ] buffer = new byte [ 1024 ] ; int length ; String resultString = null ; while ( ( length = stream . read ( buffer ) ) != - 1 ) { result . write ( buffer , 0 , length ) ; } resultString = result . toString ( "UTF-8" ) ; return resultString ; }
Utility method which converts an InputStream to a String .