Java Utililty Methods URL Normalize

List of utility methods to do URL Normalize

Description

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

Method

StringnormalizeUrl(String url)
Normalises URL according to section 3 of Oauth 2 Draft 23.
if (url != null && !url.isEmpty()) {
    int fragmentPos = url.indexOf("#");
    if (fragmentPos > -1) {
        return url.substring(0, fragmentPos);
return url;
StringnormalizeUrl(String url)
normalize Url
int questionMarkIndex = url.indexOf('?');
if (questionMarkIndex > -1) {
    url = url.substring(0, questionMarkIndex);
int forwardSlashIndex = url.indexOf('/', 8);
if (forwardSlashIndex > -1) {
    int colonIndex = url.lastIndexOf(':', forwardSlashIndex);
    if (colonIndex > -1) {
...
StringNormalizeURL(String URL)
Normalize URL
URI uri;
try {
    uri = new URI(URL);
} catch (Exception e) {
    return URL.trim();
String host = uri.getHost();
String scheme = uri.getScheme();
...
StringnormalizeUrl(String url)
normalize Url
return url.toLowerCase().replaceAll(REGEX_URL1, REGEX_URL2);
StringnormalizeUrl(String url)
Normalizes URL according to RFC 5849, paragraph 3.4.1.2.
URI uri = new URI(url);
String scheme = uri.getScheme().toLowerCase();
String authority = uri.getAuthority().toLowerCase();
int port = uri.getPort();
StringBuilder sb = new StringBuilder();
sb.append(scheme).append("://").append(authority);
if (port != -1 && (("http".equals(scheme) && 80 != port) || ("https".equals(scheme) && 443 != port))) {
    sb.append(":").append(port);
...
StringnormalizeUrl(String url)
normalize Url
if (url == null)
    return null;
return url.replaceAll("([^:]/)/{2,}", "$1/");
StringnormalizeUrl(String url)
normalize Url
URI uri = new URI(url);
String scheme = uri.getScheme().toLowerCase();
String authority = uri.getAuthority().toLowerCase();
boolean dropPort = ((scheme.equals("http")) && (uri.getPort() == 80))
        || ((scheme.equals("https")) && (uri.getPort() == 443));
if (dropPort) {
    int index = authority.lastIndexOf(":");
    if (index >= 0) {
...
StringnormalizeUrl(String url)
This methdo attempts to remove duplicate consecutive forward slashes from the given url.
if (url == null)
    return null;
return url.replaceAll("([^:]/)/{2,}", "$1/");
URLnormalizeURL(URL codebase)
Normalizes URLs to standard ones, eliminating pathname symbols.
if (codebase != null && "file".equals(codebase.getProtocol())) {
    try {
        if (codebase.getHost().length() == 0) {
            String path = codebase.getFile();
            if (path.length() == 0) {
                path = "*";
            return filePathToURI(new File(path).getAbsolutePath()).normalize().toURL();
...
URLnormalizeUrl(URL url)
normalize Url
URI uri = URI.create(url.toString());
return uri.normalize().toURL();