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

URLbuildURL(String host, String path, Map params)
build URL
StringBuilder url = new StringBuilder();
url.append(host);
if (!host.endsWith("/") && !path.startsWith("/"))
    url.append("/");
url.append(path);
if (params != null && params.keySet().size() > 0) {
    url.append("?");
    url.append(buildQueryString(params));
...
URLbuildURL(String id)
build URL
try {
    return new URL(TRACKER_URL_PREFIX + id);
} catch (MalformedURLException e) {
    throw new IllegalStateException(e);
StringbuildUrl(String repositoryUrl, String resourceUrl)
build Url
int idx = repositoryUrl.indexOf("://");
if (idx < 0) {
    return repositoryUrl + resourceUrl;
String protocol = repositoryUrl.substring(0, idx);
protocol = normalizeProtocol(protocol);
int authorityIdx = idx + 3;
String authority;
...
URLbuildURL(String spec)
build URL
assert (spec != null);
final boolean isFile = spec.startsWith("file:");
try {
    if (isFile) {
        final File file = new File(spec.substring(5));
        return adjustTrailingSlash(file.toURL(), file.isDirectory());
    return new URL(spec);
...
URLbuildURL(String spec)
build URL
if (spec == null)
    throw new NullPointerException("URL spec is null."); 
if (spec.startsWith("file:")) { 
    File file = new File(spec.substring(5));
    if (file.isAbsolute())
        return file.toURL();
return new URL(spec);
...
URLbuildURL(String spec, boolean trailingSlash)
Builds a URL with the given specification
if (spec == null)
    return null;
boolean isFile = spec.startsWith("file:"); 
try {
    if (isFile)
        return adjustTrailingSlash(new File(spec.substring(5)).toURL(), trailingSlash);
    return new URL(spec);
} catch (MalformedURLException e) {
...
URLbuildURL(String url)
Builds URL object with the specified URL string.
try {
    return new URL(url);
} catch (MalformedURLException e) {
    throw new IllegalArgumentException(e);
URLbuildURL(String url)
Construct the URL based on the String
if (url == null)
    throw new MalformedURLException();
url = convertBackSlashes(url);
final String filename = extractFileName(url);
if (filename != null) {
    return new File(url).toURI().toURL();
return new URL(url);
...
URIbuildUrl(String url)
Construct simple URL
try {
    return new URI(url);
} catch (URISyntaxException ex) {
    throw new Error("Failed to build URL", ex);
StringbuildUrl(String url, HashMap params)
build Url
StringBuilder urlString = new StringBuilder(url);
if (params.isEmpty()) {
    return urlString.toString();
urlString.append("?");
Iterator<Entry<String, String>> it = params.entrySet().iterator();
while (it.hasNext()) {
    Entry<String, String> entry = it.next();
...