Here you can find the source of normalize(URL u)
Parameter | Description |
---|
public static URL normalize(URL u)
//package com.java2s; import java.lang.reflect.Method; import java.lang.reflect.InvocationTargetException; import java.net.MalformedURLException; import java.net.URL; public class Main { static Method url_defport; /**//from w ww. j a va2s. c om * normalize an URL, * @param u, the URL to normalize * @return a new URL, the normalized version of the parameter, or * the u URL, if something failed in the process */ public static URL normalize(URL u) { String proto = u.getProtocol().toLowerCase(); String host = u.getHost().toLowerCase(); int port = u.getPort(); if (port != -1) { if (url_defport != null) { try { int udp; udp = ((Integer) url_defport.invoke(u, (Object[]) null)).intValue(); // we have the default, skip the port part if (udp == port) { port = -1; } } catch (InvocationTargetException ex) { } catch (IllegalAccessException iex) { } } else { switch (port) { case 21: if (proto.equals("ftp")) { port = -1; } break; case 80: if (proto.equals("http")) { port = -1; } break; case 443: if (proto.equals("https")) { port = -1; } break; } } } try { URL _nu; if (port == -1) { _nu = new URL(proto, host, u.getFile()); } else { _nu = new URL(proto, host, port, u.getFile()); } return _nu; } catch (MalformedURLException ex) { } return u; } }