Java Utililty Methods URL Build

List of utility methods to do URL Build

Description

The list of methods to do URL Build are organized into topic(s).

Method

StringbuildUrl(String[] indexNames, String[] types, String operationOrId)
build Url
StringBuilder urlBuilder = new StringBuilder();
if (indexNames != null && indexNames.length > 0) {
    urlBuilder.append("/").append(String.join(",", indexNames));
if (types != null && types.length > 0) {
    urlBuilder.append("/").append(String.join(",", types));
if (operationOrId != null) {
...
StringbuildUrlAsString(String scheme, String host, int port, String path)
Build a fully qualified URL from the pieces provided.
if ((scheme == null) || scheme.equals("") || (host == null) || host.equals("") || (port == 0)) {
    throw new IllegalArgumentException("Cannot build a URL using following scheme: " + scheme + " host: "
            + host + " port: " + port + " path: " + path);
StringBuilder url = new StringBuilder(200);
url.append(scheme).append("://").append(host);
if ((scheme.equalsIgnoreCase("http") && (port != 80))
        || (scheme.equalsIgnoreCase("https") && (port != 443))) {
...
StringbuildURLForParams(String... urlParams)
Returns a URL created from the given params
String url = "/";
for (String param : urlParams) {
    url += param + "/";
return url;
StringbuildURLForParamsWithPrefix(String prefix, String... urlParams)
Returns a URL created from the given params and with the given prefix
String url = "/" + prefix + buildURLForParams(urlParams);
return url;
StringbuildURLForPath(String[] _path)
build URL For Path
if (_path == null)
    return null;
int len = _path.length;
if (len == 0)
    return "";
StringBuilder url = new StringBuilder(len * 16);
for (int i = 0; i < len; i++) {
    if (i != 0)
...
StringbuildUrlFromParts(String... parts)
build Url From Parts
boolean isFirst = true;
String url = "";
for (String part : parts) {
    while (part.endsWith("/")) {
        part = part.substring(0, part.length() - 1);
    while (part.startsWith("/")) {
        part = part.substring(1, part.length());
...
StringbuildUrlWithFilter(String url, String[] filterArrayString)
build Url With Filter
StringBuilder sb = new StringBuilder();
int length = filterArrayString.length;
int count = 0;
for (String filterString : filterArrayString) {
    sb.append(filterString);
    count++;
    if (length != count) {
        sb.append("&");
...
StringqueryString(final Map> params)
Encode URL parameters as a query string.
final StringBuilder builder = new StringBuilder();
if (params != null && params.size() > 0) {
    for (final Iterator<String> it = params.keySet().iterator(); it.hasNext();) {
        final String key = it.next();
        final List<String> values = params.get(key);
        for (final String value : values) {
            try {
                builder.append(key + "=" + URLEncoder.encode(value, "UTF-8") + "&");
...
StringqueryString(final Map values)
Convert a Map to a query string.
final StringBuilder sbuf = new StringBuilder();
String separator = "";
for (final Map.Entry<String, Object> entry : values.entrySet()) {
    final Object entryValue = entry.getValue();
    if (entryValue instanceof Object[]) {
        for (final Object value : (Object[]) entryValue) {
            appendParam(sbuf, separator, entry.getKey(), value);
            separator = "&";
...
StringqueryStringFromMap(Map map)
query String From Map
StringBuilder encodedData = new StringBuilder();
Iterator<Map.Entry<String, String>> mapIterator = map.entrySet().iterator();
while (mapIterator.hasNext()) {
    Map.Entry<String, String> entry = mapIterator.next();
    if (mapIterator.hasNext()) {
        encodedData.append(String.format("%s&", urlEncodeEntry(entry)));
    } else {
        encodedData.append(urlEncodeEntry(entry));
...