1489N/A/*
2362N/A * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
1489N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1489N/A *
1489N/A * This code is free software; you can redistribute it and/or modify it
1489N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1489N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1489N/A *
1489N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1489N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1489N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1489N/A * version 2 for more details (a copy is included in the LICENSE file that
1489N/A * accompanied this code).
1489N/A *
1489N/A * You should have received a copy of the GNU General Public License version
1489N/A * 2 along with this work; if not, write to the Free Software Foundation,
1489N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1489N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1489N/A */
1489N/A
1489N/Apackage sun.net.util;
1489N/A
1489N/Aimport java.net.URL;
1489N/A
1489N/A/**
1489N/A * URL Utility class.
1489N/A */
1489N/Apublic class URLUtil {
1489N/A /**
1489N/A * Returns a string form of the url suitable for use as a key in HashMap/Sets.
1489N/A *
1489N/A * The string form should be behave in the same manner as the URL when
1489N/A * compared for equality in a HashMap/Set, except that no nameservice
1489N/A * lookup is done on the hostname (only string comparison), and the fragment
1489N/A * is not considered.
1489N/A *
1489N/A * @see java.net.URLStreamHandler.sameFile(java.net.URL)
1489N/A */
1489N/A public static String urlNoFragString(URL url) {
1489N/A StringBuilder strForm = new StringBuilder();
1489N/A
1489N/A String protocol = url.getProtocol();
1489N/A if (protocol != null) {
1489N/A /* protocol is compared case-insensitive, so convert to lowercase */
1489N/A protocol = protocol.toLowerCase();
1489N/A strForm.append(protocol);
1489N/A strForm.append("://");
1489N/A }
1489N/A
1489N/A String host = url.getHost();
1489N/A if (host != null) {
1489N/A /* host is compared case-insensitive, so convert to lowercase */
1489N/A host = host.toLowerCase();
1489N/A strForm.append(host);
1489N/A
1489N/A int port = url.getPort();
1489N/A if (port == -1) {
1489N/A /* if no port is specificed then use the protocols
1489N/A * default, if there is one */
1489N/A port = url.getDefaultPort();
1489N/A }
1489N/A if (port != -1) {
1489N/A strForm.append(":").append(port);
1489N/A }
1489N/A }
1489N/A
1489N/A String file = url.getFile();
1489N/A if (file != null) {
1489N/A strForm.append(file);
1489N/A }
1489N/A
1489N/A return strForm.toString();
1489N/A }
1489N/A}
1489N/A