Java Utililty Methods URL Create

List of utility methods to do URL Create

Description

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

Method

URLconcaturl(final URL p_base, final String p_string)
concats an URL with a path
return new URL(p_base.toString() + p_string).toURI().normalize().toURL();
URLconstructURL(URL base, String url, boolean stripRef)
Construct a URL from its basic parts.
URL result = new URL(base, url);
String file = result.getFile();
String protocol = result.getProtocol();
String host = result.getHost();
int port = result.getPort();
String ref = result.getRef();
StringBuilder sb = new StringBuilder(file);
int index = sb.indexOf(" ");
...
StringconstructURLQueryString(Map urlParameters)
This method is the opposite for extractURLParameters(String url).
if (urlParameters != null) {
    StringBuilder queryString = new StringBuilder();
    for (Map.Entry<String, String> parameter : urlParameters.entrySet()) {
        if (queryString.length() > 0)
            queryString.append("&"); 
        queryString.append(urlEncodeQuery(parameter.getKey()) + "=" + urlEncodeQuery(parameter.getValue()));
    return (queryString.toString());
...
StringconstructURLString(Map parameters)
Expand the map of parameters to construct a URL string
StringBuffer url = new StringBuffer();
boolean first = true;
for (Map.Entry<String, String> entry : parameters.entrySet()) {
    try {
        if ((entry.getValue() == null) || (entry.getKey() == null)) {
            continue;
        if (entry.getValue().length() == 0) {
...
URLconvertToURL(String host)
Convert a path to a url.
try {
    return new URL(host);
} catch (Throwable e) {
    final String error = "Unable to convert a supplied host spec to a url: " + host;
    throw new IllegalArgumentException(error);
URLconvertToURL(String url)
convert To URL
if (url != null) {
    return new URL(url);
} else {
    throw new MalformedURLException("URL is not valid");
URL[]convertToUrl(String[] paths)
Convert string paths into URL class paths.
ArrayList<URL> list = new ArrayList<URL>();
for (int i = 0; i < paths.length; i++) {
    URL url = convertToUrl(paths[i]);
    if (url != null) {
        list.add(url);
return list.toArray(new URL[list.size()]);
...
URL[]convertToURLs(String[] hosts)
Convert a set of host path statements to formal urls.
ArrayList list = new ArrayList();
for (int i = 0; i < hosts.length; i++) {
    URL url = convertToURL(hosts[i]);
    if (url != null)
        list.add(url);
return (URL[]) list.toArray(new URL[0]);
URLcreateURL(final String address)
create URL
try {
    return new URL(address);
} catch (final MalformedURLException e) {
    throw new RuntimeException("Can't create URL object for: " + address, e);
StringcreateURL(final String protocol, final String userInfo, final String host, final int port, final String path, final String query, final String ref)
create URL
final StringBuilder sb = new StringBuilder();
sb.append(protocol);
sb.append("://");
if (userInfo != null) {
    sb.append(userInfo);
    sb.append("@");
sb.append(host);
...