1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/emul/src/main/java/java/lang/ClassFormatError.java Tue Oct 30 09:14:17 2012 +0100
1.3 @@ -0,0 +1,56 @@
1.4 +/*
1.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.lang;
1.30 +
1.31 +/**
1.32 + * Thrown when the Java Virtual Machine attempts to read a class
1.33 + * file and determines that the file is malformed or otherwise cannot
1.34 + * be interpreted as a class file.
1.35 + *
1.36 + * @author unascribed
1.37 + * @since JDK1.0
1.38 + */
1.39 +public
1.40 +class ClassFormatError extends LinkageError {
1.41 + private static final long serialVersionUID = -8420114879011949195L;
1.42 +
1.43 + /**
1.44 + * Constructs a <code>ClassFormatError</code> with no detail message.
1.45 + */
1.46 + public ClassFormatError() {
1.47 + super();
1.48 + }
1.49 +
1.50 + /**
1.51 + * Constructs a <code>ClassFormatError</code> with the specified
1.52 + * detail message.
1.53 + *
1.54 + * @param s the detail message.
1.55 + */
1.56 + public ClassFormatError(String s) {
1.57 + super(s);
1.58 + }
1.59 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/src/main/java/java/lang/LinkageError.java Tue Oct 30 09:14:17 2012 +0100
2.3 @@ -0,0 +1,69 @@
2.4 +/*
2.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.7 + *
2.8 + * This code is free software; you can redistribute it and/or modify it
2.9 + * under the terms of the GNU General Public License version 2 only, as
2.10 + * published by the Free Software Foundation. Oracle designates this
2.11 + * particular file as subject to the "Classpath" exception as provided
2.12 + * by Oracle in the LICENSE file that accompanied this code.
2.13 + *
2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2.17 + * version 2 for more details (a copy is included in the LICENSE file that
2.18 + * accompanied this code).
2.19 + *
2.20 + * You should have received a copy of the GNU General Public License version
2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2.23 + *
2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2.25 + * or visit www.oracle.com if you need additional information or have any
2.26 + * questions.
2.27 + */
2.28 +
2.29 +package java.lang;
2.30 +
2.31 +/**
2.32 + * Subclasses of {@code LinkageError} indicate that a class has
2.33 + * some dependency on another class; however, the latter class has
2.34 + * incompatibly changed after the compilation of the former class.
2.35 + *
2.36 + *
2.37 + * @author Frank Yellin
2.38 + * @since JDK1.0
2.39 + */
2.40 +public
2.41 +class LinkageError extends Error {
2.42 + private static final long serialVersionUID = 3579600108157160122L;
2.43 +
2.44 + /**
2.45 + * Constructs a {@code LinkageError} with no detail message.
2.46 + */
2.47 + public LinkageError() {
2.48 + super();
2.49 + }
2.50 +
2.51 + /**
2.52 + * Constructs a {@code LinkageError} with the specified detail
2.53 + * message.
2.54 + *
2.55 + * @param s the detail message.
2.56 + */
2.57 + public LinkageError(String s) {
2.58 + super(s);
2.59 + }
2.60 +
2.61 + /**
2.62 + * Constructs a {@code LinkageError} with the specified detail
2.63 + * message and cause.
2.64 + *
2.65 + * @param s the detail message.
2.66 + * @param cause the cause, may be {@code null}
2.67 + * @since 1.7
2.68 + */
2.69 + public LinkageError(String s, Throwable cause) {
2.70 + super(s, cause);
2.71 + }
2.72 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/emul/src/main/java/java/lang/SecurityException.java Tue Oct 30 09:14:17 2012 +0100
3.3 @@ -0,0 +1,84 @@
3.4 +/*
3.5 + * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3.7 + *
3.8 + * This code is free software; you can redistribute it and/or modify it
3.9 + * under the terms of the GNU General Public License version 2 only, as
3.10 + * published by the Free Software Foundation. Oracle designates this
3.11 + * particular file as subject to the "Classpath" exception as provided
3.12 + * by Oracle in the LICENSE file that accompanied this code.
3.13 + *
3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3.17 + * version 2 for more details (a copy is included in the LICENSE file that
3.18 + * accompanied this code).
3.19 + *
3.20 + * You should have received a copy of the GNU General Public License version
3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3.23 + *
3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3.25 + * or visit www.oracle.com if you need additional information or have any
3.26 + * questions.
3.27 + */
3.28 +package java.lang;
3.29 +
3.30 +/**
3.31 + * Thrown by the security manager to indicate a security violation.
3.32 + *
3.33 + * @author unascribed
3.34 + * @see java.lang.SecurityManager
3.35 + * @since JDK1.0
3.36 + */
3.37 +public class SecurityException extends RuntimeException {
3.38 +
3.39 + private static final long serialVersionUID = 6878364983674394167L;
3.40 +
3.41 + /**
3.42 + * Constructs a <code>SecurityException</code> with no detail message.
3.43 + */
3.44 + public SecurityException() {
3.45 + super();
3.46 + }
3.47 +
3.48 + /**
3.49 + * Constructs a <code>SecurityException</code> with the specified
3.50 + * detail message.
3.51 + *
3.52 + * @param s the detail message.
3.53 + */
3.54 + public SecurityException(String s) {
3.55 + super(s);
3.56 + }
3.57 +
3.58 + /**
3.59 + * Creates a <code>SecurityException</code> with the specified
3.60 + * detail message and cause.
3.61 + *
3.62 + * @param message the detail message (which is saved for later retrieval
3.63 + * by the {@link #getMessage()} method).
3.64 + * @param cause the cause (which is saved for later retrieval by the
3.65 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
3.66 + * and indicates that the cause is nonexistent or unknown.)
3.67 + * @since 1.5
3.68 + */
3.69 + public SecurityException(String message, Throwable cause) {
3.70 + super(message, cause);
3.71 + }
3.72 +
3.73 + /**
3.74 + * Creates a <code>SecurityException</code> with the specified cause
3.75 + * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
3.76 + * (which typically contains the class and detail message of
3.77 + * <tt>cause</tt>).
3.78 + *
3.79 + * @param cause the cause (which is saved for later retrieval by the
3.80 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
3.81 + * and indicates that the cause is nonexistent or unknown.)
3.82 + * @since 1.5
3.83 + */
3.84 + public SecurityException(Throwable cause) {
3.85 + super(cause);
3.86 + }
3.87 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/emul/src/main/java/java/net/MalformedURLException.java Tue Oct 30 09:14:17 2012 +0100
4.3 @@ -0,0 +1,56 @@
4.4 +/*
4.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 + *
4.8 + * This code is free software; you can redistribute it and/or modify it
4.9 + * under the terms of the GNU General Public License version 2 only, as
4.10 + * published by the Free Software Foundation. Oracle designates this
4.11 + * particular file as subject to the "Classpath" exception as provided
4.12 + * by Oracle in the LICENSE file that accompanied this code.
4.13 + *
4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 + * version 2 for more details (a copy is included in the LICENSE file that
4.18 + * accompanied this code).
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License version
4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 + *
4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.25 + * or visit www.oracle.com if you need additional information or have any
4.26 + * questions.
4.27 + */
4.28 +
4.29 +package java.net;
4.30 +
4.31 +import java.io.IOException;
4.32 +
4.33 +/**
4.34 + * Thrown to indicate that a malformed URL has occurred. Either no
4.35 + * legal protocol could be found in a specification string or the
4.36 + * string could not be parsed.
4.37 + *
4.38 + * @author Arthur van Hoff
4.39 + * @since JDK1.0
4.40 + */
4.41 +public class MalformedURLException extends IOException {
4.42 + private static final long serialVersionUID = -182787522200415866L;
4.43 +
4.44 + /**
4.45 + * Constructs a <code>MalformedURLException</code> with no detail message.
4.46 + */
4.47 + public MalformedURLException() {
4.48 + }
4.49 +
4.50 + /**
4.51 + * Constructs a <code>MalformedURLException</code> with the
4.52 + * specified detail message.
4.53 + *
4.54 + * @param msg the detail message.
4.55 + */
4.56 + public MalformedURLException(String msg) {
4.57 + super(msg);
4.58 + }
4.59 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/emul/src/main/java/java/net/URL.java Tue Oct 30 09:14:17 2012 +0100
5.3 @@ -0,0 +1,1310 @@
5.4 +/*
5.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 + *
5.8 + * This code is free software; you can redistribute it and/or modify it
5.9 + * under the terms of the GNU General Public License version 2 only, as
5.10 + * published by the Free Software Foundation. Oracle designates this
5.11 + * particular file as subject to the "Classpath" exception as provided
5.12 + * by Oracle in the LICENSE file that accompanied this code.
5.13 + *
5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 + * version 2 for more details (a copy is included in the LICENSE file that
5.18 + * accompanied this code).
5.19 + *
5.20 + * You should have received a copy of the GNU General Public License version
5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 + *
5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.25 + * or visit www.oracle.com if you need additional information or have any
5.26 + * questions.
5.27 + */
5.28 +
5.29 +package java.net;
5.30 +
5.31 +import java.io.IOException;
5.32 +import java.io.InputStream;
5.33 +import java.io.OutputStream;
5.34 +import java.util.Hashtable;
5.35 +import java.util.StringTokenizer;
5.36 +import sun.security.util.SecurityConstants;
5.37 +
5.38 +/**
5.39 + * Class <code>URL</code> represents a Uniform Resource
5.40 + * Locator, a pointer to a "resource" on the World
5.41 + * Wide Web. A resource can be something as simple as a file or a
5.42 + * directory, or it can be a reference to a more complicated object,
5.43 + * such as a query to a database or to a search engine. More
5.44 + * information on the types of URLs and their formats can be found at:
5.45 + * <blockquote>
5.46 + * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
5.47 + * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
5.48 + * </blockquote>
5.49 + * <p>
5.50 + * In general, a URL can be broken into several parts. The previous
5.51 + * example of a URL indicates that the protocol to use is
5.52 + * <code>http</code> (HyperText Transfer Protocol) and that the
5.53 + * information resides on a host machine named
5.54 + * <code>www.socs.uts.edu.au</code>. The information on that host
5.55 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
5.56 + * meaning of this name on the host machine is both protocol
5.57 + * dependent and host dependent. The information normally resides in
5.58 + * a file, but it could be generated on the fly. This component of
5.59 + * the URL is called the <i>path</i> component.
5.60 + * <p>
5.61 + * A URL can optionally specify a "port", which is the
5.62 + * port number to which the TCP connection is made on the remote host
5.63 + * machine. If the port is not specified, the default port for
5.64 + * the protocol is used instead. For example, the default port for
5.65 + * <code>http</code> is <code>80</code>. An alternative port could be
5.66 + * specified as:
5.67 + * <blockquote><pre>
5.68 + * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
5.69 + * </pre></blockquote>
5.70 + * <p>
5.71 + * The syntax of <code>URL</code> is defined by <a
5.72 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
5.73 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
5.74 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
5.75 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
5.76 + * also supports scope_ids. The syntax and usage of scope_ids is described
5.77 + * <a href="Inet6Address.html#scoped">here</a>.
5.78 + * <p>
5.79 + * A URL may have appended to it a "fragment", also known
5.80 + * as a "ref" or a "reference". The fragment is indicated by the sharp
5.81 + * sign character "#" followed by more characters. For example,
5.82 + * <blockquote><pre>
5.83 + * http://java.sun.com/index.html#chapter1
5.84 + * </pre></blockquote>
5.85 + * <p>
5.86 + * This fragment is not technically part of the URL. Rather, it
5.87 + * indicates that after the specified resource is retrieved, the
5.88 + * application is specifically interested in that part of the
5.89 + * document that has the tag <code>chapter1</code> attached to it. The
5.90 + * meaning of a tag is resource specific.
5.91 + * <p>
5.92 + * An application can also specify a "relative URL",
5.93 + * which contains only enough information to reach the resource
5.94 + * relative to another URL. Relative URLs are frequently used within
5.95 + * HTML pages. For example, if the contents of the URL:
5.96 + * <blockquote><pre>
5.97 + * http://java.sun.com/index.html
5.98 + * </pre></blockquote>
5.99 + * contained within it the relative URL:
5.100 + * <blockquote><pre>
5.101 + * FAQ.html
5.102 + * </pre></blockquote>
5.103 + * it would be a shorthand for:
5.104 + * <blockquote><pre>
5.105 + * http://java.sun.com/FAQ.html
5.106 + * </pre></blockquote>
5.107 + * <p>
5.108 + * The relative URL need not specify all the components of a URL. If
5.109 + * the protocol, host name, or port number is missing, the value is
5.110 + * inherited from the fully specified URL. The file component must be
5.111 + * specified. The optional fragment is not inherited.
5.112 + * <p>
5.113 + * The URL class does not itself encode or decode any URL components
5.114 + * according to the escaping mechanism defined in RFC2396. It is the
5.115 + * responsibility of the caller to encode any fields, which need to be
5.116 + * escaped prior to calling URL, and also to decode any escaped fields,
5.117 + * that are returned from URL. Furthermore, because URL has no knowledge
5.118 + * of URL escaping, it does not recognise equivalence between the encoded
5.119 + * or decoded form of the same URL. For example, the two URLs:<br>
5.120 + * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
5.121 + * would be considered not equal to each other.
5.122 + * <p>
5.123 + * Note, the {@link java.net.URI} class does perform escaping of its
5.124 + * component fields in certain circumstances. The recommended way
5.125 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
5.126 + * and to convert between these two classes using {@link #toURI()} and
5.127 + * {@link URI#toURL()}.
5.128 + * <p>
5.129 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
5.130 + * used, but only for HTML form encoding, which is not the same
5.131 + * as the encoding scheme defined in RFC2396.
5.132 + *
5.133 + * @author James Gosling
5.134 + * @since JDK1.0
5.135 + */
5.136 +public final class URL implements java.io.Serializable {
5.137 +
5.138 + static final long serialVersionUID = -7627629688361524110L;
5.139 +
5.140 + /**
5.141 + * The property which specifies the package prefix list to be scanned
5.142 + * for protocol handlers. The value of this property (if any) should
5.143 + * be a vertical bar delimited list of package names to search through
5.144 + * for a protocol handler to load. The policy of this class is that
5.145 + * all protocol handlers will be in a class called <protocolname>.Handler,
5.146 + * and each package in the list is examined in turn for a matching
5.147 + * handler. If none are found (or the property is not specified), the
5.148 + * default package prefix, sun.net.www.protocol, is used. The search
5.149 + * proceeds from the first package in the list to the last and stops
5.150 + * when a match is found.
5.151 + */
5.152 + private static final String protocolPathProp = "java.protocol.handler.pkgs";
5.153 +
5.154 + /**
5.155 + * The protocol to use (ftp, http, nntp, ... etc.) .
5.156 + * @serial
5.157 + */
5.158 + private String protocol;
5.159 +
5.160 + /**
5.161 + * The host name to connect to.
5.162 + * @serial
5.163 + */
5.164 + private String host;
5.165 +
5.166 + /**
5.167 + * The protocol port to connect to.
5.168 + * @serial
5.169 + */
5.170 + private int port = -1;
5.171 +
5.172 + /**
5.173 + * The specified file name on that host. <code>file</code> is
5.174 + * defined as <code>path[?query]</code>
5.175 + * @serial
5.176 + */
5.177 + private String file;
5.178 +
5.179 + /**
5.180 + * The query part of this URL.
5.181 + */
5.182 + private transient String query;
5.183 +
5.184 + /**
5.185 + * The authority part of this URL.
5.186 + * @serial
5.187 + */
5.188 + private String authority;
5.189 +
5.190 + /**
5.191 + * The path part of this URL.
5.192 + */
5.193 + private transient String path;
5.194 +
5.195 + /**
5.196 + * The userinfo part of this URL.
5.197 + */
5.198 + private transient String userInfo;
5.199 +
5.200 + /**
5.201 + * # reference.
5.202 + * @serial
5.203 + */
5.204 + private String ref;
5.205 +
5.206 + /**
5.207 + * The host's IP address, used in equals and hashCode.
5.208 + * Computed on demand. An uninitialized or unknown hostAddress is null.
5.209 + */
5.210 + transient InetAddress hostAddress;
5.211 +
5.212 + /**
5.213 + * The URLStreamHandler for this URL.
5.214 + */
5.215 + transient URLStreamHandler handler;
5.216 +
5.217 + /* Our hash code.
5.218 + * @serial
5.219 + */
5.220 + private int hashCode = -1;
5.221 +
5.222 + /**
5.223 + * Creates a <code>URL</code> object from the specified
5.224 + * <code>protocol</code>, <code>host</code>, <code>port</code>
5.225 + * number, and <code>file</code>.<p>
5.226 + *
5.227 + * <code>host</code> can be expressed as a host name or a literal
5.228 + * IP address. If IPv6 literal address is used, it should be
5.229 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
5.230 + * specified by <a
5.231 + * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
5.232 + * However, the literal IPv6 address format defined in <a
5.233 + * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
5.234 + * Version 6 Addressing Architecture</i></a> is also accepted.<p>
5.235 + *
5.236 + * Specifying a <code>port</code> number of <code>-1</code>
5.237 + * indicates that the URL should use the default port for the
5.238 + * protocol.<p>
5.239 + *
5.240 + * If this is the first URL object being created with the specified
5.241 + * protocol, a <i>stream protocol handler</i> object, an instance of
5.242 + * class <code>URLStreamHandler</code>, is created for that protocol:
5.243 + * <ol>
5.244 + * <li>If the application has previously set up an instance of
5.245 + * <code>URLStreamHandlerFactory</code> as the stream handler factory,
5.246 + * then the <code>createURLStreamHandler</code> method of that instance
5.247 + * is called with the protocol string as an argument to create the
5.248 + * stream protocol handler.
5.249 + * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
5.250 + * or if the factory's <code>createURLStreamHandler</code> method
5.251 + * returns <code>null</code>, then the constructor finds the
5.252 + * value of the system property:
5.253 + * <blockquote><pre>
5.254 + * java.protocol.handler.pkgs
5.255 + * </pre></blockquote>
5.256 + * If the value of that system property is not <code>null</code>,
5.257 + * it is interpreted as a list of packages separated by a vertical
5.258 + * slash character '<code>|</code>'. The constructor tries to load
5.259 + * the class named:
5.260 + * <blockquote><pre>
5.261 + * <<i>package</i>>.<<i>protocol</i>>.Handler
5.262 + * </pre></blockquote>
5.263 + * where <<i>package</i>> is replaced by the name of the package
5.264 + * and <<i>protocol</i>> is replaced by the name of the protocol.
5.265 + * If this class does not exist, or if the class exists but it is not
5.266 + * a subclass of <code>URLStreamHandler</code>, then the next package
5.267 + * in the list is tried.
5.268 + * <li>If the previous step fails to find a protocol handler, then the
5.269 + * constructor tries to load from a system default package.
5.270 + * <blockquote><pre>
5.271 + * <<i>system default package</i>>.<<i>protocol</i>>.Handler
5.272 + * </pre></blockquote>
5.273 + * If this class does not exist, or if the class exists but it is not a
5.274 + * subclass of <code>URLStreamHandler</code>, then a
5.275 + * <code>MalformedURLException</code> is thrown.
5.276 + * </ol>
5.277 + *
5.278 + * <p>Protocol handlers for the following protocols are guaranteed
5.279 + * to exist on the search path :-
5.280 + * <blockquote><pre>
5.281 + * http, https, ftp, file, and jar
5.282 + * </pre></blockquote>
5.283 + * Protocol handlers for additional protocols may also be
5.284 + * available.
5.285 + *
5.286 + * <p>No validation of the inputs is performed by this constructor.
5.287 + *
5.288 + * @param protocol the name of the protocol to use.
5.289 + * @param host the name of the host.
5.290 + * @param port the port number on the host.
5.291 + * @param file the file on the host
5.292 + * @exception MalformedURLException if an unknown protocol is specified.
5.293 + * @see java.lang.System#getProperty(java.lang.String)
5.294 + * @see java.net.URL#setURLStreamHandlerFactory(
5.295 + * java.net.URLStreamHandlerFactory)
5.296 + * @see java.net.URLStreamHandler
5.297 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
5.298 + * java.lang.String)
5.299 + */
5.300 + public URL(String protocol, String host, int port, String file)
5.301 + throws MalformedURLException
5.302 + {
5.303 + this(protocol, host, port, file, null);
5.304 + }
5.305 +
5.306 + /**
5.307 + * Creates a URL from the specified <code>protocol</code>
5.308 + * name, <code>host</code> name, and <code>file</code> name. The
5.309 + * default port for the specified protocol is used.
5.310 + * <p>
5.311 + * This method is equivalent to calling the four-argument
5.312 + * constructor with the arguments being <code>protocol</code>,
5.313 + * <code>host</code>, <code>-1</code>, and <code>file</code>.
5.314 + *
5.315 + * No validation of the inputs is performed by this constructor.
5.316 + *
5.317 + * @param protocol the name of the protocol to use.
5.318 + * @param host the name of the host.
5.319 + * @param file the file on the host.
5.320 + * @exception MalformedURLException if an unknown protocol is specified.
5.321 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.322 + * int, java.lang.String)
5.323 + */
5.324 + public URL(String protocol, String host, String file)
5.325 + throws MalformedURLException {
5.326 + this(protocol, host, -1, file);
5.327 + }
5.328 +
5.329 + /**
5.330 + * Creates a <code>URL</code> object from the specified
5.331 + * <code>protocol</code>, <code>host</code>, <code>port</code>
5.332 + * number, <code>file</code>, and <code>handler</code>. Specifying
5.333 + * a <code>port</code> number of <code>-1</code> indicates that
5.334 + * the URL should use the default port for the protocol. Specifying
5.335 + * a <code>handler</code> of <code>null</code> indicates that the URL
5.336 + * should use a default stream handler for the protocol, as outlined
5.337 + * for:
5.338 + * java.net.URL#URL(java.lang.String, java.lang.String, int,
5.339 + * java.lang.String)
5.340 + *
5.341 + * <p>If the handler is not null and there is a security manager,
5.342 + * the security manager's <code>checkPermission</code>
5.343 + * method is called with a
5.344 + * <code>NetPermission("specifyStreamHandler")</code> permission.
5.345 + * This may result in a SecurityException.
5.346 + *
5.347 + * No validation of the inputs is performed by this constructor.
5.348 + *
5.349 + * @param protocol the name of the protocol to use.
5.350 + * @param host the name of the host.
5.351 + * @param port the port number on the host.
5.352 + * @param file the file on the host
5.353 + * @param handler the stream handler for the URL.
5.354 + * @exception MalformedURLException if an unknown protocol is specified.
5.355 + * @exception SecurityException
5.356 + * if a security manager exists and its
5.357 + * <code>checkPermission</code> method doesn't allow
5.358 + * specifying a stream handler explicitly.
5.359 + * @see java.lang.System#getProperty(java.lang.String)
5.360 + * @see java.net.URL#setURLStreamHandlerFactory(
5.361 + * java.net.URLStreamHandlerFactory)
5.362 + * @see java.net.URLStreamHandler
5.363 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
5.364 + * java.lang.String)
5.365 + * @see SecurityManager#checkPermission
5.366 + * @see java.net.NetPermission
5.367 + */
5.368 + public URL(String protocol, String host, int port, String file,
5.369 + URLStreamHandler handler) throws MalformedURLException {
5.370 + if (handler != null) {
5.371 + SecurityManager sm = System.getSecurityManager();
5.372 + if (sm != null) {
5.373 + // check for permission to specify a handler
5.374 + checkSpecifyHandler(sm);
5.375 + }
5.376 + }
5.377 +
5.378 + protocol = protocol.toLowerCase();
5.379 + this.protocol = protocol;
5.380 + if (host != null) {
5.381 +
5.382 + /**
5.383 + * if host is a literal IPv6 address,
5.384 + * we will make it conform to RFC 2732
5.385 + */
5.386 + if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
5.387 + host = "["+host+"]";
5.388 + }
5.389 + this.host = host;
5.390 +
5.391 + if (port < -1) {
5.392 + throw new MalformedURLException("Invalid port number :" +
5.393 + port);
5.394 + }
5.395 + this.port = port;
5.396 + authority = (port == -1) ? host : host + ":" + port;
5.397 + }
5.398 +
5.399 + Parts parts = new Parts(file);
5.400 + path = parts.getPath();
5.401 + query = parts.getQuery();
5.402 +
5.403 + if (query != null) {
5.404 + this.file = path + "?" + query;
5.405 + } else {
5.406 + this.file = path;
5.407 + }
5.408 + ref = parts.getRef();
5.409 +
5.410 + // Note: we don't do validation of the URL here. Too risky to change
5.411 + // right now, but worth considering for future reference. -br
5.412 + if (handler == null &&
5.413 + (handler = getURLStreamHandler(protocol)) == null) {
5.414 + throw new MalformedURLException("unknown protocol: " + protocol);
5.415 + }
5.416 + this.handler = handler;
5.417 + }
5.418 +
5.419 + /**
5.420 + * Creates a <code>URL</code> object from the <code>String</code>
5.421 + * representation.
5.422 + * <p>
5.423 + * This constructor is equivalent to a call to the two-argument
5.424 + * constructor with a <code>null</code> first argument.
5.425 + *
5.426 + * @param spec the <code>String</code> to parse as a URL.
5.427 + * @exception MalformedURLException if no protocol is specified, or an
5.428 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
5.429 + * @see java.net.URL#URL(java.net.URL, java.lang.String)
5.430 + */
5.431 + public URL(String spec) throws MalformedURLException {
5.432 + this(null, spec);
5.433 + }
5.434 +
5.435 + /**
5.436 + * Creates a URL by parsing the given spec within a specified context.
5.437 + *
5.438 + * The new URL is created from the given context URL and the spec
5.439 + * argument as described in
5.440 + * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
5.441 + * <blockquote><pre>
5.442 + * <scheme>://<authority><path>?<query>#<fragment>
5.443 + * </pre></blockquote>
5.444 + * The reference is parsed into the scheme, authority, path, query and
5.445 + * fragment parts. If the path component is empty and the scheme,
5.446 + * authority, and query components are undefined, then the new URL is a
5.447 + * reference to the current document. Otherwise, the fragment and query
5.448 + * parts present in the spec are used in the new URL.
5.449 + * <p>
5.450 + * If the scheme component is defined in the given spec and does not match
5.451 + * the scheme of the context, then the new URL is created as an absolute
5.452 + * URL based on the spec alone. Otherwise the scheme component is inherited
5.453 + * from the context URL.
5.454 + * <p>
5.455 + * If the authority component is present in the spec then the spec is
5.456 + * treated as absolute and the spec authority and path will replace the
5.457 + * context authority and path. If the authority component is absent in the
5.458 + * spec then the authority of the new URL will be inherited from the
5.459 + * context.
5.460 + * <p>
5.461 + * If the spec's path component begins with a slash character
5.462 + * "/" then the
5.463 + * path is treated as absolute and the spec path replaces the context path.
5.464 + * <p>
5.465 + * Otherwise, the path is treated as a relative path and is appended to the
5.466 + * context path, as described in RFC2396. Also, in this case,
5.467 + * the path is canonicalized through the removal of directory
5.468 + * changes made by occurences of ".." and ".".
5.469 + * <p>
5.470 + * For a more detailed description of URL parsing, refer to RFC2396.
5.471 + *
5.472 + * @param context the context in which to parse the specification.
5.473 + * @param spec the <code>String</code> to parse as a URL.
5.474 + * @exception MalformedURLException if no protocol is specified, or an
5.475 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
5.476 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.477 + * int, java.lang.String)
5.478 + * @see java.net.URLStreamHandler
5.479 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
5.480 + * java.lang.String, int, int)
5.481 + */
5.482 + public URL(URL context, String spec) throws MalformedURLException {
5.483 + this(context, spec, null);
5.484 + }
5.485 +
5.486 + /**
5.487 + * Creates a URL by parsing the given spec with the specified handler
5.488 + * within a specified context. If the handler is null, the parsing
5.489 + * occurs as with the two argument constructor.
5.490 + *
5.491 + * @param context the context in which to parse the specification.
5.492 + * @param spec the <code>String</code> to parse as a URL.
5.493 + * @param handler the stream handler for the URL.
5.494 + * @exception MalformedURLException if no protocol is specified, or an
5.495 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
5.496 + * @exception SecurityException
5.497 + * if a security manager exists and its
5.498 + * <code>checkPermission</code> method doesn't allow
5.499 + * specifying a stream handler.
5.500 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.501 + * int, java.lang.String)
5.502 + * @see java.net.URLStreamHandler
5.503 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
5.504 + * java.lang.String, int, int)
5.505 + */
5.506 + public URL(URL context, String spec, URLStreamHandler handler)
5.507 + throws MalformedURLException
5.508 + {
5.509 + String original = spec;
5.510 + int i, limit, c;
5.511 + int start = 0;
5.512 + String newProtocol = null;
5.513 + boolean aRef=false;
5.514 + boolean isRelative = false;
5.515 +
5.516 + // Check for permission to specify a handler
5.517 + if (handler != null) {
5.518 + SecurityManager sm = System.getSecurityManager();
5.519 + if (sm != null) {
5.520 + checkSpecifyHandler(sm);
5.521 + }
5.522 + }
5.523 +
5.524 + try {
5.525 + limit = spec.length();
5.526 + while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
5.527 + limit--; //eliminate trailing whitespace
5.528 + }
5.529 + while ((start < limit) && (spec.charAt(start) <= ' ')) {
5.530 + start++; // eliminate leading whitespace
5.531 + }
5.532 +
5.533 + if (spec.regionMatches(true, start, "url:", 0, 4)) {
5.534 + start += 4;
5.535 + }
5.536 + if (start < spec.length() && spec.charAt(start) == '#') {
5.537 + /* we're assuming this is a ref relative to the context URL.
5.538 + * This means protocols cannot start w/ '#', but we must parse
5.539 + * ref URL's like: "hello:there" w/ a ':' in them.
5.540 + */
5.541 + aRef=true;
5.542 + }
5.543 + for (i = start ; !aRef && (i < limit) &&
5.544 + ((c = spec.charAt(i)) != '/') ; i++) {
5.545 + if (c == ':') {
5.546 +
5.547 + String s = spec.substring(start, i).toLowerCase();
5.548 + if (isValidProtocol(s)) {
5.549 + newProtocol = s;
5.550 + start = i + 1;
5.551 + }
5.552 + break;
5.553 + }
5.554 + }
5.555 +
5.556 + // Only use our context if the protocols match.
5.557 + protocol = newProtocol;
5.558 + if ((context != null) && ((newProtocol == null) ||
5.559 + newProtocol.equalsIgnoreCase(context.protocol))) {
5.560 + // inherit the protocol handler from the context
5.561 + // if not specified to the constructor
5.562 + if (handler == null) {
5.563 + handler = context.handler;
5.564 + }
5.565 +
5.566 + // If the context is a hierarchical URL scheme and the spec
5.567 + // contains a matching scheme then maintain backwards
5.568 + // compatibility and treat it as if the spec didn't contain
5.569 + // the scheme; see 5.2.3 of RFC2396
5.570 + if (context.path != null && context.path.startsWith("/"))
5.571 + newProtocol = null;
5.572 +
5.573 + if (newProtocol == null) {
5.574 + protocol = context.protocol;
5.575 + authority = context.authority;
5.576 + userInfo = context.userInfo;
5.577 + host = context.host;
5.578 + port = context.port;
5.579 + file = context.file;
5.580 + path = context.path;
5.581 + isRelative = true;
5.582 + }
5.583 + }
5.584 +
5.585 + if (protocol == null) {
5.586 + throw new MalformedURLException("no protocol: "+original);
5.587 + }
5.588 +
5.589 + // Get the protocol handler if not specified or the protocol
5.590 + // of the context could not be used
5.591 + if (handler == null &&
5.592 + (handler = getURLStreamHandler(protocol)) == null) {
5.593 + throw new MalformedURLException("unknown protocol: "+protocol);
5.594 + }
5.595 +
5.596 + this.handler = handler;
5.597 +
5.598 + i = spec.indexOf('#', start);
5.599 + if (i >= 0) {
5.600 + ref = spec.substring(i + 1, limit);
5.601 + limit = i;
5.602 + }
5.603 +
5.604 + /*
5.605 + * Handle special case inheritance of query and fragment
5.606 + * implied by RFC2396 section 5.2.2.
5.607 + */
5.608 + if (isRelative && start == limit) {
5.609 + query = context.query;
5.610 + if (ref == null) {
5.611 + ref = context.ref;
5.612 + }
5.613 + }
5.614 +
5.615 + handler.parseURL(this, spec, start, limit);
5.616 +
5.617 + } catch(MalformedURLException e) {
5.618 + throw e;
5.619 + } catch(Exception e) {
5.620 + MalformedURLException exception = new MalformedURLException(e.getMessage());
5.621 + exception.initCause(e);
5.622 + throw exception;
5.623 + }
5.624 + }
5.625 +
5.626 + /*
5.627 + * Returns true if specified string is a valid protocol name.
5.628 + */
5.629 + private boolean isValidProtocol(String protocol) {
5.630 + int len = protocol.length();
5.631 + if (len < 1)
5.632 + return false;
5.633 + char c = protocol.charAt(0);
5.634 + if (!Character.isLetter(c))
5.635 + return false;
5.636 + for (int i = 1; i < len; i++) {
5.637 + c = protocol.charAt(i);
5.638 + if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
5.639 + c != '-') {
5.640 + return false;
5.641 + }
5.642 + }
5.643 + return true;
5.644 + }
5.645 +
5.646 + /*
5.647 + * Checks for permission to specify a stream handler.
5.648 + */
5.649 + private void checkSpecifyHandler(SecurityManager sm) {
5.650 + sm.checkPermission(SecurityConstants.SPECIFY_HANDLER_PERMISSION);
5.651 + }
5.652 +
5.653 + /**
5.654 + * Sets the fields of the URL. This is not a public method so that
5.655 + * only URLStreamHandlers can modify URL fields. URLs are
5.656 + * otherwise constant.
5.657 + *
5.658 + * @param protocol the name of the protocol to use
5.659 + * @param host the name of the host
5.660 + @param port the port number on the host
5.661 + * @param file the file on the host
5.662 + * @param ref the internal reference in the URL
5.663 + */
5.664 + protected void set(String protocol, String host,
5.665 + int port, String file, String ref) {
5.666 + synchronized (this) {
5.667 + this.protocol = protocol;
5.668 + this.host = host;
5.669 + authority = port == -1 ? host : host + ":" + port;
5.670 + this.port = port;
5.671 + this.file = file;
5.672 + this.ref = ref;
5.673 + /* This is very important. We must recompute this after the
5.674 + * URL has been changed. */
5.675 + hashCode = -1;
5.676 + hostAddress = null;
5.677 + int q = file.lastIndexOf('?');
5.678 + if (q != -1) {
5.679 + query = file.substring(q+1);
5.680 + path = file.substring(0, q);
5.681 + } else
5.682 + path = file;
5.683 + }
5.684 + }
5.685 +
5.686 + /**
5.687 + * Sets the specified 8 fields of the URL. This is not a public method so
5.688 + * that only URLStreamHandlers can modify URL fields. URLs are otherwise
5.689 + * constant.
5.690 + *
5.691 + * @param protocol the name of the protocol to use
5.692 + * @param host the name of the host
5.693 + * @param port the port number on the host
5.694 + * @param authority the authority part for the url
5.695 + * @param userInfo the username and password
5.696 + * @param path the file on the host
5.697 + * @param ref the internal reference in the URL
5.698 + * @param query the query part of this URL
5.699 + * @since 1.3
5.700 + */
5.701 + protected void set(String protocol, String host, int port,
5.702 + String authority, String userInfo, String path,
5.703 + String query, String ref) {
5.704 + synchronized (this) {
5.705 + this.protocol = protocol;
5.706 + this.host = host;
5.707 + this.port = port;
5.708 + this.file = query == null ? path : path + "?" + query;
5.709 + this.userInfo = userInfo;
5.710 + this.path = path;
5.711 + this.ref = ref;
5.712 + /* This is very important. We must recompute this after the
5.713 + * URL has been changed. */
5.714 + hashCode = -1;
5.715 + hostAddress = null;
5.716 + this.query = query;
5.717 + this.authority = authority;
5.718 + }
5.719 + }
5.720 +
5.721 + /**
5.722 + * Gets the query part of this <code>URL</code>.
5.723 + *
5.724 + * @return the query part of this <code>URL</code>,
5.725 + * or <CODE>null</CODE> if one does not exist
5.726 + * @since 1.3
5.727 + */
5.728 + public String getQuery() {
5.729 + return query;
5.730 + }
5.731 +
5.732 + /**
5.733 + * Gets the path part of this <code>URL</code>.
5.734 + *
5.735 + * @return the path part of this <code>URL</code>, or an
5.736 + * empty string if one does not exist
5.737 + * @since 1.3
5.738 + */
5.739 + public String getPath() {
5.740 + return path;
5.741 + }
5.742 +
5.743 + /**
5.744 + * Gets the userInfo part of this <code>URL</code>.
5.745 + *
5.746 + * @return the userInfo part of this <code>URL</code>, or
5.747 + * <CODE>null</CODE> if one does not exist
5.748 + * @since 1.3
5.749 + */
5.750 + public String getUserInfo() {
5.751 + return userInfo;
5.752 + }
5.753 +
5.754 + /**
5.755 + * Gets the authority part of this <code>URL</code>.
5.756 + *
5.757 + * @return the authority part of this <code>URL</code>
5.758 + * @since 1.3
5.759 + */
5.760 + public String getAuthority() {
5.761 + return authority;
5.762 + }
5.763 +
5.764 + /**
5.765 + * Gets the port number of this <code>URL</code>.
5.766 + *
5.767 + * @return the port number, or -1 if the port is not set
5.768 + */
5.769 + public int getPort() {
5.770 + return port;
5.771 + }
5.772 +
5.773 + /**
5.774 + * Gets the default port number of the protocol associated
5.775 + * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
5.776 + * for the URL do not define a default port number,
5.777 + * then -1 is returned.
5.778 + *
5.779 + * @return the port number
5.780 + * @since 1.4
5.781 + */
5.782 + public int getDefaultPort() {
5.783 + return handler.getDefaultPort();
5.784 + }
5.785 +
5.786 + /**
5.787 + * Gets the protocol name of this <code>URL</code>.
5.788 + *
5.789 + * @return the protocol of this <code>URL</code>.
5.790 + */
5.791 + public String getProtocol() {
5.792 + return protocol;
5.793 + }
5.794 +
5.795 + /**
5.796 + * Gets the host name of this <code>URL</code>, if applicable.
5.797 + * The format of the host conforms to RFC 2732, i.e. for a
5.798 + * literal IPv6 address, this method will return the IPv6 address
5.799 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
5.800 + *
5.801 + * @return the host name of this <code>URL</code>.
5.802 + */
5.803 + public String getHost() {
5.804 + return host;
5.805 + }
5.806 +
5.807 + /**
5.808 + * Gets the file name of this <code>URL</code>.
5.809 + * The returned file portion will be
5.810 + * the same as <CODE>getPath()</CODE>, plus the concatenation of
5.811 + * the value of <CODE>getQuery()</CODE>, if any. If there is
5.812 + * no query portion, this method and <CODE>getPath()</CODE> will
5.813 + * return identical results.
5.814 + *
5.815 + * @return the file name of this <code>URL</code>,
5.816 + * or an empty string if one does not exist
5.817 + */
5.818 + public String getFile() {
5.819 + return file;
5.820 + }
5.821 +
5.822 + /**
5.823 + * Gets the anchor (also known as the "reference") of this
5.824 + * <code>URL</code>.
5.825 + *
5.826 + * @return the anchor (also known as the "reference") of this
5.827 + * <code>URL</code>, or <CODE>null</CODE> if one does not exist
5.828 + */
5.829 + public String getRef() {
5.830 + return ref;
5.831 + }
5.832 +
5.833 + /**
5.834 + * Compares this URL for equality with another object.<p>
5.835 + *
5.836 + * If the given object is not a URL then this method immediately returns
5.837 + * <code>false</code>.<p>
5.838 + *
5.839 + * Two URL objects are equal if they have the same protocol, reference
5.840 + * equivalent hosts, have the same port number on the host, and the same
5.841 + * file and fragment of the file.<p>
5.842 + *
5.843 + * Two hosts are considered equivalent if both host names can be resolved
5.844 + * into the same IP addresses; else if either host name can't be
5.845 + * resolved, the host names must be equal without regard to case; or both
5.846 + * host names equal to null.<p>
5.847 + *
5.848 + * Since hosts comparison requires name resolution, this operation is a
5.849 + * blocking operation. <p>
5.850 + *
5.851 + * Note: The defined behavior for <code>equals</code> is known to
5.852 + * be inconsistent with virtual hosting in HTTP.
5.853 + *
5.854 + * @param obj the URL to compare against.
5.855 + * @return <code>true</code> if the objects are the same;
5.856 + * <code>false</code> otherwise.
5.857 + */
5.858 + public boolean equals(Object obj) {
5.859 + if (!(obj instanceof URL))
5.860 + return false;
5.861 + URL u2 = (URL)obj;
5.862 +
5.863 + return handler.equals(this, u2);
5.864 + }
5.865 +
5.866 + /**
5.867 + * Creates an integer suitable for hash table indexing.<p>
5.868 + *
5.869 + * The hash code is based upon all the URL components relevant for URL
5.870 + * comparison. As such, this operation is a blocking operation.<p>
5.871 + *
5.872 + * @return a hash code for this <code>URL</code>.
5.873 + */
5.874 + public synchronized int hashCode() {
5.875 + if (hashCode != -1)
5.876 + return hashCode;
5.877 +
5.878 + hashCode = handler.hashCode(this);
5.879 + return hashCode;
5.880 + }
5.881 +
5.882 + /**
5.883 + * Compares two URLs, excluding the fragment component.<p>
5.884 + *
5.885 + * Returns <code>true</code> if this <code>URL</code> and the
5.886 + * <code>other</code> argument are equal without taking the
5.887 + * fragment component into consideration.
5.888 + *
5.889 + * @param other the <code>URL</code> to compare against.
5.890 + * @return <code>true</code> if they reference the same remote object;
5.891 + * <code>false</code> otherwise.
5.892 + */
5.893 + public boolean sameFile(URL other) {
5.894 + return handler.sameFile(this, other);
5.895 + }
5.896 +
5.897 + /**
5.898 + * Constructs a string representation of this <code>URL</code>. The
5.899 + * string is created by calling the <code>toExternalForm</code>
5.900 + * method of the stream protocol handler for this object.
5.901 + *
5.902 + * @return a string representation of this object.
5.903 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
5.904 + * java.lang.String)
5.905 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
5.906 + */
5.907 + public String toString() {
5.908 + return toExternalForm();
5.909 + }
5.910 +
5.911 + /**
5.912 + * Constructs a string representation of this <code>URL</code>. The
5.913 + * string is created by calling the <code>toExternalForm</code>
5.914 + * method of the stream protocol handler for this object.
5.915 + *
5.916 + * @return a string representation of this object.
5.917 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.918 + * int, java.lang.String)
5.919 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
5.920 + */
5.921 + public String toExternalForm() {
5.922 + return handler.toExternalForm(this);
5.923 + }
5.924 +
5.925 + /**
5.926 + * Returns a {@link java.net.URI} equivalent to this URL.
5.927 + * This method functions in the same way as <code>new URI (this.toString())</code>.
5.928 + * <p>Note, any URL instance that complies with RFC 2396 can be converted
5.929 + * to a URI. However, some URLs that are not strictly in compliance
5.930 + * can not be converted to a URI.
5.931 + *
5.932 + * @exception URISyntaxException if this URL is not formatted strictly according to
5.933 + * to RFC2396 and cannot be converted to a URI.
5.934 + *
5.935 + * @return a URI instance equivalent to this URL.
5.936 + * @since 1.5
5.937 + */
5.938 + public URI toURI() throws URISyntaxException {
5.939 + return new URI (toString());
5.940 + }
5.941 +
5.942 + /**
5.943 + * Returns a {@link java.net.URLConnection URLConnection} instance that
5.944 + * represents a connection to the remote object referred to by the
5.945 + * {@code URL}.
5.946 + *
5.947 + * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
5.948 + * created every time when invoking the
5.949 + * {@linkplain java.net.URLStreamHandler#openConnection(URL)
5.950 + * URLStreamHandler.openConnection(URL)} method of the protocol handler for
5.951 + * this URL.</P>
5.952 + *
5.953 + * <P>It should be noted that a URLConnection instance does not establish
5.954 + * the actual network connection on creation. This will happen only when
5.955 + * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
5.956 + *
5.957 + * <P>If for the URL's protocol (such as HTTP or JAR), there
5.958 + * exists a public, specialized URLConnection subclass belonging
5.959 + * to one of the following packages or one of their subpackages:
5.960 + * java.lang, java.io, java.util, java.net, the connection
5.961 + * returned will be of that subclass. For example, for HTTP an
5.962 + * HttpURLConnection will be returned, and for JAR a
5.963 + * JarURLConnection will be returned.</P>
5.964 + *
5.965 + * @return a {@link java.net.URLConnection URLConnection} linking
5.966 + * to the URL.
5.967 + * @exception IOException if an I/O exception occurs.
5.968 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.969 + * int, java.lang.String)
5.970 + */
5.971 + public URLConnection openConnection() throws java.io.IOException {
5.972 + return handler.openConnection(this);
5.973 + }
5.974 +
5.975 + /**
5.976 + * Same as {@link #openConnection()}, except that the connection will be
5.977 + * made through the specified proxy; Protocol handlers that do not
5.978 + * support proxing will ignore the proxy parameter and make a
5.979 + * normal connection.
5.980 + *
5.981 + * Invoking this method preempts the system's default ProxySelector
5.982 + * settings.
5.983 + *
5.984 + * @param proxy the Proxy through which this connection
5.985 + * will be made. If direct connection is desired,
5.986 + * Proxy.NO_PROXY should be specified.
5.987 + * @return a <code>URLConnection</code> to the URL.
5.988 + * @exception IOException if an I/O exception occurs.
5.989 + * @exception SecurityException if a security manager is present
5.990 + * and the caller doesn't have permission to connect
5.991 + * to the proxy.
5.992 + * @exception IllegalArgumentException will be thrown if proxy is null,
5.993 + * or proxy has the wrong type
5.994 + * @exception UnsupportedOperationException if the subclass that
5.995 + * implements the protocol handler doesn't support
5.996 + * this method.
5.997 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.998 + * int, java.lang.String)
5.999 + * @see java.net.URLConnection
5.1000 + * @see java.net.URLStreamHandler#openConnection(java.net.URL,
5.1001 + * java.net.Proxy)
5.1002 + * @since 1.5
5.1003 + */
5.1004 + public URLConnection openConnection(Proxy proxy)
5.1005 + throws java.io.IOException {
5.1006 + if (proxy == null) {
5.1007 + throw new IllegalArgumentException("proxy can not be null");
5.1008 + }
5.1009 +
5.1010 + // Create a copy of Proxy as a security measure
5.1011 + Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : sun.net.ApplicationProxy.create(proxy);
5.1012 + SecurityManager sm = System.getSecurityManager();
5.1013 + if (p.type() != Proxy.Type.DIRECT && sm != null) {
5.1014 + InetSocketAddress epoint = (InetSocketAddress) p.address();
5.1015 + if (epoint.isUnresolved())
5.1016 + sm.checkConnect(epoint.getHostName(), epoint.getPort());
5.1017 + else
5.1018 + sm.checkConnect(epoint.getAddress().getHostAddress(),
5.1019 + epoint.getPort());
5.1020 + }
5.1021 + return handler.openConnection(this, p);
5.1022 + }
5.1023 +
5.1024 + /**
5.1025 + * Opens a connection to this <code>URL</code> and returns an
5.1026 + * <code>InputStream</code> for reading from that connection. This
5.1027 + * method is a shorthand for:
5.1028 + * <blockquote><pre>
5.1029 + * openConnection().getInputStream()
5.1030 + * </pre></blockquote>
5.1031 + *
5.1032 + * @return an input stream for reading from the URL connection.
5.1033 + * @exception IOException if an I/O exception occurs.
5.1034 + * @see java.net.URL#openConnection()
5.1035 + * @see java.net.URLConnection#getInputStream()
5.1036 + */
5.1037 + public final InputStream openStream() throws java.io.IOException {
5.1038 + return openConnection().getInputStream();
5.1039 + }
5.1040 +
5.1041 + /**
5.1042 + * Gets the contents of this URL. This method is a shorthand for:
5.1043 + * <blockquote><pre>
5.1044 + * openConnection().getContent()
5.1045 + * </pre></blockquote>
5.1046 + *
5.1047 + * @return the contents of this URL.
5.1048 + * @exception IOException if an I/O exception occurs.
5.1049 + * @see java.net.URLConnection#getContent()
5.1050 + */
5.1051 + public final Object getContent() throws java.io.IOException {
5.1052 + return openConnection().getContent();
5.1053 + }
5.1054 +
5.1055 + /**
5.1056 + * Gets the contents of this URL. This method is a shorthand for:
5.1057 + * <blockquote><pre>
5.1058 + * openConnection().getContent(Class[])
5.1059 + * </pre></blockquote>
5.1060 + *
5.1061 + * @param classes an array of Java types
5.1062 + * @return the content object of this URL that is the first match of
5.1063 + * the types specified in the classes array.
5.1064 + * null if none of the requested types are supported.
5.1065 + * @exception IOException if an I/O exception occurs.
5.1066 + * @see java.net.URLConnection#getContent(Class[])
5.1067 + * @since 1.3
5.1068 + */
5.1069 + public final Object getContent(Class[] classes)
5.1070 + throws java.io.IOException {
5.1071 + return openConnection().getContent(classes);
5.1072 + }
5.1073 +
5.1074 + /**
5.1075 + * The URLStreamHandler factory.
5.1076 + */
5.1077 + static URLStreamHandlerFactory factory;
5.1078 +
5.1079 + /**
5.1080 + * Sets an application's <code>URLStreamHandlerFactory</code>.
5.1081 + * This method can be called at most once in a given Java Virtual
5.1082 + * Machine.
5.1083 + *
5.1084 + *<p> The <code>URLStreamHandlerFactory</code> instance is used to
5.1085 + *construct a stream protocol handler from a protocol name.
5.1086 + *
5.1087 + * <p> If there is a security manager, this method first calls
5.1088 + * the security manager's <code>checkSetFactory</code> method
5.1089 + * to ensure the operation is allowed.
5.1090 + * This could result in a SecurityException.
5.1091 + *
5.1092 + * @param fac the desired factory.
5.1093 + * @exception Error if the application has already set a factory.
5.1094 + * @exception SecurityException if a security manager exists and its
5.1095 + * <code>checkSetFactory</code> method doesn't allow
5.1096 + * the operation.
5.1097 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
5.1098 + * int, java.lang.String)
5.1099 + * @see java.net.URLStreamHandlerFactory
5.1100 + * @see SecurityManager#checkSetFactory
5.1101 + */
5.1102 + public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
5.1103 + synchronized (streamHandlerLock) {
5.1104 + if (factory != null) {
5.1105 + throw new Error("factory already defined");
5.1106 + }
5.1107 + SecurityManager security = System.getSecurityManager();
5.1108 + if (security != null) {
5.1109 + security.checkSetFactory();
5.1110 + }
5.1111 + handlers.clear();
5.1112 + factory = fac;
5.1113 + }
5.1114 + }
5.1115 +
5.1116 + /**
5.1117 + * A table of protocol handlers.
5.1118 + */
5.1119 + static Hashtable handlers = new Hashtable();
5.1120 + private static Object streamHandlerLock = new Object();
5.1121 +
5.1122 + /**
5.1123 + * Returns the Stream Handler.
5.1124 + * @param protocol the protocol to use
5.1125 + */
5.1126 + static URLStreamHandler getURLStreamHandler(String protocol) {
5.1127 +
5.1128 + URLStreamHandler handler = (URLStreamHandler)handlers.get(protocol);
5.1129 + if (handler == null) {
5.1130 +
5.1131 + boolean checkedWithFactory = false;
5.1132 +
5.1133 + // Use the factory (if any)
5.1134 + if (factory != null) {
5.1135 + handler = factory.createURLStreamHandler(protocol);
5.1136 + checkedWithFactory = true;
5.1137 + }
5.1138 +
5.1139 + // Try java protocol handler
5.1140 + if (handler == null) {
5.1141 + String packagePrefixList = null;
5.1142 +
5.1143 + packagePrefixList
5.1144 + = java.security.AccessController.doPrivileged(
5.1145 + new sun.security.action.GetPropertyAction(
5.1146 + protocolPathProp,""));
5.1147 + if (packagePrefixList != "") {
5.1148 + packagePrefixList += "|";
5.1149 + }
5.1150 +
5.1151 + // REMIND: decide whether to allow the "null" class prefix
5.1152 + // or not.
5.1153 + packagePrefixList += "sun.net.www.protocol";
5.1154 +
5.1155 + StringTokenizer packagePrefixIter =
5.1156 + new StringTokenizer(packagePrefixList, "|");
5.1157 +
5.1158 + while (handler == null &&
5.1159 + packagePrefixIter.hasMoreTokens()) {
5.1160 +
5.1161 + String packagePrefix =
5.1162 + packagePrefixIter.nextToken().trim();
5.1163 + try {
5.1164 + String clsName = packagePrefix + "." + protocol +
5.1165 + ".Handler";
5.1166 + Class cls = null;
5.1167 + try {
5.1168 + cls = Class.forName(clsName);
5.1169 + } catch (ClassNotFoundException e) {
5.1170 + ClassLoader cl = ClassLoader.getSystemClassLoader();
5.1171 + if (cl != null) {
5.1172 + cls = cl.loadClass(clsName);
5.1173 + }
5.1174 + }
5.1175 + if (cls != null) {
5.1176 + handler =
5.1177 + (URLStreamHandler)cls.newInstance();
5.1178 + }
5.1179 + } catch (Exception e) {
5.1180 + // any number of exceptions can get thrown here
5.1181 + }
5.1182 + }
5.1183 + }
5.1184 +
5.1185 + synchronized (streamHandlerLock) {
5.1186 +
5.1187 + URLStreamHandler handler2 = null;
5.1188 +
5.1189 + // Check again with hashtable just in case another
5.1190 + // thread created a handler since we last checked
5.1191 + handler2 = (URLStreamHandler)handlers.get(protocol);
5.1192 +
5.1193 + if (handler2 != null) {
5.1194 + return handler2;
5.1195 + }
5.1196 +
5.1197 + // Check with factory if another thread set a
5.1198 + // factory since our last check
5.1199 + if (!checkedWithFactory && factory != null) {
5.1200 + handler2 = factory.createURLStreamHandler(protocol);
5.1201 + }
5.1202 +
5.1203 + if (handler2 != null) {
5.1204 + // The handler from the factory must be given more
5.1205 + // importance. Discard the default handler that
5.1206 + // this thread created.
5.1207 + handler = handler2;
5.1208 + }
5.1209 +
5.1210 + // Insert this handler into the hashtable
5.1211 + if (handler != null) {
5.1212 + handlers.put(protocol, handler);
5.1213 + }
5.1214 +
5.1215 + }
5.1216 + }
5.1217 +
5.1218 + return handler;
5.1219 +
5.1220 + }
5.1221 +
5.1222 + /**
5.1223 + * WriteObject is called to save the state of the URL to an
5.1224 + * ObjectOutputStream. The handler is not saved since it is
5.1225 + * specific to this system.
5.1226 + *
5.1227 + * @serialData the default write object value. When read back in,
5.1228 + * the reader must ensure that calling getURLStreamHandler with
5.1229 + * the protocol variable returns a valid URLStreamHandler and
5.1230 + * throw an IOException if it does not.
5.1231 + */
5.1232 + private synchronized void writeObject(java.io.ObjectOutputStream s)
5.1233 + throws IOException
5.1234 + {
5.1235 + s.defaultWriteObject(); // write the fields
5.1236 + }
5.1237 +
5.1238 + /**
5.1239 + * readObject is called to restore the state of the URL from the
5.1240 + * stream. It reads the components of the URL and finds the local
5.1241 + * stream handler.
5.1242 + */
5.1243 + private synchronized void readObject(java.io.ObjectInputStream s)
5.1244 + throws IOException, ClassNotFoundException
5.1245 + {
5.1246 + s.defaultReadObject(); // read the fields
5.1247 + if ((handler = getURLStreamHandler(protocol)) == null) {
5.1248 + throw new IOException("unknown protocol: " + protocol);
5.1249 + }
5.1250 +
5.1251 + // Construct authority part
5.1252 + if (authority == null &&
5.1253 + ((host != null && host.length() > 0) || port != -1)) {
5.1254 + if (host == null)
5.1255 + host = "";
5.1256 + authority = (port == -1) ? host : host + ":" + port;
5.1257 +
5.1258 + // Handle hosts with userInfo in them
5.1259 + int at = host.lastIndexOf('@');
5.1260 + if (at != -1) {
5.1261 + userInfo = host.substring(0, at);
5.1262 + host = host.substring(at+1);
5.1263 + }
5.1264 + } else if (authority != null) {
5.1265 + // Construct user info part
5.1266 + int ind = authority.indexOf('@');
5.1267 + if (ind != -1)
5.1268 + userInfo = authority.substring(0, ind);
5.1269 + }
5.1270 +
5.1271 + // Construct path and query part
5.1272 + path = null;
5.1273 + query = null;
5.1274 + if (file != null) {
5.1275 + // Fix: only do this if hierarchical?
5.1276 + int q = file.lastIndexOf('?');
5.1277 + if (q != -1) {
5.1278 + query = file.substring(q+1);
5.1279 + path = file.substring(0, q);
5.1280 + } else
5.1281 + path = file;
5.1282 + }
5.1283 + }
5.1284 +}
5.1285 +
5.1286 +class Parts {
5.1287 + String path, query, ref;
5.1288 +
5.1289 + Parts(String file) {
5.1290 + int ind = file.indexOf('#');
5.1291 + ref = ind < 0 ? null: file.substring(ind + 1);
5.1292 + file = ind < 0 ? file: file.substring(0, ind);
5.1293 + int q = file.lastIndexOf('?');
5.1294 + if (q != -1) {
5.1295 + query = file.substring(q+1);
5.1296 + path = file.substring(0, q);
5.1297 + } else {
5.1298 + path = file;
5.1299 + }
5.1300 + }
5.1301 +
5.1302 + String getPath() {
5.1303 + return path;
5.1304 + }
5.1305 +
5.1306 + String getQuery() {
5.1307 + return query;
5.1308 + }
5.1309 +
5.1310 + String getRef() {
5.1311 + return ref;
5.1312 + }
5.1313 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/src/main/java/java/util/Enumeration.java Tue Oct 30 09:14:17 2012 +0100
6.3 @@ -0,0 +1,79 @@
6.4 +/*
6.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +package java.util;
6.30 +
6.31 +/**
6.32 + * An object that implements the Enumeration interface generates a
6.33 + * series of elements, one at a time. Successive calls to the
6.34 + * <code>nextElement</code> method return successive elements of the
6.35 + * series.
6.36 + * <p>
6.37 + * For example, to print all elements of a <tt>Vector<E></tt> <i>v</i>:
6.38 + * <pre>
6.39 + * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
6.40 + * System.out.println(e.nextElement());</pre>
6.41 + * <p>
6.42 + * Methods are provided to enumerate through the elements of a
6.43 + * vector, the keys of a hashtable, and the values in a hashtable.
6.44 + * Enumerations are also used to specify the input streams to a
6.45 + * <code>SequenceInputStream</code>.
6.46 + * <p>
6.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
6.48 + * interface. In addition, Iterator adds an optional remove operation, and
6.49 + * has shorter method names. New implementations should consider using
6.50 + * Iterator in preference to Enumeration.
6.51 + *
6.52 + * @see java.util.Iterator
6.53 + * @see java.io.SequenceInputStream
6.54 + * @see java.util.Enumeration#nextElement()
6.55 + * @see java.util.Hashtable
6.56 + * @see java.util.Hashtable#elements()
6.57 + * @see java.util.Hashtable#keys()
6.58 + * @see java.util.Vector
6.59 + * @see java.util.Vector#elements()
6.60 + *
6.61 + * @author Lee Boynton
6.62 + * @since JDK1.0
6.63 + */
6.64 +public interface Enumeration<E> {
6.65 + /**
6.66 + * Tests if this enumeration contains more elements.
6.67 + *
6.68 + * @return <code>true</code> if and only if this enumeration object
6.69 + * contains at least one more element to provide;
6.70 + * <code>false</code> otherwise.
6.71 + */
6.72 + boolean hasMoreElements();
6.73 +
6.74 + /**
6.75 + * Returns the next element of this enumeration if this enumeration
6.76 + * object has at least one more element to provide.
6.77 + *
6.78 + * @return the next element of this enumeration.
6.79 + * @exception NoSuchElementException if no more elements exist.
6.80 + */
6.81 + E nextElement();
6.82 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/emul/src/main/java/java/util/NoSuchElementException.java Tue Oct 30 09:14:17 2012 +0100
7.3 @@ -0,0 +1,60 @@
7.4 +/*
7.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.util;
7.30 +
7.31 +/**
7.32 + * Thrown by the <code>nextElement</code> method of an
7.33 + * <code>Enumeration</code> to indicate that there are no more
7.34 + * elements in the enumeration.
7.35 + *
7.36 + * @author unascribed
7.37 + * @see java.util.Enumeration
7.38 + * @see java.util.Enumeration#nextElement()
7.39 + * @since JDK1.0
7.40 + */
7.41 +public
7.42 +class NoSuchElementException extends RuntimeException {
7.43 + private static final long serialVersionUID = 6769829250639411880L;
7.44 +
7.45 + /**
7.46 + * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
7.47 + * as its error message string.
7.48 + */
7.49 + public NoSuchElementException() {
7.50 + super();
7.51 + }
7.52 +
7.53 + /**
7.54 + * Constructs a <code>NoSuchElementException</code>, saving a reference
7.55 + * to the error message string <tt>s</tt> for later retrieval by the
7.56 + * <tt>getMessage</tt> method.
7.57 + *
7.58 + * @param s the detail message.
7.59 + */
7.60 + public NoSuchElementException(String s) {
7.61 + super(s);
7.62 + }
7.63 +}