code: String readInputStreamAsEncodedString(InputStream inputStream, HttpURLConnection connection) throws IOException {
          if (inputStream == null) {
              return null;
          }
  
          BufferedReader reader = null;
          try {
              String responseEncoding = getResponseEncoding(connection);
              if (izGzipped(connection)) {
                  inputStream = new GZIPInputStream(inputStream);
              }
              final InputStreamReader in = responseEncoding != null ? new InputStreamReader(inputStream, responseEncoding)
                      : new InputStreamReader(inputStream, CHARSET_UTF_8);
              reader = new BufferedReader(in);
              StringBuilder sb = new StringBuilder();
              for (String line; (line = reader.readLine()) != null; ) {
                  sb.append(line);
              }
              return sb.toString();
          } finally {
              inputStream.close();
              if (reader != null) {
                  try { reader.close(); } catch (IOException ignore) { }
              }
          }
      }
docs: <p>
  Reads an InputStream as a String allowing for different encoding types. This closes the stream at the end.
  </p>
  
  @param inputStream      The input stream
  @param connection     The HTTP connection object
  @return A String representation of the input stream
  @throws IOException If something goes wrong