Java URL Create concatUrl(final URL baseUrl, final String extraPath)

Here you can find the source of concatUrl(final URL baseUrl, final String extraPath)

Description

concat Url

License

Open Source License

Declaration

public static URL concatUrl(final URL baseUrl, final String extraPath) 

Method Source Code

//package com.java2s;

import java.net.URI;
import java.net.URL;

public class Main {
    public static URL concatUrl(final URL baseUrl, final String extraPath) {
        try {//  w  w  w. j  a v a  2  s. co  m
            URI uri = baseUrl.toURI();
            String newPath = uri.getPath() + (uri.getPath().endsWith("/") ? "" : "/") + extraPath;
            URI newUri = uri.resolve(newPath);
            return newUri.toURL();
        } catch (Exception e) {
            throw new RuntimeException("Can't add extra path " + extraPath + " to url " + baseUrl, e);
        }
    }
}

Related

  1. buildUrlsList(final String domain, final String... paths)
  2. buildURLString(Iterable elements, String joiner)
  3. concatenate(URL server, String address)
  4. concatenateURL(final URL url, final String query)
  5. concatenateURL(URL url, String query)
  6. concaturl(final URL p_base, final String p_string)
  7. constructURL(URL base, String url, boolean stripRef)
  8. constructURLQueryString(Map urlParameters)
  9. constructURLString(Map parameters)