code: public static String readTextURI(final URI source, final String encoding,
                                       final String accept, final String acceptLanguage)
              throws XIncludeFatalException, XIncludeResourceException
      {
          try
          {
              final URL url = source.toURL();
              final URLConnection urlConnection = url.openConnection();
              if (null != accept)
              {
                  urlConnection.setRequestProperty(HttpHeaders.ACCEPT, accept);
              }
              if (null != acceptLanguage)
              {
                  urlConnection.setRequestProperty(HttpHeaders.ACCEPT_LANGUAGE, acceptLanguage);
              }
              final InputStream urlInputStream = urlConnection.getInputStream();
              final byte[] inputBytes = ByteStreams.toByteArray(urlInputStream);
              urlInputStream.close();
              final BOMInputStream bomInputStream = new BOMInputStream(new ByteArrayInputStream(inputBytes));
              if (bomInputStream.hasBOM())
              {
                  final Readable reader = new InputStreamReader(new BufferedInputStream(bomInputStream));
                  return CharStreams.toString(reader);
              }
              else
              {
                  final ByteSource supplier = ByteSource.wrap(inputBytes);
                  final Charset charset = (null == encoding) ? EncodingUtils.getCharset(supplier.openBufferedStream()) : Charset.forName(encoding);
                  return CharStreams.toString(new InputStreamReader(supplier.openStream(), charset));
              }
  
          }
          catch (MalformedURLException | UnsupportedEncodingException e)
          {
              throw new XIncludeFatalException(e.getMessage());
          } catch (IOException e)
          {
              throw new XIncludeResourceException(e.getMessage());
          }
      }
docs: Read a text source from the {@link java.net.URI}
  
  @param source the source
  @param encoding the encoding, if encoding is null an analyse of the source will be done to
  find correct encoding
  @param accept the accept
  @param acceptLanguage the accept language
  @return string text readed
  @throws XIncludeFatalException in case of fatal error
  @throws XIncludeResourceException if source is unreadable