code: 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();
      }
docs: Write to a string the bytes read from an input stream.
  
  @param charset the charset used to read the input stream
  @return the inputstream as a string