docs: public static String urlEncode(final String value, final boolean path) {
          if (value == null) {
              return "";
          }
  
          try {
              String encoded = URLEncoder.encode(value, DEFAULT_ENCODING);
  
              Matcher matcher = ENCODED_CHARACTERS_PATTERN.matcher(encoded);
              StringBuffer buffer = new StringBuffer(encoded.length());
  
              while (matcher.find()) {
                  String replacement = matcher.group(0);
  
                  if ("+".equals(replacement)) {
                      replacement = "%20";
                  } else if ("*".equals(replacement)) {
                      replacement = "%2A";
                  } else if ("%7E".equals(replacement)) {
                      replacement = "~";
                  } else if (path && "%2F".equals(replacement)) {
                      replacement = "/";
                  }
  
                  matcher.appendReplacement(buffer, replacement);
              }
  
              matcher.appendTail(buffer);
              return buffer.toString();
  
          } catch (UnsupportedEncodingException ex) {
              throw new RuntimeException(ex);
          }
      }