Java URL Normalize normalizeURL(URL url)

Here you can find the source of normalizeURL(URL url)

Description

normalize URL

License

Open Source License

Declaration

public static URL normalizeURL(URL url) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 IBM Corporation and others 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * /*from  w w w.  j  av a  2s  .c om*/
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.net.MalformedURLException;

import java.net.URL;

public class Main {
    public static URL normalizeURL(URL url) {
        if (url == null)
            return null;

        String urlString = url.toString();
        if (urlString.endsWith("/")) {
            urlString = urlString.substring(0, urlString.length() - 1);
        }

        try {
            return new URL(urlString);
        } catch (MalformedURLException e) {
            return null;
        }
    }
}

Related

  1. normalizeUrl(String url)
  2. normalizeUrl(String url)
  3. normalizeURL(URL codebase)
  4. normalizeUrl(URL url)
  5. normalizeUrl(URL url)
  6. normalizeUrl(URL url)
  7. normalizeUrl(URL url)
  8. normalizeURL(URL url)
  9. normalizeUrlStr(String urlStr)