code: public static String encodeURI(String string) throws UnsupportedEncodingException {
          if (string == null) {
              return null;
          }
  
          return URLEncoder.encode(string, "UTF-8")
                  .replace("+", "%20")
                  .replace("%21", "!")
                  .replace("%27", "'")
                  .replace("%28", "(")
                  .replace("%29", ")")
                  .replace("%7E", "~");
      }
docs: Duplicate code from OmniFacew project under apache license:
  https://github.com/omnifaces/omnifaces/blob/develop/license.txt
  <p>
  URI-encode the given string using UTF-8. URIs (paths and filenames) have different encoding rules as compared to
  URL query string parameters. {@link URLEncoder} is actually only for www (HTML) form based query string parameter
  values (as used when a webbrowser submits a HTML form). URI encoding has a lot in common with URL encoding, but
  the space has to be %20 and some chars doesn't necessarily need to be encoded.
  @param string The string to be URI-encoded using UTF-8.
  @return The given string, URI-encoded using UTF-8, or <code>null</code> if <code>null</code> was given.
  @throws UnsupportedEncodingException if UTF-8 is not supported