2362N/A * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/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 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 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 0N/A * A Uri object represents an absolute Uniform Resource Identifier 0N/A * (URI) as defined by RFC 2396 and updated by RFC 2373 and RFC 2732. 0N/A * The most commonly used form of URI is the Uniform Resource Locator (URL). 0N/A * <p> The java.net.URL class cannot be used to parse URIs since it 0N/A * requires the installation of URL stream handlers that may not be 0N/A * available. The hack of getting around this by temporarily 0N/A * replacing the scheme part of a URI is not appropriate here: JNDI 0N/A * service providers must work on older Java platforms, and we want 0N/A * new features and bug fixes that are not available in old versions 0N/A * <p> It may be appropriate to drop this code in favor of the 0N/A * java.net.URI class. The changes would need to be written so as to 0N/A * still run on pre-1.4 platforms not containing that class. 0N/A * <p> The format of an absolute URI (see the RFCs mentioned above) is: 0N/A * <p><blockquote><pre> 0N/A * absoluteURI = scheme ":" ( hier_part | opaque_part ) 0N/A * scheme = alpha *( alpha | digit | "+" | "-" | "." ) 0N/A * hier_part = ( net_path | abs_path ) [ "?" query ] 0N/A * opaque_part = uric_no_slash *uric 0N/A * net_path = "//" authority [ abs_path ] 0N/A * abs_path = "/" path_segments 0N/A * authority = server | reg_name 0N/A * reg_name = 1*( unreserved | escaped | "$" | "," | 0N/A * ";" | ":" | "@" | "&" | "=" | "+" ) 0N/A * server = [ [ userinfo "@" ] hostport ] 0N/A * userinfo = *( unreserved | escaped | 0N/A * ";" | ":" | "&" | "=" | "+" | "$" | "," ) 0N/A * hostport = host [ ":" port ] 0N/A * host = hostname | IPv4address | IPv6reference 0N/A * IPv6reference = "[" IPv6address "]" 0N/A * IPv6address = hexpart [ ":" IPv4address ] 0N/A * IPv4address = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit 0N/A * hexpart = hexseq | hexseq "::" [ hexseq ] | "::" [ hexseq ] 0N/A * hexseq = hex4 *( ":" hex4) 0N/A * path = [ abs_path | opaque_part ] 0N/A * path_segments = segment *( "/" segment ) 0N/A * segment = *pchar *( ";" param ) 0N/A * pchar = unreserved | escaped | 0N/A * ":" | "@" | "&" | "=" | "+" | "$" | "," 0N/A * uric = reserved | unreserved | escaped 0N/A * uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" | 0N/A * "&" | "=" | "+" | "$" | "," 0N/A * reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | 0N/A * "$" | "," | "[" | "]" 0N/A * unreserved = alphanum | mark 0N/A * mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")" 0N/A * escaped = "%" hex hex 0N/A * unwise = "{" | "}" | "|" | "\" | "^" | "`" 0N/A * </pre></blockquote> 0N/A * <p> Currently URIs containing <tt>userinfo</tt> or <tt>reg_name</tt> 0N/A * are not supported. 0N/A * The <tt>opaque_part</tt> of a non-hierarchical URI is treated as if 0N/A * if were a <tt>path</tt> without a leading slash. 0N/A * Creates a Uri object given a URI string. 0N/A * Creates an uninitialized Uri object. The init() method must 0N/A * be called before any other Uri methods. 0N/A * Initializes a Uri object given a URI string. 0N/A * This method must be called exactly once, and before any other Uri 0N/A * Returns the URI's scheme. 0N/A * Returns the host from the URI's authority part, or null 0N/A * if no host is provided. If the host is an IPv6 literal, the 0N/A * delimiting brackets are part of the returned value (see 0N/A * {@link java.net.URI#getHost}). 0N/A * Returns the port from the URI's authority part, or -1 if 0N/A * no port is provided. 0N/A * Returns the URI's path. The path is never null. Note that a 0N/A * slash following the authority part (or the scheme if there is 0N/A * no authority part) is part of the path. For example, the path 0N/A * Returns the URI's query part, or null if no query is provided. 0N/A * Note that a query always begins with a leading "?". 0N/A * Returns the URI as a string. 0N/A * Parses a URI string and sets this object's fields accordingly. 0N/A int i;
// index into URI 0N/A i++;
// skip past ":" 0N/A i +=
2;
// skip past "//" 0N/A }
else {
// at host name or IPv4 0N/A i++;
// skip past ":" 0N/A public static void main(String args[]) throws MalformedURLException { 0N/A for (int i = 0; i < args.length; i++) { 0N/A Uri uri = new Uri(args[i]); 0N/A String h = (uri.getHost() != null) ? uri.getHost() : ""; 0N/A String p = (uri.getPort() != -1) ? (":" + uri.getPort()) : ""; 0N/A String a = uri.hasAuthority ? ("//" + h + p) : ""; 0N/A String q = (uri.getQuery() != null) ? uri.getQuery() : ""; 0N/A String str = uri.getScheme() + ":" + a + uri.getPath() + q; 0N/A if (! uri.toString().equals(str)) { 0N/A System.out.println(str); 0N/A System.out.println(h);