code: public static boolean isValid(String s) {
      try {
        new URI(UriEncoder.encode(s));
      }
      catch (URISyntaxException e) {
        return false;
      }
      return true;
    }
docs: Tests whether a string is a valid URI reference.
  @param s the String to be tested
  @return true is s is a valid URI reference, false otherwise