Java Utililty Methods URL is Absolute

List of utility methods to do URL is Absolute

Description

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

Method

StringgetAbsoluteUrl(String base_url, String rel_url)
get Absolute Url
URL base = new URL(base_url);
URL abs = new URL(base, rel_url);
return abs.toString();
URLgetAbsoluteURL(String baseUrl, String url)
get Absolute URL
try {
    return new URL(url);
} catch (MalformedURLException e) {
    try {
        return new URL(appendPath(baseUrl, url));
    } catch (MalformedURLException e1) {
        throw e;
StringgetAbsoluteURL(String baseURLString, String relURlString)
get Absolute URL
try {
    URL baseURL = new URL(baseURLString);
    String url = baseURL.getProtocol() + "://" + baseURL.getHost() + ":" + baseURL.getPort()
            + toRelativeURL(relURlString);
    return url;
} catch (IOException e) {
    return "";
StringgetAbsoluteURL(String relativeURL, String baseURL)
get Absolute URL
if (relativeURL.equals("")) {
    return "";
} else {
    URL url;
    try {
        url = new URL(relativeURL);
    } catch (Exception e) {
        try {
...
URLgetAbsoluteURL(String url, URL base)
interprets url w.r.t base and returns the corresponding absolute URL (only if url is indeed a relative URL ; returns the original url otherwise)
URL res = null;
if (url.startsWith("http:") || url.startsWith("file:") || url.startsWith("ftp:")) {
    try {
        res = new URL(url);
        return res;
    } catch (MalformedURLException mue) {
        System.err.println("Error:Utils.getAbsoluteURL():malformed URL: " + url);
        mue.printStackTrace();
...
URLgetAbsoluteUrl(URL baseUrl, String relativeUrl)
get Absolute Url
if (isAbsolute(relativeUrl)) {
    return new URL(relativeUrl);
return new URL(baseUrl, relativeUrl);
StringgetAbsoluteUrlFromFile(final String file)
Converts a file String to a valid URL String.
Example: index.html converts to file://C:/path/to/file/index.html.
if (file == null) {
    throw new IllegalArgumentException("file must not be null");
final URL url = ClassLoader.getSystemResource(file);
if (url == null) {
    throw new NullPointerException("url from file=" + file + " is null");
return url.toString();
...
StringgetAbsoluteUrlPathFromFile(String file)
Removes file name from URL string
String url = getAbsoluteUrlFromFile(file);
return url.substring(0, url.lastIndexOf('/'));
booleanisAbsolute(String uri)
is Absolute
if (isWindowsDrive(uri)) {
    return true;
} else if (hasScheme(uri)) {
    uri = chopScheme(uri);
if (startsWith(uri, LINUX_FILE_SEP) || startsWith(uri, WIN_FILE_SEP) || isWindowsDrive(uri)) {
    return true;
return false;
booleanisAbsolute(String uri)
is Absolute
int colon = uri.indexOf(':');
if (colon < 1)
    return false;
return true;