Java Utililty Methods Path to URL

List of utility methods to do Path to URL

Description

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

Method

StringfileToURIString(File file)
file To URI String
return file.getAbsoluteFile().toURI().toString();
URIgetUri(String baseApiUrl, String path)
Gets the absolute URL to use to invoke a rest API at a given path.
if (baseApiUrl.endsWith("/")) {
    baseApiUrl = baseApiUrl.substring(0, baseApiUrl.length() - 1);
if (path == null) {
    return new URI(baseApiUrl);
} else {
    return new URI(baseApiUrl + path);
String[]getUriNormalizedContainerAndPathWithoutSlash(String stringUriValue, String containerUrl, boolean normalizeUrlMode, boolean matchBaseUrlMode)
TODO replace by merely using URI to parse !
String uriBaseUrl = null;
String urlPathWithoutSlash = null;
if (normalizeUrlMode) {
    URI uriValue = new URI(stringUriValue).normalize(); 
    if (uriValue.isAbsolute()) {
        if (!allowedProtocolSet.contains(uriValue.getScheme())) {
            throw new MalformedURLException(
                    "Datacore URIs should be HTTP(S) but is " + uriValue.getScheme());
...
URLgetURL(String aPath)
Returns a URL for given path.
try {
    return getFile(aPath).toURI().toURL();
} catch (Exception e) {
    throw new RuntimeException(e);
StringgetUrl(String baseUrl, String absPath)
get Url
URI baseUri = new URI(baseUrl);
URI absUri = baseUri.resolve(absPath);
return absUri.toString();
URLgetURL(String host, int port, String path, boolean isHTTPS)
get URL
String myUrl = isHTTPS ? "https" : "http";
myUrl += "://" + host + ":" + port + path;
return new URL(myUrl);
URLgetUrl(String inPath)
get Url
return new URL(ClassLoader.getSystemResource("") + inPath);
StringgetUrl(String ip, String port, String servicePath, String serviceName, String... args)
get Url
StringBuilder params = new StringBuilder();
params.append("http://");
params.append(ip);
params.append(":");
params.append(port);
params.append(servicePath);
params.append(serviceName);
for (String arg : args) {
...
URLgetURL(String path)
get URL
class ClassOnCurrentClassLoader {
;
Object c = new ClassOnCurrentClassLoader();
return c.getClass().getResource(path); 
URLgetURL(String path)
Convert a network path to a URL
if (path == null)
    return null;
try {
    return new URL(path);
} catch (MalformedURLException e) {
    try {
        return new File(path).toURI().toURL();
    } catch (MalformedURLException e2) {
...