Android URL Parse getNormalizedURLString(String url)

Here you can find the source of getNormalizedURLString(String url)

Description

get Normalized URL String

Parameter

Parameter Description
url a parameter

Declaration


private static String getNormalizedURLString(String url) 

Method Source Code

//package com.java2s;
import java.net.URI;

public class Main {
    /**//from   ww  w.jav  a  2s .c  om
     * 
     * @param url
     * @return
     */
    // ----------------------------------------------------------------------------------
    private static String getNormalizedURLString(String url) {
        if (url != null) {
            try {
                StringBuffer buffer = new StringBuffer();
                URI uri = new URI(url);
                String scheme = uri.getScheme().toLowerCase();
                buffer.append(scheme); // scheme
                buffer.append("://");
                buffer.append(uri.getHost().toLowerCase()); // host
                int port = uri.getPort();
                if (port != -1
                        && ((scheme.compareTo("http") == 0 && port != 80) || (scheme
                                .compareTo("https") == 0 && port != 433))) {
                    buffer.append(":");
                    buffer.append(port); // port
                }
                buffer.append(uri.getPath()); // path

                String result = buffer.toString();
                return result;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return null;
    }
}

Related

  1. parseHttpParamsToHash(String s)
  2. getHost(String url)
  3. getOrigin(String url)
  4. getParentUrl(String url)
  5. getRecentMediaUrl(String tag)
  6. getStringFromUrl(String url)