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:05:33 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:05:33 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:05:33 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/URL.java Tue Oct 30 09:05:33 2012 +0100
4.3 @@ -0,0 +1,1310 @@
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 +import java.io.InputStream;
4.33 +import java.io.OutputStream;
4.34 +import java.util.Hashtable;
4.35 +import java.util.StringTokenizer;
4.36 +import sun.security.util.SecurityConstants;
4.37 +
4.38 +/**
4.39 + * Class <code>URL</code> represents a Uniform Resource
4.40 + * Locator, a pointer to a "resource" on the World
4.41 + * Wide Web. A resource can be something as simple as a file or a
4.42 + * directory, or it can be a reference to a more complicated object,
4.43 + * such as a query to a database or to a search engine. More
4.44 + * information on the types of URLs and their formats can be found at:
4.45 + * <blockquote>
4.46 + * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
4.47 + * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
4.48 + * </blockquote>
4.49 + * <p>
4.50 + * In general, a URL can be broken into several parts. The previous
4.51 + * example of a URL indicates that the protocol to use is
4.52 + * <code>http</code> (HyperText Transfer Protocol) and that the
4.53 + * information resides on a host machine named
4.54 + * <code>www.socs.uts.edu.au</code>. The information on that host
4.55 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
4.56 + * meaning of this name on the host machine is both protocol
4.57 + * dependent and host dependent. The information normally resides in
4.58 + * a file, but it could be generated on the fly. This component of
4.59 + * the URL is called the <i>path</i> component.
4.60 + * <p>
4.61 + * A URL can optionally specify a "port", which is the
4.62 + * port number to which the TCP connection is made on the remote host
4.63 + * machine. If the port is not specified, the default port for
4.64 + * the protocol is used instead. For example, the default port for
4.65 + * <code>http</code> is <code>80</code>. An alternative port could be
4.66 + * specified as:
4.67 + * <blockquote><pre>
4.68 + * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
4.69 + * </pre></blockquote>
4.70 + * <p>
4.71 + * The syntax of <code>URL</code> is defined by <a
4.72 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
4.73 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
4.74 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
4.75 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
4.76 + * also supports scope_ids. The syntax and usage of scope_ids is described
4.77 + * <a href="Inet6Address.html#scoped">here</a>.
4.78 + * <p>
4.79 + * A URL may have appended to it a "fragment", also known
4.80 + * as a "ref" or a "reference". The fragment is indicated by the sharp
4.81 + * sign character "#" followed by more characters. For example,
4.82 + * <blockquote><pre>
4.83 + * http://java.sun.com/index.html#chapter1
4.84 + * </pre></blockquote>
4.85 + * <p>
4.86 + * This fragment is not technically part of the URL. Rather, it
4.87 + * indicates that after the specified resource is retrieved, the
4.88 + * application is specifically interested in that part of the
4.89 + * document that has the tag <code>chapter1</code> attached to it. The
4.90 + * meaning of a tag is resource specific.
4.91 + * <p>
4.92 + * An application can also specify a "relative URL",
4.93 + * which contains only enough information to reach the resource
4.94 + * relative to another URL. Relative URLs are frequently used within
4.95 + * HTML pages. For example, if the contents of the URL:
4.96 + * <blockquote><pre>
4.97 + * http://java.sun.com/index.html
4.98 + * </pre></blockquote>
4.99 + * contained within it the relative URL:
4.100 + * <blockquote><pre>
4.101 + * FAQ.html
4.102 + * </pre></blockquote>
4.103 + * it would be a shorthand for:
4.104 + * <blockquote><pre>
4.105 + * http://java.sun.com/FAQ.html
4.106 + * </pre></blockquote>
4.107 + * <p>
4.108 + * The relative URL need not specify all the components of a URL. If
4.109 + * the protocol, host name, or port number is missing, the value is
4.110 + * inherited from the fully specified URL. The file component must be
4.111 + * specified. The optional fragment is not inherited.
4.112 + * <p>
4.113 + * The URL class does not itself encode or decode any URL components
4.114 + * according to the escaping mechanism defined in RFC2396. It is the
4.115 + * responsibility of the caller to encode any fields, which need to be
4.116 + * escaped prior to calling URL, and also to decode any escaped fields,
4.117 + * that are returned from URL. Furthermore, because URL has no knowledge
4.118 + * of URL escaping, it does not recognise equivalence between the encoded
4.119 + * or decoded form of the same URL. For example, the two URLs:<br>
4.120 + * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
4.121 + * would be considered not equal to each other.
4.122 + * <p>
4.123 + * Note, the {@link java.net.URI} class does perform escaping of its
4.124 + * component fields in certain circumstances. The recommended way
4.125 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
4.126 + * and to convert between these two classes using {@link #toURI()} and
4.127 + * {@link URI#toURL()}.
4.128 + * <p>
4.129 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
4.130 + * used, but only for HTML form encoding, which is not the same
4.131 + * as the encoding scheme defined in RFC2396.
4.132 + *
4.133 + * @author James Gosling
4.134 + * @since JDK1.0
4.135 + */
4.136 +public final class URL implements java.io.Serializable {
4.137 +
4.138 + static final long serialVersionUID = -7627629688361524110L;
4.139 +
4.140 + /**
4.141 + * The property which specifies the package prefix list to be scanned
4.142 + * for protocol handlers. The value of this property (if any) should
4.143 + * be a vertical bar delimited list of package names to search through
4.144 + * for a protocol handler to load. The policy of this class is that
4.145 + * all protocol handlers will be in a class called <protocolname>.Handler,
4.146 + * and each package in the list is examined in turn for a matching
4.147 + * handler. If none are found (or the property is not specified), the
4.148 + * default package prefix, sun.net.www.protocol, is used. The search
4.149 + * proceeds from the first package in the list to the last and stops
4.150 + * when a match is found.
4.151 + */
4.152 + private static final String protocolPathProp = "java.protocol.handler.pkgs";
4.153 +
4.154 + /**
4.155 + * The protocol to use (ftp, http, nntp, ... etc.) .
4.156 + * @serial
4.157 + */
4.158 + private String protocol;
4.159 +
4.160 + /**
4.161 + * The host name to connect to.
4.162 + * @serial
4.163 + */
4.164 + private String host;
4.165 +
4.166 + /**
4.167 + * The protocol port to connect to.
4.168 + * @serial
4.169 + */
4.170 + private int port = -1;
4.171 +
4.172 + /**
4.173 + * The specified file name on that host. <code>file</code> is
4.174 + * defined as <code>path[?query]</code>
4.175 + * @serial
4.176 + */
4.177 + private String file;
4.178 +
4.179 + /**
4.180 + * The query part of this URL.
4.181 + */
4.182 + private transient String query;
4.183 +
4.184 + /**
4.185 + * The authority part of this URL.
4.186 + * @serial
4.187 + */
4.188 + private String authority;
4.189 +
4.190 + /**
4.191 + * The path part of this URL.
4.192 + */
4.193 + private transient String path;
4.194 +
4.195 + /**
4.196 + * The userinfo part of this URL.
4.197 + */
4.198 + private transient String userInfo;
4.199 +
4.200 + /**
4.201 + * # reference.
4.202 + * @serial
4.203 + */
4.204 + private String ref;
4.205 +
4.206 + /**
4.207 + * The host's IP address, used in equals and hashCode.
4.208 + * Computed on demand. An uninitialized or unknown hostAddress is null.
4.209 + */
4.210 + transient InetAddress hostAddress;
4.211 +
4.212 + /**
4.213 + * The URLStreamHandler for this URL.
4.214 + */
4.215 + transient URLStreamHandler handler;
4.216 +
4.217 + /* Our hash code.
4.218 + * @serial
4.219 + */
4.220 + private int hashCode = -1;
4.221 +
4.222 + /**
4.223 + * Creates a <code>URL</code> object from the specified
4.224 + * <code>protocol</code>, <code>host</code>, <code>port</code>
4.225 + * number, and <code>file</code>.<p>
4.226 + *
4.227 + * <code>host</code> can be expressed as a host name or a literal
4.228 + * IP address. If IPv6 literal address is used, it should be
4.229 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
4.230 + * specified by <a
4.231 + * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
4.232 + * However, the literal IPv6 address format defined in <a
4.233 + * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
4.234 + * Version 6 Addressing Architecture</i></a> is also accepted.<p>
4.235 + *
4.236 + * Specifying a <code>port</code> number of <code>-1</code>
4.237 + * indicates that the URL should use the default port for the
4.238 + * protocol.<p>
4.239 + *
4.240 + * If this is the first URL object being created with the specified
4.241 + * protocol, a <i>stream protocol handler</i> object, an instance of
4.242 + * class <code>URLStreamHandler</code>, is created for that protocol:
4.243 + * <ol>
4.244 + * <li>If the application has previously set up an instance of
4.245 + * <code>URLStreamHandlerFactory</code> as the stream handler factory,
4.246 + * then the <code>createURLStreamHandler</code> method of that instance
4.247 + * is called with the protocol string as an argument to create the
4.248 + * stream protocol handler.
4.249 + * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
4.250 + * or if the factory's <code>createURLStreamHandler</code> method
4.251 + * returns <code>null</code>, then the constructor finds the
4.252 + * value of the system property:
4.253 + * <blockquote><pre>
4.254 + * java.protocol.handler.pkgs
4.255 + * </pre></blockquote>
4.256 + * If the value of that system property is not <code>null</code>,
4.257 + * it is interpreted as a list of packages separated by a vertical
4.258 + * slash character '<code>|</code>'. The constructor tries to load
4.259 + * the class named:
4.260 + * <blockquote><pre>
4.261 + * <<i>package</i>>.<<i>protocol</i>>.Handler
4.262 + * </pre></blockquote>
4.263 + * where <<i>package</i>> is replaced by the name of the package
4.264 + * and <<i>protocol</i>> is replaced by the name of the protocol.
4.265 + * If this class does not exist, or if the class exists but it is not
4.266 + * a subclass of <code>URLStreamHandler</code>, then the next package
4.267 + * in the list is tried.
4.268 + * <li>If the previous step fails to find a protocol handler, then the
4.269 + * constructor tries to load from a system default package.
4.270 + * <blockquote><pre>
4.271 + * <<i>system default package</i>>.<<i>protocol</i>>.Handler
4.272 + * </pre></blockquote>
4.273 + * If this class does not exist, or if the class exists but it is not a
4.274 + * subclass of <code>URLStreamHandler</code>, then a
4.275 + * <code>MalformedURLException</code> is thrown.
4.276 + * </ol>
4.277 + *
4.278 + * <p>Protocol handlers for the following protocols are guaranteed
4.279 + * to exist on the search path :-
4.280 + * <blockquote><pre>
4.281 + * http, https, ftp, file, and jar
4.282 + * </pre></blockquote>
4.283 + * Protocol handlers for additional protocols may also be
4.284 + * available.
4.285 + *
4.286 + * <p>No validation of the inputs is performed by this constructor.
4.287 + *
4.288 + * @param protocol the name of the protocol to use.
4.289 + * @param host the name of the host.
4.290 + * @param port the port number on the host.
4.291 + * @param file the file on the host
4.292 + * @exception MalformedURLException if an unknown protocol is specified.
4.293 + * @see java.lang.System#getProperty(java.lang.String)
4.294 + * @see java.net.URL#setURLStreamHandlerFactory(
4.295 + * java.net.URLStreamHandlerFactory)
4.296 + * @see java.net.URLStreamHandler
4.297 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
4.298 + * java.lang.String)
4.299 + */
4.300 + public URL(String protocol, String host, int port, String file)
4.301 + throws MalformedURLException
4.302 + {
4.303 + this(protocol, host, port, file, null);
4.304 + }
4.305 +
4.306 + /**
4.307 + * Creates a URL from the specified <code>protocol</code>
4.308 + * name, <code>host</code> name, and <code>file</code> name. The
4.309 + * default port for the specified protocol is used.
4.310 + * <p>
4.311 + * This method is equivalent to calling the four-argument
4.312 + * constructor with the arguments being <code>protocol</code>,
4.313 + * <code>host</code>, <code>-1</code>, and <code>file</code>.
4.314 + *
4.315 + * No validation of the inputs is performed by this constructor.
4.316 + *
4.317 + * @param protocol the name of the protocol to use.
4.318 + * @param host the name of the host.
4.319 + * @param file the file on the host.
4.320 + * @exception MalformedURLException if an unknown protocol is specified.
4.321 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.322 + * int, java.lang.String)
4.323 + */
4.324 + public URL(String protocol, String host, String file)
4.325 + throws MalformedURLException {
4.326 + this(protocol, host, -1, file);
4.327 + }
4.328 +
4.329 + /**
4.330 + * Creates a <code>URL</code> object from the specified
4.331 + * <code>protocol</code>, <code>host</code>, <code>port</code>
4.332 + * number, <code>file</code>, and <code>handler</code>. Specifying
4.333 + * a <code>port</code> number of <code>-1</code> indicates that
4.334 + * the URL should use the default port for the protocol. Specifying
4.335 + * a <code>handler</code> of <code>null</code> indicates that the URL
4.336 + * should use a default stream handler for the protocol, as outlined
4.337 + * for:
4.338 + * java.net.URL#URL(java.lang.String, java.lang.String, int,
4.339 + * java.lang.String)
4.340 + *
4.341 + * <p>If the handler is not null and there is a security manager,
4.342 + * the security manager's <code>checkPermission</code>
4.343 + * method is called with a
4.344 + * <code>NetPermission("specifyStreamHandler")</code> permission.
4.345 + * This may result in a SecurityException.
4.346 + *
4.347 + * No validation of the inputs is performed by this constructor.
4.348 + *
4.349 + * @param protocol the name of the protocol to use.
4.350 + * @param host the name of the host.
4.351 + * @param port the port number on the host.
4.352 + * @param file the file on the host
4.353 + * @param handler the stream handler for the URL.
4.354 + * @exception MalformedURLException if an unknown protocol is specified.
4.355 + * @exception SecurityException
4.356 + * if a security manager exists and its
4.357 + * <code>checkPermission</code> method doesn't allow
4.358 + * specifying a stream handler explicitly.
4.359 + * @see java.lang.System#getProperty(java.lang.String)
4.360 + * @see java.net.URL#setURLStreamHandlerFactory(
4.361 + * java.net.URLStreamHandlerFactory)
4.362 + * @see java.net.URLStreamHandler
4.363 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
4.364 + * java.lang.String)
4.365 + * @see SecurityManager#checkPermission
4.366 + * @see java.net.NetPermission
4.367 + */
4.368 + public URL(String protocol, String host, int port, String file,
4.369 + URLStreamHandler handler) throws MalformedURLException {
4.370 + if (handler != null) {
4.371 + SecurityManager sm = System.getSecurityManager();
4.372 + if (sm != null) {
4.373 + // check for permission to specify a handler
4.374 + checkSpecifyHandler(sm);
4.375 + }
4.376 + }
4.377 +
4.378 + protocol = protocol.toLowerCase();
4.379 + this.protocol = protocol;
4.380 + if (host != null) {
4.381 +
4.382 + /**
4.383 + * if host is a literal IPv6 address,
4.384 + * we will make it conform to RFC 2732
4.385 + */
4.386 + if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
4.387 + host = "["+host+"]";
4.388 + }
4.389 + this.host = host;
4.390 +
4.391 + if (port < -1) {
4.392 + throw new MalformedURLException("Invalid port number :" +
4.393 + port);
4.394 + }
4.395 + this.port = port;
4.396 + authority = (port == -1) ? host : host + ":" + port;
4.397 + }
4.398 +
4.399 + Parts parts = new Parts(file);
4.400 + path = parts.getPath();
4.401 + query = parts.getQuery();
4.402 +
4.403 + if (query != null) {
4.404 + this.file = path + "?" + query;
4.405 + } else {
4.406 + this.file = path;
4.407 + }
4.408 + ref = parts.getRef();
4.409 +
4.410 + // Note: we don't do validation of the URL here. Too risky to change
4.411 + // right now, but worth considering for future reference. -br
4.412 + if (handler == null &&
4.413 + (handler = getURLStreamHandler(protocol)) == null) {
4.414 + throw new MalformedURLException("unknown protocol: " + protocol);
4.415 + }
4.416 + this.handler = handler;
4.417 + }
4.418 +
4.419 + /**
4.420 + * Creates a <code>URL</code> object from the <code>String</code>
4.421 + * representation.
4.422 + * <p>
4.423 + * This constructor is equivalent to a call to the two-argument
4.424 + * constructor with a <code>null</code> first argument.
4.425 + *
4.426 + * @param spec the <code>String</code> to parse as a URL.
4.427 + * @exception MalformedURLException if no protocol is specified, or an
4.428 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
4.429 + * @see java.net.URL#URL(java.net.URL, java.lang.String)
4.430 + */
4.431 + public URL(String spec) throws MalformedURLException {
4.432 + this(null, spec);
4.433 + }
4.434 +
4.435 + /**
4.436 + * Creates a URL by parsing the given spec within a specified context.
4.437 + *
4.438 + * The new URL is created from the given context URL and the spec
4.439 + * argument as described in
4.440 + * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
4.441 + * <blockquote><pre>
4.442 + * <scheme>://<authority><path>?<query>#<fragment>
4.443 + * </pre></blockquote>
4.444 + * The reference is parsed into the scheme, authority, path, query and
4.445 + * fragment parts. If the path component is empty and the scheme,
4.446 + * authority, and query components are undefined, then the new URL is a
4.447 + * reference to the current document. Otherwise, the fragment and query
4.448 + * parts present in the spec are used in the new URL.
4.449 + * <p>
4.450 + * If the scheme component is defined in the given spec and does not match
4.451 + * the scheme of the context, then the new URL is created as an absolute
4.452 + * URL based on the spec alone. Otherwise the scheme component is inherited
4.453 + * from the context URL.
4.454 + * <p>
4.455 + * If the authority component is present in the spec then the spec is
4.456 + * treated as absolute and the spec authority and path will replace the
4.457 + * context authority and path. If the authority component is absent in the
4.458 + * spec then the authority of the new URL will be inherited from the
4.459 + * context.
4.460 + * <p>
4.461 + * If the spec's path component begins with a slash character
4.462 + * "/" then the
4.463 + * path is treated as absolute and the spec path replaces the context path.
4.464 + * <p>
4.465 + * Otherwise, the path is treated as a relative path and is appended to the
4.466 + * context path, as described in RFC2396. Also, in this case,
4.467 + * the path is canonicalized through the removal of directory
4.468 + * changes made by occurences of ".." and ".".
4.469 + * <p>
4.470 + * For a more detailed description of URL parsing, refer to RFC2396.
4.471 + *
4.472 + * @param context the context in which to parse the specification.
4.473 + * @param spec the <code>String</code> to parse as a URL.
4.474 + * @exception MalformedURLException if no protocol is specified, or an
4.475 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
4.476 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.477 + * int, java.lang.String)
4.478 + * @see java.net.URLStreamHandler
4.479 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
4.480 + * java.lang.String, int, int)
4.481 + */
4.482 + public URL(URL context, String spec) throws MalformedURLException {
4.483 + this(context, spec, null);
4.484 + }
4.485 +
4.486 + /**
4.487 + * Creates a URL by parsing the given spec with the specified handler
4.488 + * within a specified context. If the handler is null, the parsing
4.489 + * occurs as with the two argument constructor.
4.490 + *
4.491 + * @param context the context in which to parse the specification.
4.492 + * @param spec the <code>String</code> to parse as a URL.
4.493 + * @param handler the stream handler for the URL.
4.494 + * @exception MalformedURLException if no protocol is specified, or an
4.495 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
4.496 + * @exception SecurityException
4.497 + * if a security manager exists and its
4.498 + * <code>checkPermission</code> method doesn't allow
4.499 + * specifying a stream handler.
4.500 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.501 + * int, java.lang.String)
4.502 + * @see java.net.URLStreamHandler
4.503 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
4.504 + * java.lang.String, int, int)
4.505 + */
4.506 + public URL(URL context, String spec, URLStreamHandler handler)
4.507 + throws MalformedURLException
4.508 + {
4.509 + String original = spec;
4.510 + int i, limit, c;
4.511 + int start = 0;
4.512 + String newProtocol = null;
4.513 + boolean aRef=false;
4.514 + boolean isRelative = false;
4.515 +
4.516 + // Check for permission to specify a handler
4.517 + if (handler != null) {
4.518 + SecurityManager sm = System.getSecurityManager();
4.519 + if (sm != null) {
4.520 + checkSpecifyHandler(sm);
4.521 + }
4.522 + }
4.523 +
4.524 + try {
4.525 + limit = spec.length();
4.526 + while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
4.527 + limit--; //eliminate trailing whitespace
4.528 + }
4.529 + while ((start < limit) && (spec.charAt(start) <= ' ')) {
4.530 + start++; // eliminate leading whitespace
4.531 + }
4.532 +
4.533 + if (spec.regionMatches(true, start, "url:", 0, 4)) {
4.534 + start += 4;
4.535 + }
4.536 + if (start < spec.length() && spec.charAt(start) == '#') {
4.537 + /* we're assuming this is a ref relative to the context URL.
4.538 + * This means protocols cannot start w/ '#', but we must parse
4.539 + * ref URL's like: "hello:there" w/ a ':' in them.
4.540 + */
4.541 + aRef=true;
4.542 + }
4.543 + for (i = start ; !aRef && (i < limit) &&
4.544 + ((c = spec.charAt(i)) != '/') ; i++) {
4.545 + if (c == ':') {
4.546 +
4.547 + String s = spec.substring(start, i).toLowerCase();
4.548 + if (isValidProtocol(s)) {
4.549 + newProtocol = s;
4.550 + start = i + 1;
4.551 + }
4.552 + break;
4.553 + }
4.554 + }
4.555 +
4.556 + // Only use our context if the protocols match.
4.557 + protocol = newProtocol;
4.558 + if ((context != null) && ((newProtocol == null) ||
4.559 + newProtocol.equalsIgnoreCase(context.protocol))) {
4.560 + // inherit the protocol handler from the context
4.561 + // if not specified to the constructor
4.562 + if (handler == null) {
4.563 + handler = context.handler;
4.564 + }
4.565 +
4.566 + // If the context is a hierarchical URL scheme and the spec
4.567 + // contains a matching scheme then maintain backwards
4.568 + // compatibility and treat it as if the spec didn't contain
4.569 + // the scheme; see 5.2.3 of RFC2396
4.570 + if (context.path != null && context.path.startsWith("/"))
4.571 + newProtocol = null;
4.572 +
4.573 + if (newProtocol == null) {
4.574 + protocol = context.protocol;
4.575 + authority = context.authority;
4.576 + userInfo = context.userInfo;
4.577 + host = context.host;
4.578 + port = context.port;
4.579 + file = context.file;
4.580 + path = context.path;
4.581 + isRelative = true;
4.582 + }
4.583 + }
4.584 +
4.585 + if (protocol == null) {
4.586 + throw new MalformedURLException("no protocol: "+original);
4.587 + }
4.588 +
4.589 + // Get the protocol handler if not specified or the protocol
4.590 + // of the context could not be used
4.591 + if (handler == null &&
4.592 + (handler = getURLStreamHandler(protocol)) == null) {
4.593 + throw new MalformedURLException("unknown protocol: "+protocol);
4.594 + }
4.595 +
4.596 + this.handler = handler;
4.597 +
4.598 + i = spec.indexOf('#', start);
4.599 + if (i >= 0) {
4.600 + ref = spec.substring(i + 1, limit);
4.601 + limit = i;
4.602 + }
4.603 +
4.604 + /*
4.605 + * Handle special case inheritance of query and fragment
4.606 + * implied by RFC2396 section 5.2.2.
4.607 + */
4.608 + if (isRelative && start == limit) {
4.609 + query = context.query;
4.610 + if (ref == null) {
4.611 + ref = context.ref;
4.612 + }
4.613 + }
4.614 +
4.615 + handler.parseURL(this, spec, start, limit);
4.616 +
4.617 + } catch(MalformedURLException e) {
4.618 + throw e;
4.619 + } catch(Exception e) {
4.620 + MalformedURLException exception = new MalformedURLException(e.getMessage());
4.621 + exception.initCause(e);
4.622 + throw exception;
4.623 + }
4.624 + }
4.625 +
4.626 + /*
4.627 + * Returns true if specified string is a valid protocol name.
4.628 + */
4.629 + private boolean isValidProtocol(String protocol) {
4.630 + int len = protocol.length();
4.631 + if (len < 1)
4.632 + return false;
4.633 + char c = protocol.charAt(0);
4.634 + if (!Character.isLetter(c))
4.635 + return false;
4.636 + for (int i = 1; i < len; i++) {
4.637 + c = protocol.charAt(i);
4.638 + if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
4.639 + c != '-') {
4.640 + return false;
4.641 + }
4.642 + }
4.643 + return true;
4.644 + }
4.645 +
4.646 + /*
4.647 + * Checks for permission to specify a stream handler.
4.648 + */
4.649 + private void checkSpecifyHandler(SecurityManager sm) {
4.650 + sm.checkPermission(SecurityConstants.SPECIFY_HANDLER_PERMISSION);
4.651 + }
4.652 +
4.653 + /**
4.654 + * Sets the fields of the URL. This is not a public method so that
4.655 + * only URLStreamHandlers can modify URL fields. URLs are
4.656 + * otherwise constant.
4.657 + *
4.658 + * @param protocol the name of the protocol to use
4.659 + * @param host the name of the host
4.660 + @param port the port number on the host
4.661 + * @param file the file on the host
4.662 + * @param ref the internal reference in the URL
4.663 + */
4.664 + protected void set(String protocol, String host,
4.665 + int port, String file, String ref) {
4.666 + synchronized (this) {
4.667 + this.protocol = protocol;
4.668 + this.host = host;
4.669 + authority = port == -1 ? host : host + ":" + port;
4.670 + this.port = port;
4.671 + this.file = file;
4.672 + this.ref = ref;
4.673 + /* This is very important. We must recompute this after the
4.674 + * URL has been changed. */
4.675 + hashCode = -1;
4.676 + hostAddress = null;
4.677 + int q = file.lastIndexOf('?');
4.678 + if (q != -1) {
4.679 + query = file.substring(q+1);
4.680 + path = file.substring(0, q);
4.681 + } else
4.682 + path = file;
4.683 + }
4.684 + }
4.685 +
4.686 + /**
4.687 + * Sets the specified 8 fields of the URL. This is not a public method so
4.688 + * that only URLStreamHandlers can modify URL fields. URLs are otherwise
4.689 + * constant.
4.690 + *
4.691 + * @param protocol the name of the protocol to use
4.692 + * @param host the name of the host
4.693 + * @param port the port number on the host
4.694 + * @param authority the authority part for the url
4.695 + * @param userInfo the username and password
4.696 + * @param path the file on the host
4.697 + * @param ref the internal reference in the URL
4.698 + * @param query the query part of this URL
4.699 + * @since 1.3
4.700 + */
4.701 + protected void set(String protocol, String host, int port,
4.702 + String authority, String userInfo, String path,
4.703 + String query, String ref) {
4.704 + synchronized (this) {
4.705 + this.protocol = protocol;
4.706 + this.host = host;
4.707 + this.port = port;
4.708 + this.file = query == null ? path : path + "?" + query;
4.709 + this.userInfo = userInfo;
4.710 + this.path = path;
4.711 + this.ref = ref;
4.712 + /* This is very important. We must recompute this after the
4.713 + * URL has been changed. */
4.714 + hashCode = -1;
4.715 + hostAddress = null;
4.716 + this.query = query;
4.717 + this.authority = authority;
4.718 + }
4.719 + }
4.720 +
4.721 + /**
4.722 + * Gets the query part of this <code>URL</code>.
4.723 + *
4.724 + * @return the query part of this <code>URL</code>,
4.725 + * or <CODE>null</CODE> if one does not exist
4.726 + * @since 1.3
4.727 + */
4.728 + public String getQuery() {
4.729 + return query;
4.730 + }
4.731 +
4.732 + /**
4.733 + * Gets the path part of this <code>URL</code>.
4.734 + *
4.735 + * @return the path part of this <code>URL</code>, or an
4.736 + * empty string if one does not exist
4.737 + * @since 1.3
4.738 + */
4.739 + public String getPath() {
4.740 + return path;
4.741 + }
4.742 +
4.743 + /**
4.744 + * Gets the userInfo part of this <code>URL</code>.
4.745 + *
4.746 + * @return the userInfo part of this <code>URL</code>, or
4.747 + * <CODE>null</CODE> if one does not exist
4.748 + * @since 1.3
4.749 + */
4.750 + public String getUserInfo() {
4.751 + return userInfo;
4.752 + }
4.753 +
4.754 + /**
4.755 + * Gets the authority part of this <code>URL</code>.
4.756 + *
4.757 + * @return the authority part of this <code>URL</code>
4.758 + * @since 1.3
4.759 + */
4.760 + public String getAuthority() {
4.761 + return authority;
4.762 + }
4.763 +
4.764 + /**
4.765 + * Gets the port number of this <code>URL</code>.
4.766 + *
4.767 + * @return the port number, or -1 if the port is not set
4.768 + */
4.769 + public int getPort() {
4.770 + return port;
4.771 + }
4.772 +
4.773 + /**
4.774 + * Gets the default port number of the protocol associated
4.775 + * with this <code>URL</code>. If the URL scheme or the URLStreamHandler
4.776 + * for the URL do not define a default port number,
4.777 + * then -1 is returned.
4.778 + *
4.779 + * @return the port number
4.780 + * @since 1.4
4.781 + */
4.782 + public int getDefaultPort() {
4.783 + return handler.getDefaultPort();
4.784 + }
4.785 +
4.786 + /**
4.787 + * Gets the protocol name of this <code>URL</code>.
4.788 + *
4.789 + * @return the protocol of this <code>URL</code>.
4.790 + */
4.791 + public String getProtocol() {
4.792 + return protocol;
4.793 + }
4.794 +
4.795 + /**
4.796 + * Gets the host name of this <code>URL</code>, if applicable.
4.797 + * The format of the host conforms to RFC 2732, i.e. for a
4.798 + * literal IPv6 address, this method will return the IPv6 address
4.799 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
4.800 + *
4.801 + * @return the host name of this <code>URL</code>.
4.802 + */
4.803 + public String getHost() {
4.804 + return host;
4.805 + }
4.806 +
4.807 + /**
4.808 + * Gets the file name of this <code>URL</code>.
4.809 + * The returned file portion will be
4.810 + * the same as <CODE>getPath()</CODE>, plus the concatenation of
4.811 + * the value of <CODE>getQuery()</CODE>, if any. If there is
4.812 + * no query portion, this method and <CODE>getPath()</CODE> will
4.813 + * return identical results.
4.814 + *
4.815 + * @return the file name of this <code>URL</code>,
4.816 + * or an empty string if one does not exist
4.817 + */
4.818 + public String getFile() {
4.819 + return file;
4.820 + }
4.821 +
4.822 + /**
4.823 + * Gets the anchor (also known as the "reference") of this
4.824 + * <code>URL</code>.
4.825 + *
4.826 + * @return the anchor (also known as the "reference") of this
4.827 + * <code>URL</code>, or <CODE>null</CODE> if one does not exist
4.828 + */
4.829 + public String getRef() {
4.830 + return ref;
4.831 + }
4.832 +
4.833 + /**
4.834 + * Compares this URL for equality with another object.<p>
4.835 + *
4.836 + * If the given object is not a URL then this method immediately returns
4.837 + * <code>false</code>.<p>
4.838 + *
4.839 + * Two URL objects are equal if they have the same protocol, reference
4.840 + * equivalent hosts, have the same port number on the host, and the same
4.841 + * file and fragment of the file.<p>
4.842 + *
4.843 + * Two hosts are considered equivalent if both host names can be resolved
4.844 + * into the same IP addresses; else if either host name can't be
4.845 + * resolved, the host names must be equal without regard to case; or both
4.846 + * host names equal to null.<p>
4.847 + *
4.848 + * Since hosts comparison requires name resolution, this operation is a
4.849 + * blocking operation. <p>
4.850 + *
4.851 + * Note: The defined behavior for <code>equals</code> is known to
4.852 + * be inconsistent with virtual hosting in HTTP.
4.853 + *
4.854 + * @param obj the URL to compare against.
4.855 + * @return <code>true</code> if the objects are the same;
4.856 + * <code>false</code> otherwise.
4.857 + */
4.858 + public boolean equals(Object obj) {
4.859 + if (!(obj instanceof URL))
4.860 + return false;
4.861 + URL u2 = (URL)obj;
4.862 +
4.863 + return handler.equals(this, u2);
4.864 + }
4.865 +
4.866 + /**
4.867 + * Creates an integer suitable for hash table indexing.<p>
4.868 + *
4.869 + * The hash code is based upon all the URL components relevant for URL
4.870 + * comparison. As such, this operation is a blocking operation.<p>
4.871 + *
4.872 + * @return a hash code for this <code>URL</code>.
4.873 + */
4.874 + public synchronized int hashCode() {
4.875 + if (hashCode != -1)
4.876 + return hashCode;
4.877 +
4.878 + hashCode = handler.hashCode(this);
4.879 + return hashCode;
4.880 + }
4.881 +
4.882 + /**
4.883 + * Compares two URLs, excluding the fragment component.<p>
4.884 + *
4.885 + * Returns <code>true</code> if this <code>URL</code> and the
4.886 + * <code>other</code> argument are equal without taking the
4.887 + * fragment component into consideration.
4.888 + *
4.889 + * @param other the <code>URL</code> to compare against.
4.890 + * @return <code>true</code> if they reference the same remote object;
4.891 + * <code>false</code> otherwise.
4.892 + */
4.893 + public boolean sameFile(URL other) {
4.894 + return handler.sameFile(this, other);
4.895 + }
4.896 +
4.897 + /**
4.898 + * Constructs a string representation of this <code>URL</code>. The
4.899 + * string is created by calling the <code>toExternalForm</code>
4.900 + * method of the stream protocol handler for this object.
4.901 + *
4.902 + * @return a string representation of this object.
4.903 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
4.904 + * java.lang.String)
4.905 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
4.906 + */
4.907 + public String toString() {
4.908 + return toExternalForm();
4.909 + }
4.910 +
4.911 + /**
4.912 + * Constructs a string representation of this <code>URL</code>. The
4.913 + * string is created by calling the <code>toExternalForm</code>
4.914 + * method of the stream protocol handler for this object.
4.915 + *
4.916 + * @return a string representation of this object.
4.917 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.918 + * int, java.lang.String)
4.919 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
4.920 + */
4.921 + public String toExternalForm() {
4.922 + return handler.toExternalForm(this);
4.923 + }
4.924 +
4.925 + /**
4.926 + * Returns a {@link java.net.URI} equivalent to this URL.
4.927 + * This method functions in the same way as <code>new URI (this.toString())</code>.
4.928 + * <p>Note, any URL instance that complies with RFC 2396 can be converted
4.929 + * to a URI. However, some URLs that are not strictly in compliance
4.930 + * can not be converted to a URI.
4.931 + *
4.932 + * @exception URISyntaxException if this URL is not formatted strictly according to
4.933 + * to RFC2396 and cannot be converted to a URI.
4.934 + *
4.935 + * @return a URI instance equivalent to this URL.
4.936 + * @since 1.5
4.937 + */
4.938 + public URI toURI() throws URISyntaxException {
4.939 + return new URI (toString());
4.940 + }
4.941 +
4.942 + /**
4.943 + * Returns a {@link java.net.URLConnection URLConnection} instance that
4.944 + * represents a connection to the remote object referred to by the
4.945 + * {@code URL}.
4.946 + *
4.947 + * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
4.948 + * created every time when invoking the
4.949 + * {@linkplain java.net.URLStreamHandler#openConnection(URL)
4.950 + * URLStreamHandler.openConnection(URL)} method of the protocol handler for
4.951 + * this URL.</P>
4.952 + *
4.953 + * <P>It should be noted that a URLConnection instance does not establish
4.954 + * the actual network connection on creation. This will happen only when
4.955 + * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
4.956 + *
4.957 + * <P>If for the URL's protocol (such as HTTP or JAR), there
4.958 + * exists a public, specialized URLConnection subclass belonging
4.959 + * to one of the following packages or one of their subpackages:
4.960 + * java.lang, java.io, java.util, java.net, the connection
4.961 + * returned will be of that subclass. For example, for HTTP an
4.962 + * HttpURLConnection will be returned, and for JAR a
4.963 + * JarURLConnection will be returned.</P>
4.964 + *
4.965 + * @return a {@link java.net.URLConnection URLConnection} linking
4.966 + * to the URL.
4.967 + * @exception IOException if an I/O exception occurs.
4.968 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.969 + * int, java.lang.String)
4.970 + */
4.971 + public URLConnection openConnection() throws java.io.IOException {
4.972 + return handler.openConnection(this);
4.973 + }
4.974 +
4.975 + /**
4.976 + * Same as {@link #openConnection()}, except that the connection will be
4.977 + * made through the specified proxy; Protocol handlers that do not
4.978 + * support proxing will ignore the proxy parameter and make a
4.979 + * normal connection.
4.980 + *
4.981 + * Invoking this method preempts the system's default ProxySelector
4.982 + * settings.
4.983 + *
4.984 + * @param proxy the Proxy through which this connection
4.985 + * will be made. If direct connection is desired,
4.986 + * Proxy.NO_PROXY should be specified.
4.987 + * @return a <code>URLConnection</code> to the URL.
4.988 + * @exception IOException if an I/O exception occurs.
4.989 + * @exception SecurityException if a security manager is present
4.990 + * and the caller doesn't have permission to connect
4.991 + * to the proxy.
4.992 + * @exception IllegalArgumentException will be thrown if proxy is null,
4.993 + * or proxy has the wrong type
4.994 + * @exception UnsupportedOperationException if the subclass that
4.995 + * implements the protocol handler doesn't support
4.996 + * this method.
4.997 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.998 + * int, java.lang.String)
4.999 + * @see java.net.URLConnection
4.1000 + * @see java.net.URLStreamHandler#openConnection(java.net.URL,
4.1001 + * java.net.Proxy)
4.1002 + * @since 1.5
4.1003 + */
4.1004 + public URLConnection openConnection(Proxy proxy)
4.1005 + throws java.io.IOException {
4.1006 + if (proxy == null) {
4.1007 + throw new IllegalArgumentException("proxy can not be null");
4.1008 + }
4.1009 +
4.1010 + // Create a copy of Proxy as a security measure
4.1011 + Proxy p = proxy == Proxy.NO_PROXY ? Proxy.NO_PROXY : sun.net.ApplicationProxy.create(proxy);
4.1012 + SecurityManager sm = System.getSecurityManager();
4.1013 + if (p.type() != Proxy.Type.DIRECT && sm != null) {
4.1014 + InetSocketAddress epoint = (InetSocketAddress) p.address();
4.1015 + if (epoint.isUnresolved())
4.1016 + sm.checkConnect(epoint.getHostName(), epoint.getPort());
4.1017 + else
4.1018 + sm.checkConnect(epoint.getAddress().getHostAddress(),
4.1019 + epoint.getPort());
4.1020 + }
4.1021 + return handler.openConnection(this, p);
4.1022 + }
4.1023 +
4.1024 + /**
4.1025 + * Opens a connection to this <code>URL</code> and returns an
4.1026 + * <code>InputStream</code> for reading from that connection. This
4.1027 + * method is a shorthand for:
4.1028 + * <blockquote><pre>
4.1029 + * openConnection().getInputStream()
4.1030 + * </pre></blockquote>
4.1031 + *
4.1032 + * @return an input stream for reading from the URL connection.
4.1033 + * @exception IOException if an I/O exception occurs.
4.1034 + * @see java.net.URL#openConnection()
4.1035 + * @see java.net.URLConnection#getInputStream()
4.1036 + */
4.1037 + public final InputStream openStream() throws java.io.IOException {
4.1038 + return openConnection().getInputStream();
4.1039 + }
4.1040 +
4.1041 + /**
4.1042 + * Gets the contents of this URL. This method is a shorthand for:
4.1043 + * <blockquote><pre>
4.1044 + * openConnection().getContent()
4.1045 + * </pre></blockquote>
4.1046 + *
4.1047 + * @return the contents of this URL.
4.1048 + * @exception IOException if an I/O exception occurs.
4.1049 + * @see java.net.URLConnection#getContent()
4.1050 + */
4.1051 + public final Object getContent() throws java.io.IOException {
4.1052 + return openConnection().getContent();
4.1053 + }
4.1054 +
4.1055 + /**
4.1056 + * Gets the contents of this URL. This method is a shorthand for:
4.1057 + * <blockquote><pre>
4.1058 + * openConnection().getContent(Class[])
4.1059 + * </pre></blockquote>
4.1060 + *
4.1061 + * @param classes an array of Java types
4.1062 + * @return the content object of this URL that is the first match of
4.1063 + * the types specified in the classes array.
4.1064 + * null if none of the requested types are supported.
4.1065 + * @exception IOException if an I/O exception occurs.
4.1066 + * @see java.net.URLConnection#getContent(Class[])
4.1067 + * @since 1.3
4.1068 + */
4.1069 + public final Object getContent(Class[] classes)
4.1070 + throws java.io.IOException {
4.1071 + return openConnection().getContent(classes);
4.1072 + }
4.1073 +
4.1074 + /**
4.1075 + * The URLStreamHandler factory.
4.1076 + */
4.1077 + static URLStreamHandlerFactory factory;
4.1078 +
4.1079 + /**
4.1080 + * Sets an application's <code>URLStreamHandlerFactory</code>.
4.1081 + * This method can be called at most once in a given Java Virtual
4.1082 + * Machine.
4.1083 + *
4.1084 + *<p> The <code>URLStreamHandlerFactory</code> instance is used to
4.1085 + *construct a stream protocol handler from a protocol name.
4.1086 + *
4.1087 + * <p> If there is a security manager, this method first calls
4.1088 + * the security manager's <code>checkSetFactory</code> method
4.1089 + * to ensure the operation is allowed.
4.1090 + * This could result in a SecurityException.
4.1091 + *
4.1092 + * @param fac the desired factory.
4.1093 + * @exception Error if the application has already set a factory.
4.1094 + * @exception SecurityException if a security manager exists and its
4.1095 + * <code>checkSetFactory</code> method doesn't allow
4.1096 + * the operation.
4.1097 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
4.1098 + * int, java.lang.String)
4.1099 + * @see java.net.URLStreamHandlerFactory
4.1100 + * @see SecurityManager#checkSetFactory
4.1101 + */
4.1102 + public static void setURLStreamHandlerFactory(URLStreamHandlerFactory fac) {
4.1103 + synchronized (streamHandlerLock) {
4.1104 + if (factory != null) {
4.1105 + throw new Error("factory already defined");
4.1106 + }
4.1107 + SecurityManager security = System.getSecurityManager();
4.1108 + if (security != null) {
4.1109 + security.checkSetFactory();
4.1110 + }
4.1111 + handlers.clear();
4.1112 + factory = fac;
4.1113 + }
4.1114 + }
4.1115 +
4.1116 + /**
4.1117 + * A table of protocol handlers.
4.1118 + */
4.1119 + static Hashtable handlers = new Hashtable();
4.1120 + private static Object streamHandlerLock = new Object();
4.1121 +
4.1122 + /**
4.1123 + * Returns the Stream Handler.
4.1124 + * @param protocol the protocol to use
4.1125 + */
4.1126 + static URLStreamHandler getURLStreamHandler(String protocol) {
4.1127 +
4.1128 + URLStreamHandler handler = (URLStreamHandler)handlers.get(protocol);
4.1129 + if (handler == null) {
4.1130 +
4.1131 + boolean checkedWithFactory = false;
4.1132 +
4.1133 + // Use the factory (if any)
4.1134 + if (factory != null) {
4.1135 + handler = factory.createURLStreamHandler(protocol);
4.1136 + checkedWithFactory = true;
4.1137 + }
4.1138 +
4.1139 + // Try java protocol handler
4.1140 + if (handler == null) {
4.1141 + String packagePrefixList = null;
4.1142 +
4.1143 + packagePrefixList
4.1144 + = java.security.AccessController.doPrivileged(
4.1145 + new sun.security.action.GetPropertyAction(
4.1146 + protocolPathProp,""));
4.1147 + if (packagePrefixList != "") {
4.1148 + packagePrefixList += "|";
4.1149 + }
4.1150 +
4.1151 + // REMIND: decide whether to allow the "null" class prefix
4.1152 + // or not.
4.1153 + packagePrefixList += "sun.net.www.protocol";
4.1154 +
4.1155 + StringTokenizer packagePrefixIter =
4.1156 + new StringTokenizer(packagePrefixList, "|");
4.1157 +
4.1158 + while (handler == null &&
4.1159 + packagePrefixIter.hasMoreTokens()) {
4.1160 +
4.1161 + String packagePrefix =
4.1162 + packagePrefixIter.nextToken().trim();
4.1163 + try {
4.1164 + String clsName = packagePrefix + "." + protocol +
4.1165 + ".Handler";
4.1166 + Class cls = null;
4.1167 + try {
4.1168 + cls = Class.forName(clsName);
4.1169 + } catch (ClassNotFoundException e) {
4.1170 + ClassLoader cl = ClassLoader.getSystemClassLoader();
4.1171 + if (cl != null) {
4.1172 + cls = cl.loadClass(clsName);
4.1173 + }
4.1174 + }
4.1175 + if (cls != null) {
4.1176 + handler =
4.1177 + (URLStreamHandler)cls.newInstance();
4.1178 + }
4.1179 + } catch (Exception e) {
4.1180 + // any number of exceptions can get thrown here
4.1181 + }
4.1182 + }
4.1183 + }
4.1184 +
4.1185 + synchronized (streamHandlerLock) {
4.1186 +
4.1187 + URLStreamHandler handler2 = null;
4.1188 +
4.1189 + // Check again with hashtable just in case another
4.1190 + // thread created a handler since we last checked
4.1191 + handler2 = (URLStreamHandler)handlers.get(protocol);
4.1192 +
4.1193 + if (handler2 != null) {
4.1194 + return handler2;
4.1195 + }
4.1196 +
4.1197 + // Check with factory if another thread set a
4.1198 + // factory since our last check
4.1199 + if (!checkedWithFactory && factory != null) {
4.1200 + handler2 = factory.createURLStreamHandler(protocol);
4.1201 + }
4.1202 +
4.1203 + if (handler2 != null) {
4.1204 + // The handler from the factory must be given more
4.1205 + // importance. Discard the default handler that
4.1206 + // this thread created.
4.1207 + handler = handler2;
4.1208 + }
4.1209 +
4.1210 + // Insert this handler into the hashtable
4.1211 + if (handler != null) {
4.1212 + handlers.put(protocol, handler);
4.1213 + }
4.1214 +
4.1215 + }
4.1216 + }
4.1217 +
4.1218 + return handler;
4.1219 +
4.1220 + }
4.1221 +
4.1222 + /**
4.1223 + * WriteObject is called to save the state of the URL to an
4.1224 + * ObjectOutputStream. The handler is not saved since it is
4.1225 + * specific to this system.
4.1226 + *
4.1227 + * @serialData the default write object value. When read back in,
4.1228 + * the reader must ensure that calling getURLStreamHandler with
4.1229 + * the protocol variable returns a valid URLStreamHandler and
4.1230 + * throw an IOException if it does not.
4.1231 + */
4.1232 + private synchronized void writeObject(java.io.ObjectOutputStream s)
4.1233 + throws IOException
4.1234 + {
4.1235 + s.defaultWriteObject(); // write the fields
4.1236 + }
4.1237 +
4.1238 + /**
4.1239 + * readObject is called to restore the state of the URL from the
4.1240 + * stream. It reads the components of the URL and finds the local
4.1241 + * stream handler.
4.1242 + */
4.1243 + private synchronized void readObject(java.io.ObjectInputStream s)
4.1244 + throws IOException, ClassNotFoundException
4.1245 + {
4.1246 + s.defaultReadObject(); // read the fields
4.1247 + if ((handler = getURLStreamHandler(protocol)) == null) {
4.1248 + throw new IOException("unknown protocol: " + protocol);
4.1249 + }
4.1250 +
4.1251 + // Construct authority part
4.1252 + if (authority == null &&
4.1253 + ((host != null && host.length() > 0) || port != -1)) {
4.1254 + if (host == null)
4.1255 + host = "";
4.1256 + authority = (port == -1) ? host : host + ":" + port;
4.1257 +
4.1258 + // Handle hosts with userInfo in them
4.1259 + int at = host.lastIndexOf('@');
4.1260 + if (at != -1) {
4.1261 + userInfo = host.substring(0, at);
4.1262 + host = host.substring(at+1);
4.1263 + }
4.1264 + } else if (authority != null) {
4.1265 + // Construct user info part
4.1266 + int ind = authority.indexOf('@');
4.1267 + if (ind != -1)
4.1268 + userInfo = authority.substring(0, ind);
4.1269 + }
4.1270 +
4.1271 + // Construct path and query part
4.1272 + path = null;
4.1273 + query = null;
4.1274 + if (file != null) {
4.1275 + // Fix: only do this if hierarchical?
4.1276 + int q = file.lastIndexOf('?');
4.1277 + if (q != -1) {
4.1278 + query = file.substring(q+1);
4.1279 + path = file.substring(0, q);
4.1280 + } else
4.1281 + path = file;
4.1282 + }
4.1283 + }
4.1284 +}
4.1285 +
4.1286 +class Parts {
4.1287 + String path, query, ref;
4.1288 +
4.1289 + Parts(String file) {
4.1290 + int ind = file.indexOf('#');
4.1291 + ref = ind < 0 ? null: file.substring(ind + 1);
4.1292 + file = ind < 0 ? file: file.substring(0, ind);
4.1293 + int q = file.lastIndexOf('?');
4.1294 + if (q != -1) {
4.1295 + query = file.substring(q+1);
4.1296 + path = file.substring(0, q);
4.1297 + } else {
4.1298 + path = file;
4.1299 + }
4.1300 + }
4.1301 +
4.1302 + String getPath() {
4.1303 + return path;
4.1304 + }
4.1305 +
4.1306 + String getQuery() {
4.1307 + return query;
4.1308 + }
4.1309 +
4.1310 + String getRef() {
4.1311 + return ref;
4.1312 + }
4.1313 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/emul/src/main/java/java/util/Enumeration.java Tue Oct 30 09:05:33 2012 +0100
5.3 @@ -0,0 +1,79 @@
5.4 +/*
5.5 + * Copyright (c) 1994, 2005, 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.util;
5.30 +
5.31 +/**
5.32 + * An object that implements the Enumeration interface generates a
5.33 + * series of elements, one at a time. Successive calls to the
5.34 + * <code>nextElement</code> method return successive elements of the
5.35 + * series.
5.36 + * <p>
5.37 + * For example, to print all elements of a <tt>Vector<E></tt> <i>v</i>:
5.38 + * <pre>
5.39 + * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
5.40 + * System.out.println(e.nextElement());</pre>
5.41 + * <p>
5.42 + * Methods are provided to enumerate through the elements of a
5.43 + * vector, the keys of a hashtable, and the values in a hashtable.
5.44 + * Enumerations are also used to specify the input streams to a
5.45 + * <code>SequenceInputStream</code>.
5.46 + * <p>
5.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
5.48 + * interface. In addition, Iterator adds an optional remove operation, and
5.49 + * has shorter method names. New implementations should consider using
5.50 + * Iterator in preference to Enumeration.
5.51 + *
5.52 + * @see java.util.Iterator
5.53 + * @see java.io.SequenceInputStream
5.54 + * @see java.util.Enumeration#nextElement()
5.55 + * @see java.util.Hashtable
5.56 + * @see java.util.Hashtable#elements()
5.57 + * @see java.util.Hashtable#keys()
5.58 + * @see java.util.Vector
5.59 + * @see java.util.Vector#elements()
5.60 + *
5.61 + * @author Lee Boynton
5.62 + * @since JDK1.0
5.63 + */
5.64 +public interface Enumeration<E> {
5.65 + /**
5.66 + * Tests if this enumeration contains more elements.
5.67 + *
5.68 + * @return <code>true</code> if and only if this enumeration object
5.69 + * contains at least one more element to provide;
5.70 + * <code>false</code> otherwise.
5.71 + */
5.72 + boolean hasMoreElements();
5.73 +
5.74 + /**
5.75 + * Returns the next element of this enumeration if this enumeration
5.76 + * object has at least one more element to provide.
5.77 + *
5.78 + * @return the next element of this enumeration.
5.79 + * @exception NoSuchElementException if no more elements exist.
5.80 + */
5.81 + E nextElement();
5.82 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/src/main/java/java/util/NoSuchElementException.java Tue Oct 30 09:05:33 2012 +0100
6.3 @@ -0,0 +1,60 @@
6.4 +/*
6.5 + * Copyright (c) 1994, 2008, 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 + * Thrown by the <code>nextElement</code> method of an
6.33 + * <code>Enumeration</code> to indicate that there are no more
6.34 + * elements in the enumeration.
6.35 + *
6.36 + * @author unascribed
6.37 + * @see java.util.Enumeration
6.38 + * @see java.util.Enumeration#nextElement()
6.39 + * @since JDK1.0
6.40 + */
6.41 +public
6.42 +class NoSuchElementException extends RuntimeException {
6.43 + private static final long serialVersionUID = 6769829250639411880L;
6.44 +
6.45 + /**
6.46 + * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
6.47 + * as its error message string.
6.48 + */
6.49 + public NoSuchElementException() {
6.50 + super();
6.51 + }
6.52 +
6.53 + /**
6.54 + * Constructs a <code>NoSuchElementException</code>, saving a reference
6.55 + * to the error message string <tt>s</tt> for later retrieval by the
6.56 + * <tt>getMessage</tt> method.
6.57 + *
6.58 + * @param s the detail message.
6.59 + */
6.60 + public NoSuchElementException(String s) {
6.61 + super(s);
6.62 + }
6.63 +}