# HG changeset patch
# User Jaroslav Tulach Applications that need to define a subclass of A subclass must provide an implementation of this method.
+ *
+ * @return the next byte of data, or If the length of The first byte read is stored into element The This method blocks until input data is available, end of file is
+ * detected, or an exception is thrown.
+ *
+ * If The first byte read is stored into element In every case, elements The The Note that while some implementations of {@code InputStream} will return
+ * the total number of bytes in the stream, many will not. It is
+ * never correct to use the return value of this method to allocate
+ * a buffer intended to hold all data in this stream.
+ *
+ * A subclass' implementation of this method may choose to throw an
+ * {@link IOException} if this input stream has been closed by
+ * invoking the {@link #close()} method.
+ *
+ * The {@code available} method for class {@code InputStream} always
+ * returns {@code 0}.
+ *
+ * This method should be overridden by subclasses.
+ *
+ * @return an estimate of the number of bytes that can be read (or skipped
+ * over) from this input stream without blocking or {@code 0} when
+ * it reaches the end of the input stream.
+ * @exception IOException if an I/O error occurs.
+ */
+ public int available() throws IOException {
+ return 0;
+ }
+
+ /**
+ * Closes this input stream and releases any system resources associated
+ * with the stream.
+ *
+ * The The The general contract of Marking a closed stream should not have any effect on the stream.
+ *
+ * The The general contract of The method While this interface method is declared to throw {@code
+ * Exception}, implementers are strongly encouraged to
+ * declare concrete implementations of the {@code close} method to
+ * throw more specific exceptions, or to throw no exception at all
+ * if the close operation cannot fail.
+ *
+ * Implementers of this interface are also strongly advised
+ * to not have the {@code close} method throw {@link
+ * InterruptedException}.
+ *
+ * This exception interacts with a thread's interrupted status,
+ * and runtime misbehavior is likely to occur if an {@code
+ * InterruptedException} is {@linkplain Throwable#addSuppressed
+ * suppressed}.
+ *
+ * More generally, if it would cause problems for an
+ * exception to be suppressed, the {@code AutoCloseable.close}
+ * method should not throw it.
+ *
+ * Note that unlike the {@link java.io.Closeable#close close}
+ * method of {@link java.io.Closeable}, this {@code close} method
+ * is not required to be idempotent. In other words,
+ * calling this {@code close} method more than once may have some
+ * visible side effect, unlike {@code Closeable.close} which is
+ * required to have no effect if called more than once.
+ *
+ * However, implementers of this interface are strongly encouraged
+ * to make their {@code close} methods idempotent.
+ *
+ * @throws Exception if this resource cannot be closed
+ */
+ void close() throws Exception;
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/lang/Class.java
--- a/emul/src/main/java/java/lang/Class.java Mon Oct 29 13:05:56 2012 +0100
+++ b/emul/src/main/java/java/lang/Class.java Tue Oct 30 09:24:41 2012 +0100
@@ -25,6 +25,7 @@
package java.lang;
+import java.io.InputStream;
import java.lang.annotation.Annotation;
/**
@@ -552,15 +553,15 @@
* @throws NullPointerException If {@code name} is {@code null}
* @since JDK1.1
*/
-// public InputStream getResourceAsStream(String name) {
-// name = resolveName(name);
-// ClassLoader cl = getClassLoader0();
-// if (cl==null) {
-// // A system class.
-// return ClassLoader.getSystemResourceAsStream(name);
-// }
-// return cl.getResourceAsStream(name);
-// }
+ public InputStream getResourceAsStream(String name) {
+ name = resolveName(name);
+ ClassLoader cl = getClassLoader0();
+ if (cl==null) {
+ // A system class.
+ return ClassLoader.getSystemResourceAsStream(name);
+ }
+ return cl.getResourceAsStream(name);
+ }
/**
* Finds a resource with a given name. The rules for searching resources
@@ -596,18 +597,86 @@
* resource with this name is found
* @since JDK1.1
*/
-// public java.net.URL getResource(String name) {
-// name = resolveName(name);
-// ClassLoader cl = getClassLoader0();
-// if (cl==null) {
-// // A system class.
-// return ClassLoader.getSystemResource(name);
-// }
-// return cl.getResource(name);
-// }
+ public java.net.URL getResource(String name) {
+ name = resolveName(name);
+ ClassLoader cl = getClassLoader0();
+ if (cl==null) {
+ // A system class.
+ return ClassLoader.getSystemResource(name);
+ }
+ return cl.getResource(name);
+ }
+ /**
+ * Add a package name prefix if the name is not absolute Remove leading "/"
+ * if name is absolute
+ */
+ private String resolveName(String name) {
+ if (name == null) {
+ return name;
+ }
+ if (!name.startsWith("/")) {
+ Class> c = this;
+ while (c.isArray()) {
+ c = c.getComponentType();
+ }
+ String baseName = c.getName();
+ int index = baseName.lastIndexOf('.');
+ if (index != -1) {
+ name = baseName.substring(0, index).replace('.', '/')
+ +"/"+name;
+ }
+ } else {
+ name = name.substring(1);
+ }
+ return name;
+ }
+
+ /**
+ * Returns the class loader for the class. Some implementations may use
+ * null to represent the bootstrap class loader. This method will return
+ * null in such implementations if this class was loaded by the bootstrap
+ * class loader.
+ *
+ * If a security manager is present, and the caller's class loader is
+ * not null and the caller's class loader is not the same as or an ancestor of
+ * the class loader for the class whose class loader is requested, then
+ * this method calls the security manager's {@code checkPermission}
+ * method with a {@code RuntimePermission("getClassLoader")}
+ * permission to ensure it's ok to access the class loader for the class.
+ *
+ * If this object
+ * represents a primitive type or void, null is returned.
+ *
+ * @return the class loader that loaded the class or interface
+ * represented by this object.
+ * @throws SecurityException
+ * if a security manager exists and its
+ * {@code checkPermission} method denies
+ * access to the class loader for the class.
+ * @see java.lang.ClassLoader
+ * @see SecurityManager#checkPermission
+ * @see java.lang.RuntimePermission
+ */
+ public ClassLoader getClassLoader() {
+ throw new SecurityException();
+ }
+
+ // Package-private to allow ClassLoader access
+ native ClassLoader getClassLoader0();
+ /**
+ * Returns the {@code Class} representing the component type of an
+ * array. If this class does not represent an array class this method
+ * returns null.
+ *
+ * @return the {@code Class} representing the component type of this
+ * class if this class is an array
+ * @see java.lang.reflect.Array
+ * @since JDK1.1
+ */
+ public native Class> getComponentType();
/**
* Returns true if and only if this class was declared as an enum in the
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/lang/ClassFormatError.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/lang/ClassFormatError.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.lang;
+
+/**
+ * Thrown when the Java Virtual Machine attempts to read a class
+ * file and determines that the file is malformed or otherwise cannot
+ * be interpreted as a class file.
+ *
+ * @author unascribed
+ * @since JDK1.0
+ */
+public
+class ClassFormatError extends LinkageError {
+ private static final long serialVersionUID = -8420114879011949195L;
+
+ /**
+ * Constructs a Every {@link Class Class} object contains a {@link
+ * Class#getClassLoader() reference} to the ClassLoader that defined
+ * it.
+ *
+ * Class objects for array classes are not created by class
+ * loaders, but are created automatically as required by the Java runtime.
+ * The class loader for an array class, as returned by {@link
+ * Class#getClassLoader()} is the same as the class loader for its element
+ * type; if the element type is a primitive type, then the array class has no
+ * class loader.
+ *
+ * Applications implement subclasses of ClassLoader in order to
+ * extend the manner in which the Java virtual machine dynamically loads
+ * classes.
+ *
+ * Class loaders may typically be used by security managers to indicate
+ * security domains.
+ *
+ * The ClassLoader class uses a delegation model to search for
+ * classes and resources. Each instance of ClassLoader has an
+ * associated parent class loader. When requested to find a class or
+ * resource, a ClassLoader instance will delegate the search for the
+ * class or resource to its parent class loader before attempting to find the
+ * class or resource itself. The virtual machine's built-in class loader,
+ * called the "bootstrap class loader", does not itself have a parent but may
+ * serve as the parent of a ClassLoader instance.
+ *
+ * Class loaders that support concurrent loading of classes are known as
+ * parallel capable class loaders and are required to register
+ * themselves at their class initialization time by invoking the
+ * {@link
+ * #registerAsParallelCapable ClassLoader.registerAsParallelCapable}
+ * method. Note that the ClassLoader class is registered as parallel
+ * capable by default. However, its subclasses still need to register themselves
+ * if they are parallel capable. Normally, the Java virtual machine loads classes from the local file
+ * system in a platform-dependent manner. For example, on UNIX systems, the
+ * virtual machine loads classes from the directory defined by the
+ * CLASSPATH environment variable.
+ *
+ * However, some classes may not originate from a file; they may originate
+ * from other sources, such as the network, or they could be constructed by an
+ * application. The method {@link #defineClass(String, byte[], int, int)
+ * defineClass} converts an array of bytes into an instance of class
+ * Class. Instances of this newly defined class can be created using
+ * {@link Class#newInstance Class.newInstance}.
+ *
+ * The methods and constructors of objects created by a class loader may
+ * reference other classes. To determine the class(es) referred to, the Java
+ * virtual machine invokes the {@link #loadClass loadClass} method of
+ * the class loader that originally created the class.
+ *
+ * For example, an application could create a network class loader to
+ * download class files from a server. Sample code might look like:
+ *
+ * The network class loader subclass must define the methods {@link
+ * #findClass findClass} and loadClassData to load a class
+ * from the network. Once it has downloaded the bytes that make up the class,
+ * it should use the method {@link #defineClass defineClass} to
+ * create a class instance. A sample implementation is:
+ *
+ * Any class name provided as a {@link String} parameter to methods in
+ * ClassLoader must be a binary name as defined by
+ * The Java™ Language Specification.
+ *
+ * Examples of valid class names include:
+ * If there is a security manager, its {@link
+ * SecurityManager#checkCreateClassLoader()
+ * checkCreateClassLoader} method is invoked. This may result in
+ * a security exception. If there is a security manager, its {@link
+ * SecurityManager#checkCreateClassLoader()
+ * checkCreateClassLoader} method is invoked. This may result in
+ * a security exception. InputStream
+ * must always provide a method that returns the next byte of input.
+ *
+ * @author Arthur van Hoff
+ * @see java.io.BufferedInputStream
+ * @see java.io.ByteArrayInputStream
+ * @see java.io.DataInputStream
+ * @see java.io.FilterInputStream
+ * @see java.io.InputStream#read()
+ * @see java.io.OutputStream
+ * @see java.io.PushbackInputStream
+ * @since JDK1.0
+ */
+public abstract class InputStream implements Closeable {
+
+ // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
+ private static final int SKIP_BUFFER_SIZE = 2048;
+ // skipBuffer is initialized in skip(long), if needed.
+ private static byte[] skipBuffer;
+
+ /**
+ * Reads the next byte of data from the input stream. The value byte is
+ * returned as an int
in the range 0
to
+ * 255
. If no byte is available because the end of the stream
+ * has been reached, the value -1
is returned. This method
+ * blocks until input data is available, the end of the stream is detected,
+ * or an exception is thrown.
+ *
+ * -1
if the end of the
+ * stream is reached.
+ * @exception IOException if an I/O error occurs.
+ */
+ public abstract int read() throws IOException;
+
+ /**
+ * Reads some number of bytes from the input stream and stores them into
+ * the buffer array b
. The number of bytes actually read is
+ * returned as an integer. This method blocks until input data is
+ * available, end of file is detected, or an exception is thrown.
+ *
+ * b
is zero, then no bytes are read and
+ * 0
is returned; otherwise, there is an attempt to read at
+ * least one byte. If no byte is available because the stream is at the
+ * end of the file, the value -1
is returned; otherwise, at
+ * least one byte is read and stored into b
.
+ *
+ * b[0]
, the
+ * next one into b[1]
, and so on. The number of bytes read is,
+ * at most, equal to the length of b
. Let k be the
+ * number of bytes actually read; these bytes will be stored in elements
+ * b[0]
through b[
k-1]
,
+ * leaving elements b[
k]
through
+ * b[b.length-1]
unaffected.
+ *
+ * read(b)
method for class InputStream
+ * has the same effect as:
+ *
+ * @param b the buffer into which the data is read.
+ * @return the total number of bytes read into the buffer, or
+ * read(b, 0, b.length)
-1
if there is no more data because the end of
+ * the stream has been reached.
+ * @exception IOException If the first byte cannot be read for any reason
+ * other than the end of the file, if the input stream has been closed, or
+ * if some other I/O error occurs.
+ * @exception NullPointerException if b
is null
.
+ * @see java.io.InputStream#read(byte[], int, int)
+ */
+ public int read(byte b[]) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ /**
+ * Reads up to len
bytes of data from the input stream into
+ * an array of bytes. An attempt is made to read as many as
+ * len
bytes, but a smaller number may be read.
+ * The number of bytes actually read is returned as an integer.
+ *
+ * len
is zero, then no bytes are read and
+ * 0
is returned; otherwise, there is an attempt to read at
+ * least one byte. If no byte is available because the stream is at end of
+ * file, the value -1
is returned; otherwise, at least one
+ * byte is read and stored into b
.
+ *
+ * b[off]
, the
+ * next one into b[off+1]
, and so on. The number of bytes read
+ * is, at most, equal to len
. Let k be the number of
+ * bytes actually read; these bytes will be stored in elements
+ * b[off]
through b[off+
k-1]
,
+ * leaving elements b[off+
k]
through
+ * b[off+len-1]
unaffected.
+ *
+ * b[0]
through
+ * b[off]
and elements b[off+len]
through
+ * b[b.length-1]
are unaffected.
+ *
+ * read(b,
off,
len)
method
+ * for class InputStream
simply calls the method
+ * read()
repeatedly. If the first such call results in an
+ * IOException
, that exception is returned from the call to
+ * the read(b,
off,
len)
method. If
+ * any subsequent call to read()
results in a
+ * IOException
, the exception is caught and treated as if it
+ * were end of file; the bytes read up to that point are stored into
+ * b
and the number of bytes read before the exception
+ * occurred is returned. The default implementation of this method blocks
+ * until the requested amount of input data len
has been read,
+ * end of file is detected, or an exception is thrown. Subclasses are encouraged
+ * to provide a more efficient implementation of this method.
+ *
+ * @param b the buffer into which the data is read.
+ * @param off the start offset in array b
+ * at which the data is written.
+ * @param len the maximum number of bytes to read.
+ * @return the total number of bytes read into the buffer, or
+ * -1
if there is no more data because the end of
+ * the stream has been reached.
+ * @exception IOException If the first byte cannot be read for any reason
+ * other than end of file, or if the input stream has been closed, or if
+ * some other I/O error occurs.
+ * @exception NullPointerException If b
is null
.
+ * @exception IndexOutOfBoundsException If off
is negative,
+ * len
is negative, or len
is greater than
+ * b.length - off
+ * @see java.io.InputStream#read()
+ */
+ public int read(byte b[], int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if (off < 0 || len < 0 || len > b.length - off) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ int c = read();
+ if (c == -1) {
+ return -1;
+ }
+ b[off] = (byte)c;
+
+ int i = 1;
+ try {
+ for (; i < len ; i++) {
+ c = read();
+ if (c == -1) {
+ break;
+ }
+ b[off + i] = (byte)c;
+ }
+ } catch (IOException ee) {
+ }
+ return i;
+ }
+
+ /**
+ * Skips over and discards n
bytes of data from this input
+ * stream. The skip
method may, for a variety of reasons, end
+ * up skipping over some smaller number of bytes, possibly 0
.
+ * This may result from any of a number of conditions; reaching end of file
+ * before n
bytes have been skipped is only one possibility.
+ * The actual number of bytes skipped is returned. If n
is
+ * negative, no bytes are skipped.
+ *
+ * skip
method of this class creates a
+ * byte array and then repeatedly reads into it until n
bytes
+ * have been read or the end of the stream has been reached. Subclasses are
+ * encouraged to provide a more efficient implementation of this method.
+ * For instance, the implementation may depend on the ability to seek.
+ *
+ * @param n the number of bytes to be skipped.
+ * @return the actual number of bytes skipped.
+ * @exception IOException if the stream does not support seek,
+ * or if some other I/O error occurs.
+ */
+ public long skip(long n) throws IOException {
+
+ long remaining = n;
+ int nr;
+ if (skipBuffer == null)
+ skipBuffer = new byte[SKIP_BUFFER_SIZE];
+
+ byte[] localSkipBuffer = skipBuffer;
+
+ if (n <= 0) {
+ return 0;
+ }
+
+ while (remaining > 0) {
+ nr = read(localSkipBuffer, 0,
+ (int) Math.min(SKIP_BUFFER_SIZE, remaining));
+ if (nr < 0) {
+ break;
+ }
+ remaining -= nr;
+ }
+
+ return n - remaining;
+ }
+
+ /**
+ * Returns an estimate of the number of bytes that can be read (or
+ * skipped over) from this input stream without blocking by the next
+ * invocation of a method for this input stream. The next invocation
+ * might be the same thread or another thread. A single read or skip of this
+ * many bytes will not block, but may read or skip fewer bytes.
+ *
+ * close
method of InputStream
does
+ * nothing.
+ *
+ * @exception IOException if an I/O error occurs.
+ */
+ public void close() throws IOException {}
+
+ /**
+ * Marks the current position in this input stream. A subsequent call to
+ * the reset
method repositions this stream at the last marked
+ * position so that subsequent reads re-read the same bytes.
+ *
+ * readlimit
arguments tells this input stream to
+ * allow that many bytes to be read before the mark position gets
+ * invalidated.
+ *
+ * mark
is that, if the method
+ * markSupported
returns true
, the stream somehow
+ * remembers all the bytes read after the call to mark
and
+ * stands ready to supply those same bytes again if and whenever the method
+ * reset
is called. However, the stream is not required to
+ * remember any data at all if more than readlimit
bytes are
+ * read from the stream before reset
is called.
+ *
+ * mark
method of InputStream
does
+ * nothing.
+ *
+ * @param readlimit the maximum limit of bytes that can be read before
+ * the mark position becomes invalid.
+ * @see java.io.InputStream#reset()
+ */
+ public synchronized void mark(int readlimit) {}
+
+ /**
+ * Repositions this stream to the position at the time the
+ * mark
method was last called on this input stream.
+ *
+ * reset
is:
+ *
+ *
+ *
+ *
+ *
+ * markSupported
returns
+ * true
, then:
+ *
+ *
+ *
+ * mark
has not been called since
+ * the stream was created, or the number of bytes read from the stream
+ * since mark
was last called is larger than the argument
+ * to mark
at that last call, then an
+ * IOException
might be thrown.
+ *
+ * IOException
is not thrown, then the
+ * stream is reset to a state such that all the bytes read since the
+ * most recent call to mark
(or since the start of the
+ * file, if mark
has not been called) will be resupplied
+ * to subsequent callers of the read
method, followed by
+ * any bytes that otherwise would have been the next input data as of
+ * the time of the call to reset
. markSupported
returns
+ * false
, then:
+ *
+ * reset
may throw an
+ * IOException
.
+ *
+ * IOException
is not thrown, then the stream
+ * is reset to a fixed state that depends on the particular type of the
+ * input stream and how it was created. The bytes that will be supplied
+ * to subsequent callers of the read
method depend on the
+ * particular type of the input stream. reset
for class InputStream
+ * does nothing except throw an IOException
.
+ *
+ * @exception IOException if this stream has not been marked or if the
+ * mark has been invalidated.
+ * @see java.io.InputStream#mark(int)
+ * @see java.io.IOException
+ */
+ public synchronized void reset() throws IOException {
+ throw new IOException("mark/reset not supported");
+ }
+
+ /**
+ * Tests if this input stream supports the mark
and
+ * reset
methods. Whether or not mark
and
+ * reset
are supported is an invariant property of a
+ * particular input stream instance. The markSupported
method
+ * of InputStream
returns false
.
+ *
+ * @return true
if this stream instance supports the mark
+ * and reset methods; false
otherwise.
+ * @see java.io.InputStream#mark(int)
+ * @see java.io.InputStream#reset()
+ */
+ public boolean markSupported() {
+ return false;
+ }
+
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/lang/AutoCloseable.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/lang/AutoCloseable.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.lang;
+
+/**
+ * A resource that must be closed when it is no longer needed.
+ *
+ * @author Josh Bloch
+ * @since 1.7
+ */
+public interface AutoCloseable {
+ /**
+ * Closes this resource, relinquishing any underlying resources.
+ * This method is invoked automatically on objects managed by the
+ * {@code try}-with-resources statement.
+ *
+ * ClassFormatError
with no detail message.
+ */
+ public ClassFormatError() {
+ super();
+ }
+
+ /**
+ * Constructs a ClassFormatError
with the specified
+ * detail message.
+ *
+ * @param s the detail message.
+ */
+ public ClassFormatError(String s) {
+ super(s);
+ }
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/lang/ClassLoader.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/lang/ClassLoader.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,912 @@
+/*
+ * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package java.lang;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * A class loader is an object that is responsible for loading classes. The
+ * class ClassLoader is an abstract class. Given the binary name of a class, a class loader should attempt to
+ * locate or generate data that constitutes a definition for the class. A
+ * typical strategy is to transform the name into a file name and then read a
+ * "class file" of that name from a file system.
+ *
+ *
+ * In environments in which the delegation model is not strictly
+ * hierarchical, class loaders need to be parallel capable, otherwise class
+ * loading can lead to deadlocks because the loader lock is held for the
+ * duration of the class loading process (see {@link #loadClass
+ * loadClass} methods).
+ *
+ *
+ *
+ *
+ * ClassLoader loader = new NetworkClassLoader(host, port);
+ * Object main = loader.loadClass("Main", true).newInstance();
+ * . . .
+ *
+ *
+ *
+ * class NetworkClassLoader extends ClassLoader {
+ * String host;
+ * int port;
+ *
+ * public Class findClass(String name) {
+ * byte[] b = loadClassData(name);
+ * return defineClass(name, b, 0, b.length);
+ * }
+ *
+ * private byte[] loadClassData(String name) {
+ * // load the class data from the connection
+ * . . .
+ * }
+ * }
+ *
Binary names
+ *
+ *
+ *
+ * @see #resolveClass(Class)
+ * @since 1.0
+ */
+public abstract class ClassLoader {
+
+ private static native void registerNatives();
+ static {
+ registerNatives();
+ }
+
+ // The parent class loader for delegation
+ // Note: VM hardcoded the offset of this field, thus all new fields
+ // must be added *after* it.
+ private final ClassLoader parent;
+
+
+ /**
+ * Creates a new class loader using the specified parent class loader for
+ * delegation.
+ *
+ *
+ * "java.lang.String"
+ * "javax.swing.JSpinner$DefaultEditor"
+ * "java.security.KeyStore$Builder$FileBuilder$1"
+ * "java.net.URLClassLoader$3$1"
+ *
Invoke {@link #findLoadedClass(String)} to check if the class + * has already been loaded.
Invoke the {@link #loadClass(String) loadClass} method + * on the parent class loader. If the parent is null the class + * loader built-in to the virtual machine is used, instead.
Invoke the {@link #findClass(String)} method to find the + * class.
If the class was found using the above steps, and the + * resolve flag is true, this method will then invoke the {@link + * #resolveClass(Class)} method on the resulting Class object. + * + *
Subclasses of ClassLoader are encouraged to override {@link + * #findClass(String)}, rather than this method.
+ * + *Unless overridden, this method synchronizes on the result of + * {@link #getClassLoadingLock getClassLoadingLock} method + * during the entire class loading process. + * + * @param name + * The binary name of the class + * + * @param resolve + * If true then resolve the class + * + * @return The resulting Class object + * + * @throws ClassNotFoundException + * If the class could not be found + */ + protected Class> loadClass(String name, boolean resolve) + throws ClassNotFoundException + { + synchronized (getClassLoadingLock(name)) { + // First, check if the class has already been loaded + Class c = findLoadedClass(name); + if (c == null) { + try { + if (parent != null) { + c = parent.loadClass(name, false); + } else { + c = findBootstrapClassOrNull(name); + } + } catch (ClassNotFoundException e) { + // ClassNotFoundException thrown if class not found + // from the non-null parent class loader + } + + if (c == null) { + // If still not found, then invoke findClass in order + // to find the class. + c = findClass(name); + +// // this is the defining class loader; record the stats +// sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0); +// sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1); +// sun.misc.PerfCounter.getFindClasses().increment(); + } + } + if (resolve) { + resolveClass(c); + } + return c; + } + } + + /** + * Returns the lock object for class loading operations. + * For backward compatibility, the default implementation of this method + * behaves as follows. If this ClassLoader object is registered as + * parallel capable, the method returns a dedicated object associated + * with the specified class name. Otherwise, the method returns this + * ClassLoader object.
+ * + * @param className + * The name of the to-be-loaded class + * + * @return the lock for class loading operations + * + * @throws NullPointerException + * If registered as parallel capable and className is null + * + * @see #loadClass(String, boolean) + * + * @since 1.7 + */ + protected Object getClassLoadingLock(String className) { + Object lock = this; + return lock; + } + + /** + * Finds the class with the specified binary name. + * This method should be overridden by class loader implementations that + * follow the delegation model for loading classes, and will be invoked by + * the {@link #loadClass loadClass} method after checking the + * parent class loader for the requested class. The default implementation + * throws a ClassNotFoundException. + * + * @param name + * The binary name of the class + * + * @return The resulting Class object + * + * @throws ClassNotFoundException + * If the class could not be found + * + * @since 1.2 + */ + protected Class> findClass(String name) throws ClassNotFoundException { + throw new ClassNotFoundException(name); + } + + /** + * Converts an array of bytes into an instance of class Class. + * Before the Class can be used it must be resolved. This method + * is deprecated in favor of the version that takes a binary name as its first argument, and is more secure. + * + * @param b + * The bytes that make up the class data. The bytes in positions + * off through off+len-1 should have the format + * of a valid class file as defined by + * The Java™ Virtual Machine Specification. + * + * @param off + * The start offset in b of the class data + * + * @param len + * The length of the class data + * + * @return The Class object that was created from the specified + * class data + * + * @throws ClassFormatError + * If the data did not contain a valid class + * + * @throws IndexOutOfBoundsException + * If either off or len is negative, or if + * off+len is greater than b.length. + * + * @throws SecurityException + * If an attempt is made to add this class to a package that + * contains classes that were signed by a different set of + * certificates than this class, or if an attempt is made + * to define a class in a package with a fully-qualified name + * that starts with "{@code java.}". + * + * @see #loadClass(String, boolean) + * @see #resolveClass(Class) + * + * @deprecated Replaced by {@link #defineClass(String, byte[], int, int) + * defineClass(String, byte[], int, int)} + */ + @Deprecated + protected final Class> defineClass(byte[] b, int off, int len) + throws ClassFormatError + { + throw new SecurityException(); + } + + /** + * Converts an array of bytes into an instance of class Class. + * Before the Class can be used it must be resolved. + * + *This method assigns a default {@link java.security.ProtectionDomain + * ProtectionDomain} to the newly defined class. The + * ProtectionDomain is effectively granted the same set of + * permissions returned when {@link + * java.security.Policy#getPermissions(java.security.CodeSource) + * Policy.getPolicy().getPermissions(new CodeSource(null, null))} + * is invoked. The default domain is created on the first invocation of + * {@link #defineClass(String, byte[], int, int) defineClass}, + * and re-used on subsequent invocations. + * + *
To assign a specific ProtectionDomain to the class, use + * the {@link #defineClass(String, byte[], int, int, + * java.security.ProtectionDomain) defineClass} method that takes a + * ProtectionDomain as one of its arguments.
+ * + * @param name + * The expected binary name of the class, or + * null if not known + * + * @param b + * The bytes that make up the class data. The bytes in positions + * off through off+len-1 should have the format + * of a valid class file as defined by + * The Java™ Virtual Machine Specification. + * + * @param off + * The start offset in b of the class data + * + * @param len + * The length of the class data + * + * @return The Class object that was created from the specified + * class data. + * + * @throws ClassFormatError + * If the data did not contain a valid class + * + * @throws IndexOutOfBoundsException + * If either off or len is negative, or if + * off+len is greater than b.length. + * + * @throws SecurityException + * If an attempt is made to add this class to a package that + * contains classes that were signed by a different set of + * certificates than this class (which is unsigned), or if + * name begins with "java.". + * + * @see #loadClass(String, boolean) + * @see #resolveClass(Class) + * @see java.security.CodeSource + * @see java.security.SecureClassLoader + * + * @since 1.1 + */ + protected final Class> defineClass(String name, byte[] b, int off, int len) + throws ClassFormatError + { + throw new SecurityException(); + } + + /** + * Links the specified class. This (misleadingly named) method may be + * used by a class loader to link a class. If the class c has + * already been linked, then this method simply returns. Otherwise, the + * class is linked as described in the "Execution" chapter of + * The Java™ Language Specification. + * + * + * @param c + * The class to link + * + * @throws NullPointerException + * If c is null. + * + * @see #defineClass(String, byte[], int, int) + */ + protected final void resolveClass(Class> c) { + resolveClass0(c); + } + + private native void resolveClass0(Class c); + + + /** + * Returns the class with the given binary name if this + * loader has been recorded by the Java virtual machine as an initiating + * loader of a class with that binary name. Otherwise + * null is returned. + * + * @param name + * The binary name of the class + * + * @return The Class object, or null if the class has + * not been loaded + * + * @since 1.1 + */ + protected final Class> findLoadedClass(String name) { + if (!checkName(name)) + return null; + return findLoadedClass0(name); + } + + private native final Class findLoadedClass0(String name); + + /** + * Sets the signers of a class. This should be invoked after defining a + * class. + * + * @param c + * The Class object + * + * @param signers + * The signers for the class + * + * @since 1.1 + */ + protected final void setSigners(Class> c, Object[] signers) { + //c.setSigners(signers); + throw new UnsupportedOperationException(); + } + + + // -- Resource -- + + /** + * Finds the resource with the given name. A resource is some data + * (images, audio, text, etc) that can be accessed by class code in a way + * that is independent of the location of the code. + * + *The name of a resource is a '/'-separated path name that + * identifies the resource. + * + *
This method will first search the parent class loader for the + * resource; if the parent is null the path of the class loader + * built-in to the virtual machine is searched. That failing, this method + * will invoke {@link #findResource(String)} to find the resource.
+ * + * @param name + * The resource name + * + * @return A URL object for reading the resource, or + * null if the resource could not be found or the invoker + * doesn't have adequate privileges to get the resource. + * + * @since 1.1 + */ + public URL getResource(String name) { + URL url; + if (parent != null) { + url = parent.getResource(name); + } else { + url = getBootstrapResource(name); + } + if (url == null) { + url = findResource(name); + } + return url; + } + + /** + * Finds all the resources with the given name. A resource is some data + * (images, audio, text, etc) that can be accessed by class code in a way + * that is independent of the location of the code. + * + *The name of a resource is a /-separated path name that + * identifies the resource. + * + *
The search order is described in the documentation for {@link + * #getResource(String)}.
+ * + * @param name + * The resource name + * + * @return An enumeration of {@link java.net.URL URL} objects for + * the resource. If no resources could be found, the enumeration + * will be empty. Resources that the class loader doesn't have + * access to will not be in the enumeration. + * + * @throws IOException + * If I/O errors occur + * + * @see #findResources(String) + * + * @since 1.2 + */ + public EnumerationThe search order is described in the documentation for {@link + * #getSystemResource(String)}.
+ * + * @param name + * The resource name + * + * @return An enumeration of resource {@link java.net.URL URL} + * objects + * + * @throws IOException + * If I/O errors occur + + * @since 1.2 + */ + public static EnumerationThe search order is described in the documentation for {@link + * #getResource(String)}.
+ * + * @param name + * The resource name + * + * @return An input stream for reading the resource, or null + * if the resource could not be found + * + * @since 1.1 + */ + public InputStream getResourceAsStream(String name) { + URL url = getResource(name); + try { + return url != null ? url.openStream() : null; + } catch (IOException e) { + return null; + } + } + + /** + * Open for reading, a resource of the specified name from the search path + * used to load classes. This method locates the resource through the + * system class loader (see {@link #getSystemClassLoader()}). + * + * @param name + * The resource name + * + * @return An input stream for reading the resource, or null + * if the resource could not be found + * + * @since 1.1 + */ + public static InputStream getSystemResourceAsStream(String name) { + URL url = getSystemResource(name); + try { + return url != null ? url.openStream() : null; + } catch (IOException e) { + return null; + } + } + + + // -- Hierarchy -- + + /** + * Returns the parent class loader for delegation. Some implementations may + * use null to represent the bootstrap class loader. This method + * will return null in such implementations if this class loader's + * parent is the bootstrap class loader. + * + *If a security manager is present, and the invoker's class loader is + * not null and is not an ancestor of this class loader, then this + * method invokes the security manager's {@link + * SecurityManager#checkPermission(java.security.Permission) + * checkPermission} method with a {@link + * RuntimePermission#RuntimePermission(String) + * RuntimePermission("getClassLoader")} permission to verify + * access to the parent class loader is permitted. If not, a + * SecurityException will be thrown.
+ * + * @return The parent ClassLoader + * + * @throws SecurityException + * If a security manager exists and its checkPermission + * method doesn't allow access to this class loader's parent class + * loader. + * + * @since 1.2 + */ + public final ClassLoader getParent() { + throw new SecurityException(); + } + + /** + * Returns the system class loader for delegation. This is the default + * delegation parent for new ClassLoader instances, and is + * typically the class loader used to start the application. + * + *This method is first invoked early in the runtime's startup + * sequence, at which point it creates the system class loader and sets it + * as the context class loader of the invoking Thread. + * + *
The default system class loader is an implementation-dependent + * instance of this class. + * + *
If the system property "java.system.class.loader" is defined + * when this method is first invoked then the value of that property is + * taken to be the name of a class that will be returned as the system + * class loader. The class is loaded using the default system class loader + * and must define a public constructor that takes a single parameter of + * type ClassLoader which is used as the delegation parent. An + * instance is then created using this constructor with the default system + * class loader as the parameter. The resulting class loader is defined + * to be the system class loader. + * + *
If a security manager is present, and the invoker's class loader is + * not null and the invoker's class loader is not the same as or + * an ancestor of the system class loader, then this method invokes the + * security manager's {@link + * SecurityManager#checkPermission(java.security.Permission) + * checkPermission} method with a {@link + * RuntimePermission#RuntimePermission(String) + * RuntimePermission("getClassLoader")} permission to verify + * access to the system class loader. If not, a + * SecurityException will be thrown.
+ * + * @return The system ClassLoader for delegation, or + * null if none + * + * @throws SecurityException + * If a security manager exists and its checkPermission + * method doesn't allow access to the system class loader. + * + * @throws IllegalStateException + * If invoked recursively during the construction of the class + * loader specified by the "java.system.class.loader" + * property. + * + * @throws Error + * If the system property "java.system.class.loader" + * is defined but the named class could not be loaded, the + * provider class does not define the required constructor, or an + * exception is thrown by that constructor when it is invoked. The + * underlying cause of the error can be retrieved via the + * {@link Throwable#getCause()} method. + * + * @revised 1.4 + */ + public static ClassLoader getSystemClassLoader() { + throw new SecurityException(); + } + + // Returns true if the specified class loader can be found in this class + // loader's delegation chain. + boolean isAncestor(ClassLoader cl) { + ClassLoader acl = this; + do { + acl = acl.parent; + if (cl == acl) { + return true; + } + } while (acl != null); + return false; + } + + private boolean checkName(String name) { + throw new UnsupportedOperationException(); + } + + private Class findBootstrapClassOrNull(String name) { + throw new UnsupportedOperationException(); + } + + private static URL getBootstrapResource(String name) { + throw new UnsupportedOperationException(); + } + + private static EnumerationSecurityException
with no detail message.
+ */
+ public SecurityException() {
+ super();
+ }
+
+ /**
+ * Constructs a SecurityException
with the specified
+ * detail message.
+ *
+ * @param s the detail message.
+ */
+ public SecurityException(String s) {
+ super(s);
+ }
+
+ /**
+ * Creates a SecurityException
with the specified
+ * detail message and cause.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A null value is permitted,
+ * and indicates that the cause is nonexistent or unknown.)
+ * @since 1.5
+ */
+ public SecurityException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a SecurityException
with the specified cause
+ * and a detail message of (cause==null ? null : cause.toString())
+ * (which typically contains the class and detail message of
+ * cause).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A null value is permitted,
+ * and indicates that the cause is nonexistent or unknown.)
+ * @since 1.5
+ */
+ public SecurityException(Throwable cause) {
+ super(cause);
+ }
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/net/MalformedURLException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/net/MalformedURLException.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.net;
+
+import java.io.IOException;
+
+/**
+ * Thrown to indicate that a malformed URL has occurred. Either no
+ * legal protocol could be found in a specification string or the
+ * string could not be parsed.
+ *
+ * @author Arthur van Hoff
+ * @since JDK1.0
+ */
+public class MalformedURLException extends IOException {
+ private static final long serialVersionUID = -182787522200415866L;
+
+ /**
+ * Constructs a MalformedURLException
with no detail message.
+ */
+ public MalformedURLException() {
+ }
+
+ /**
+ * Constructs a MalformedURLException
with the
+ * specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public MalformedURLException(String msg) {
+ super(msg);
+ }
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/net/URL.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/net/URL.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,958 @@
+/*
+ * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.net;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Class URL
represents a Uniform Resource
+ * Locator, a pointer to a "resource" on the World
+ * Wide Web. A resource can be something as simple as a file or a
+ * directory, or it can be a reference to a more complicated object,
+ * such as a query to a database or to a search engine. More
+ * information on the types of URLs and their formats can be found at:
+ * + * + * http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html + *+ *
+ * In general, a URL can be broken into several parts. The previous
+ * example of a URL indicates that the protocol to use is
+ * http
(HyperText Transfer Protocol) and that the
+ * information resides on a host machine named
+ * www.socs.uts.edu.au
. The information on that host
+ * machine is named /MosaicDocs-old/url-primer.html
. The exact
+ * meaning of this name on the host machine is both protocol
+ * dependent and host dependent. The information normally resides in
+ * a file, but it could be generated on the fly. This component of
+ * the URL is called the path component.
+ *
+ * A URL can optionally specify a "port", which is the
+ * port number to which the TCP connection is made on the remote host
+ * machine. If the port is not specified, the default port for
+ * the protocol is used instead. For example, the default port for
+ * http
is 80
. An alternative port could be
+ * specified as:
+ *
+ *+ * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html + *
+ * The syntax of URL
is defined by RFC 2396: Uniform
+ * Resource Identifiers (URI): Generic Syntax, amended by RFC 2732: Format for
+ * Literal IPv6 Addresses in URLs. The Literal IPv6 address format
+ * also supports scope_ids. The syntax and usage of scope_ids is described
+ * here.
+ *
+ * A URL may have appended to it a "fragment", also known + * as a "ref" or a "reference". The fragment is indicated by the sharp + * sign character "#" followed by more characters. For example, + *
+ *+ * http://java.sun.com/index.html#chapter1 + *
+ * This fragment is not technically part of the URL. Rather, it
+ * indicates that after the specified resource is retrieved, the
+ * application is specifically interested in that part of the
+ * document that has the tag chapter1
attached to it. The
+ * meaning of a tag is resource specific.
+ *
+ * An application can also specify a "relative URL", + * which contains only enough information to reach the resource + * relative to another URL. Relative URLs are frequently used within + * HTML pages. For example, if the contents of the URL: + *
+ * contained within it the relative URL: + *+ * http://java.sun.com/index.html + *
+ * it would be a shorthand for: + *+ * FAQ.html + *
+ *+ * http://java.sun.com/FAQ.html + *
+ * The relative URL need not specify all the components of a URL. If + * the protocol, host name, or port number is missing, the value is + * inherited from the fully specified URL. The file component must be + * specified. The optional fragment is not inherited. + *
+ * The URL class does not itself encode or decode any URL components
+ * according to the escaping mechanism defined in RFC2396. It is the
+ * responsibility of the caller to encode any fields, which need to be
+ * escaped prior to calling URL, and also to decode any escaped fields,
+ * that are returned from URL. Furthermore, because URL has no knowledge
+ * of URL escaping, it does not recognise equivalence between the encoded
+ * or decoded form of the same URL. For example, the two URLs:
+ *
http://foo.com/hello world/ and http://foo.com/hello%20world+ * would be considered not equal to each other. + *
+ * Note, the {@link java.net.URI} class does perform escaping of its + * component fields in certain circumstances. The recommended way + * to manage the encoding and decoding of URLs is to use {@link java.net.URI}, + * and to convert between these two classes using {@link #toURI()} and + * {@link URI#toURL()}. + *
+ * The {@link URLEncoder} and {@link URLDecoder} classes can also be
+ * used, but only for HTML form encoding, which is not the same
+ * as the encoding scheme defined in RFC2396.
+ *
+ * @author James Gosling
+ * @since JDK1.0
+ */
+public final class URL implements java.io.Serializable {
+
+ static final long serialVersionUID = -7627629688361524110L;
+
+ /**
+ * The property which specifies the package prefix list to be scanned
+ * for protocol handlers. The value of this property (if any) should
+ * be a vertical bar delimited list of package names to search through
+ * for a protocol handler to load. The policy of this class is that
+ * all protocol handlers will be in a class called
+ *
+ *
+ *
+ * Specifying a
+ *
+ * If this is the first URL object being created with the specified
+ * protocol, a stream protocol handler object, an instance of
+ * class Protocol handlers for the following protocols are guaranteed
+ * to exist on the search path :-
+ * No validation of the inputs is performed by this constructor.
+ *
+ * @param protocol the name of the protocol to use.
+ * @param host the name of the host.
+ * @param port the port number on the host.
+ * @param file the file on the host
+ * @exception MalformedURLException if an unknown protocol is specified.
+ * @see java.lang.System#getProperty(java.lang.String)
+ * @see java.net.URL#setURLStreamHandlerFactory(
+ * java.net.URLStreamHandlerFactory)
+ * @see java.net.URLStreamHandler
+ * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
+ * java.lang.String)
+ */
+ public URL(String protocol, String host, int port, String file)
+ throws MalformedURLException
+ {
+ this(protocol, host, port, file, null);
+ }
+
+ /**
+ * Creates a URL from the specified
+ * This method is equivalent to calling the four-argument
+ * constructor with the arguments being
+ * This constructor is equivalent to a call to the two-argument
+ * constructor with a
+ * If the scheme component is defined in the given spec and does not match
+ * the scheme of the context, then the new URL is created as an absolute
+ * URL based on the spec alone. Otherwise the scheme component is inherited
+ * from the context URL.
+ *
+ * If the authority component is present in the spec then the spec is
+ * treated as absolute and the spec authority and path will replace the
+ * context authority and path. If the authority component is absent in the
+ * spec then the authority of the new URL will be inherited from the
+ * context.
+ *
+ * If the spec's path component begins with a slash character
+ * "/" then the
+ * path is treated as absolute and the spec path replaces the context path.
+ *
+ * Otherwise, the path is treated as a relative path and is appended to the
+ * context path, as described in RFC2396. Also, in this case,
+ * the path is canonicalized through the removal of directory
+ * changes made by occurences of ".." and ".".
+ *
+ * For a more detailed description of URL parsing, refer to RFC2396.
+ *
+ * @param context the context in which to parse the specification.
+ * @param spec the
+ *
+ * If the given object is not a URL then this method immediately returns
+ *
+ *
+ * Two URL objects are equal if they have the same protocol, reference
+ * equivalent hosts, have the same port number on the host, and the same
+ * file and fragment of the file.
+ *
+ * Two hosts are considered equivalent if both host names can be resolved
+ * into the same IP addresses; else if either host name can't be
+ * resolved, the host names must be equal without regard to case; or both
+ * host names equal to null.
+ *
+ * Since hosts comparison requires name resolution, this operation is a
+ * blocking operation.
+ *
+ * Note: The defined behavior for
+ *
+ * The hash code is based upon all the URL components relevant for URL
+ * comparison. As such, this operation is a blocking operation.
+ *
+ * @return a hash code for this
+ *
+ * Returns A new instance of {@linkplain java.net.URLConnection URLConnection} is
+ * created every time when invoking the
+ * {@linkplain java.net.URLStreamHandler#openConnection(URL)
+ * URLStreamHandler.openConnection(URL)} method of the protocol handler for
+ * this URL. It should be noted that a URLConnection instance does not establish
+ * the actual network connection on creation. This will happen only when
+ * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}. If for the URL's protocol (such as HTTP or JAR), there
+ * exists a public, specialized URLConnection subclass belonging
+ * to one of the following packages or one of their subpackages:
+ * java.lang, java.io, java.util, java.net, the connection
+ * returned will be of that subclass. For example, for HTTP an
+ * HttpURLConnection will be returned, and for JAR a
+ * JarURLConnection will be returned.
+ * For example, to print all elements of a Vector<E> v:
+ *
+ * Methods are provided to enumerate through the elements of a
+ * vector, the keys of a hashtable, and the values in a hashtable.
+ * Enumerations are also used to specify the input streams to a
+ *
+ * NOTE: The functionality of this interface is duplicated by the Iterator
+ * interface. In addition, Iterator adds an optional remove operation, and
+ * has shorter method names. New implementations should consider using
+ * Iterator in preference to Enumeration.
+ *
+ * @see java.util.Iterator
+ * @see java.io.SequenceInputStream
+ * @see java.util.Enumeration#nextElement()
+ * @see java.util.Hashtable
+ * @see java.util.Hashtable#elements()
+ * @see java.util.Hashtable#keys()
+ * @see java.util.Vector
+ * @see java.util.Vector#elements()
+ *
+ * @author Lee Boynton
+ * @since JDK1.0
+ */
+public interface Enumerationfile
is
+ * defined as path[?query]
+ * @serial
+ */
+ private String file;
+
+ /**
+ * The query part of this URL.
+ */
+ private transient String query;
+
+ /**
+ * The authority part of this URL.
+ * @serial
+ */
+ private String authority;
+
+ /**
+ * The path part of this URL.
+ */
+ private transient String path;
+
+ /**
+ * The userinfo part of this URL.
+ */
+ private transient String userInfo;
+
+ /**
+ * # reference.
+ * @serial
+ */
+ private String ref;
+
+ /* Our hash code.
+ * @serial
+ */
+ private int hashCode = -1;
+
+ /**
+ * Creates a URL
object from the specified
+ * protocol
, host
, port
+ * number, and file
.host
can be expressed as a host name or a literal
+ * IP address. If IPv6 literal address is used, it should be
+ * enclosed in square brackets ('[' and ']'), as
+ * specified by RFC 2732;
+ * However, the literal IPv6 address format defined in RFC 2373: IP
+ * Version 6 Addressing Architecture is also accepted.port
number of -1
+ * indicates that the URL should use the default port for the
+ * protocol.URLStreamHandler
, is created for that protocol:
+ *
+ *
+ *
+ * URLStreamHandlerFactory
as the stream handler factory,
+ * then the createURLStreamHandler
method of that instance
+ * is called with the protocol string as an argument to create the
+ * stream protocol handler.
+ * URLStreamHandlerFactory
has yet been set up,
+ * or if the factory's createURLStreamHandler
method
+ * returns null
, then the constructor finds the
+ * value of the system property:
+ *
+ * If the value of that system property is not
+ * java.protocol.handler.pkgs
+ *
null
,
+ * it is interpreted as a list of packages separated by a vertical
+ * slash character '|
'. The constructor tries to load
+ * the class named:
+ *
+ * where <package> is replaced by the name of the package
+ * and <protocol> is replaced by the name of the protocol.
+ * If this class does not exist, or if the class exists but it is not
+ * a subclass of
+ * <package>.<protocol>.Handler
+ *
URLStreamHandler
, then the next package
+ * in the list is tried.
+ *
+ * If this class does not exist, or if the class exists but it is not a
+ * subclass of
+ * <system default package>.<protocol>.Handler
+ *
URLStreamHandler
, then a
+ * MalformedURLException
is thrown.
+ *
+ * Protocol handlers for additional protocols may also be
+ * available.
+ *
+ *
+ * http, https, ftp, file, and jar
+ *
protocol
+ * name, host
name, and file
name. The
+ * default port for the specified protocol is used.
+ * protocol
,
+ * host
, -1
, and file
.
+ *
+ * No validation of the inputs is performed by this constructor.
+ *
+ * @param protocol the name of the protocol to use.
+ * @param host the name of the host.
+ * @param file the file on the host.
+ * @exception MalformedURLException if an unknown protocol is specified.
+ * @see java.net.URL#URL(java.lang.String, java.lang.String,
+ * int, java.lang.String)
+ */
+ public URL(String protocol, String host, String file)
+ throws MalformedURLException {
+ this(protocol, host, -1, file);
+ }
+
+ private URL(String protocol, String host, int port, String file,
+ Object handler) throws MalformedURLException {
+ if (handler != null) {
+ throw new SecurityException();
+ }
+
+ protocol = protocol.toLowerCase();
+ this.protocol = protocol;
+ if (host != null) {
+
+ /**
+ * if host is a literal IPv6 address,
+ * we will make it conform to RFC 2732
+ */
+ if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
+ host = "["+host+"]";
+ }
+ this.host = host;
+
+ if (port < -1) {
+ throw new MalformedURLException("Invalid port number :" +
+ port);
+ }
+ this.port = port;
+ authority = (port == -1) ? host : host + ":" + port;
+ }
+
+ Parts parts = new Parts(file);
+ path = parts.getPath();
+ query = parts.getQuery();
+
+ if (query != null) {
+ this.file = path + "?" + query;
+ } else {
+ this.file = path;
+ }
+ ref = parts.getRef();
+
+ // Note: we don't do validation of the URL here. Too risky to change
+ // right now, but worth considering for future reference. -br
+// if (handler == null &&
+// (handler = getURLStreamHandler(protocol)) == null) {
+// throw new MalformedURLException("unknown protocol: " + protocol);
+// }
+ }
+
+ /**
+ * Creates a URL
object from the String
+ * representation.
+ * null
first argument.
+ *
+ * @param spec the String
to parse as a URL.
+ * @exception MalformedURLException if no protocol is specified, or an
+ * unknown protocol is found, or spec is null.
+ * @see java.net.URL#URL(java.net.URL, java.lang.String)
+ */
+ public URL(String spec) throws MalformedURLException {
+ this(null, spec);
+ }
+
+ /**
+ * Creates a URL by parsing the given spec within a specified context.
+ *
+ * The new URL is created from the given context URL and the spec
+ * argument as described in
+ * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
+ *
+ * The reference is parsed into the scheme, authority, path, query and
+ * fragment parts. If the path component is empty and the scheme,
+ * authority, and query components are undefined, then the new URL is a
+ * reference to the current document. Otherwise, the fragment and query
+ * parts present in the spec are used in the new URL.
+ *
+ * <scheme>://<authority><path>?<query>#<fragment>
+ *
String
to parse as a URL.
+ * @exception MalformedURLException if no protocol is specified, or an
+ * unknown protocol is found, or spec is null.
+ * @see java.net.URL#URL(java.lang.String, java.lang.String,
+ * int, java.lang.String)
+ * @see java.net.URLStreamHandler
+ * @see java.net.URLStreamHandler#parseURL(java.net.URL,
+ * java.lang.String, int, int)
+ */
+ public URL(URL context, String spec) throws MalformedURLException {
+ this(context, spec, null);
+ }
+
+ /**
+ * Creates a URL by parsing the given spec with the specified handler
+ * within a specified context. If the handler is null, the parsing
+ * occurs as with the two argument constructor.
+ *
+ * @param context the context in which to parse the specification.
+ * @param spec the String
to parse as a URL.
+ * @param handler the stream handler for the URL.
+ * @exception MalformedURLException if no protocol is specified, or an
+ * unknown protocol is found, or spec is null.
+ * @exception SecurityException
+ * if a security manager exists and its
+ * checkPermission
method doesn't allow
+ * specifying a stream handler.
+ * @see java.net.URL#URL(java.lang.String, java.lang.String,
+ * int, java.lang.String)
+ * @see java.net.URLStreamHandler
+ * @see java.net.URLStreamHandler#parseURL(java.net.URL,
+ * java.lang.String, int, int)
+ */
+ private URL(URL context, String spec, Object handler)
+ throws MalformedURLException
+ {
+ String original = spec;
+ int i, limit, c;
+ int start = 0;
+ String newProtocol = null;
+ boolean aRef=false;
+ boolean isRelative = false;
+
+ // Check for permission to specify a handler
+ if (handler != null) {
+ throw new SecurityException();
+ }
+
+ try {
+ limit = spec.length();
+ while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
+ limit--; //eliminate trailing whitespace
+ }
+ while ((start < limit) && (spec.charAt(start) <= ' ')) {
+ start++; // eliminate leading whitespace
+ }
+
+ if (spec.regionMatches(true, start, "url:", 0, 4)) {
+ start += 4;
+ }
+ if (start < spec.length() && spec.charAt(start) == '#') {
+ /* we're assuming this is a ref relative to the context URL.
+ * This means protocols cannot start w/ '#', but we must parse
+ * ref URL's like: "hello:there" w/ a ':' in them.
+ */
+ aRef=true;
+ }
+ for (i = start ; !aRef && (i < limit) &&
+ ((c = spec.charAt(i)) != '/') ; i++) {
+ if (c == ':') {
+
+ String s = spec.substring(start, i).toLowerCase();
+ if (isValidProtocol(s)) {
+ newProtocol = s;
+ start = i + 1;
+ }
+ break;
+ }
+ }
+
+ // Only use our context if the protocols match.
+ protocol = newProtocol;
+ if ((context != null) && ((newProtocol == null) ||
+ newProtocol.equalsIgnoreCase(context.protocol))) {
+ // inherit the protocol handler from the context
+ // if not specified to the constructor
+// if (handler == null) {
+// handler = context.handler;
+// }
+
+ // If the context is a hierarchical URL scheme and the spec
+ // contains a matching scheme then maintain backwards
+ // compatibility and treat it as if the spec didn't contain
+ // the scheme; see 5.2.3 of RFC2396
+ if (context.path != null && context.path.startsWith("/"))
+ newProtocol = null;
+
+ if (newProtocol == null) {
+ protocol = context.protocol;
+ authority = context.authority;
+ userInfo = context.userInfo;
+ host = context.host;
+ port = context.port;
+ file = context.file;
+ path = context.path;
+ isRelative = true;
+ }
+ }
+
+ if (protocol == null) {
+ throw new MalformedURLException("no protocol: "+original);
+ }
+
+ // Get the protocol handler if not specified or the protocol
+ // of the context could not be used
+// if (handler == null &&
+// (handler = getURLStreamHandler(protocol)) == null) {
+// throw new MalformedURLException("unknown protocol: "+protocol);
+// }
+
+// this.handler = handler;
+
+ i = spec.indexOf('#', start);
+ if (i >= 0) {
+ ref = spec.substring(i + 1, limit);
+ limit = i;
+ }
+
+ /*
+ * Handle special case inheritance of query and fragment
+ * implied by RFC2396 section 5.2.2.
+ */
+ if (isRelative && start == limit) {
+ query = context.query;
+ if (ref == null) {
+ ref = context.ref;
+ }
+ }
+
+// handler.parseURL(this, spec, start, limit);
+
+ } catch(MalformedURLException e) {
+ throw e;
+ } catch(Exception e) {
+ MalformedURLException exception = new MalformedURLException(e.getMessage());
+ exception.initCause(e);
+ throw exception;
+ }
+ }
+
+ /*
+ * Returns true if specified string is a valid protocol name.
+ */
+ private boolean isValidProtocol(String protocol) {
+ int len = protocol.length();
+ if (len < 1)
+ return false;
+ char c = protocol.charAt(0);
+ if (!Character.isLetter(c))
+ return false;
+ for (int i = 1; i < len; i++) {
+ c = protocol.charAt(i);
+ if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
+ c != '-') {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Sets the fields of the URL. This is not a public method so that
+ * only URLStreamHandlers can modify URL fields. URLs are
+ * otherwise constant.
+ *
+ * @param protocol the name of the protocol to use
+ * @param host the name of the host
+ @param port the port number on the host
+ * @param file the file on the host
+ * @param ref the internal reference in the URL
+ */
+ protected void set(String protocol, String host,
+ int port, String file, String ref) {
+ synchronized (this) {
+ this.protocol = protocol;
+ this.host = host;
+ authority = port == -1 ? host : host + ":" + port;
+ this.port = port;
+ this.file = file;
+ this.ref = ref;
+ /* This is very important. We must recompute this after the
+ * URL has been changed. */
+ hashCode = -1;
+ int q = file.lastIndexOf('?');
+ if (q != -1) {
+ query = file.substring(q+1);
+ path = file.substring(0, q);
+ } else
+ path = file;
+ }
+ }
+
+ /**
+ * Sets the specified 8 fields of the URL. This is not a public method so
+ * that only URLStreamHandlers can modify URL fields. URLs are otherwise
+ * constant.
+ *
+ * @param protocol the name of the protocol to use
+ * @param host the name of the host
+ * @param port the port number on the host
+ * @param authority the authority part for the url
+ * @param userInfo the username and password
+ * @param path the file on the host
+ * @param ref the internal reference in the URL
+ * @param query the query part of this URL
+ * @since 1.3
+ */
+ protected void set(String protocol, String host, int port,
+ String authority, String userInfo, String path,
+ String query, String ref) {
+ synchronized (this) {
+ this.protocol = protocol;
+ this.host = host;
+ this.port = port;
+ this.file = query == null ? path : path + "?" + query;
+ this.userInfo = userInfo;
+ this.path = path;
+ this.ref = ref;
+ /* This is very important. We must recompute this after the
+ * URL has been changed. */
+ hashCode = -1;
+ this.query = query;
+ this.authority = authority;
+ }
+ }
+
+ /**
+ * Gets the query part of this URL
.
+ *
+ * @return the query part of this URL
,
+ * or null
if one does not exist
+ * @since 1.3
+ */
+ public String getQuery() {
+ return query;
+ }
+
+ /**
+ * Gets the path part of this URL
.
+ *
+ * @return the path part of this URL
, or an
+ * empty string if one does not exist
+ * @since 1.3
+ */
+ public String getPath() {
+ return path;
+ }
+
+ /**
+ * Gets the userInfo part of this URL
.
+ *
+ * @return the userInfo part of this URL
, or
+ * null
if one does not exist
+ * @since 1.3
+ */
+ public String getUserInfo() {
+ return userInfo;
+ }
+
+ /**
+ * Gets the authority part of this URL
.
+ *
+ * @return the authority part of this URL
+ * @since 1.3
+ */
+ public String getAuthority() {
+ return authority;
+ }
+
+ /**
+ * Gets the port number of this URL
.
+ *
+ * @return the port number, or -1 if the port is not set
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * Gets the protocol name of this URL
.
+ *
+ * @return the protocol of this URL
.
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
+ * Gets the host name of this URL
, if applicable.
+ * The format of the host conforms to RFC 2732, i.e. for a
+ * literal IPv6 address, this method will return the IPv6 address
+ * enclosed in square brackets ('[' and ']').
+ *
+ * @return the host name of this URL
.
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * Gets the file name of this URL
.
+ * The returned file portion will be
+ * the same as getPath()
, plus the concatenation of
+ * the value of getQuery()
, if any. If there is
+ * no query portion, this method and getPath()
will
+ * return identical results.
+ *
+ * @return the file name of this URL
,
+ * or an empty string if one does not exist
+ */
+ public String getFile() {
+ return file;
+ }
+
+ /**
+ * Gets the anchor (also known as the "reference") of this
+ * URL
.
+ *
+ * @return the anchor (also known as the "reference") of this
+ * URL
, or null
if one does not exist
+ */
+ public String getRef() {
+ return ref;
+ }
+
+ /**
+ * Compares this URL for equality with another object.false
.equals
is known to
+ * be inconsistent with virtual hosting in HTTP.
+ *
+ * @param obj the URL to compare against.
+ * @return true
if the objects are the same;
+ * false
otherwise.
+ */
+ public boolean equals(Object obj) {
+ if (!(obj instanceof URL))
+ return false;
+ URL u2 = (URL)obj;
+
+ // return handler.equals(this, u2);
+ return u2 == this;
+ }
+
+ /**
+ * Creates an integer suitable for hash table indexing.URL
.
+ */
+ public synchronized int hashCode() {
+ if (hashCode != -1)
+ return hashCode;
+
+ // hashCode = handler.hashCode(this);
+ return hashCode;
+ }
+
+ /**
+ * Compares two URLs, excluding the fragment component.true
if this URL
and the
+ * other
argument are equal without taking the
+ * fragment component into consideration.
+ *
+ * @param other the URL
to compare against.
+ * @return true
if they reference the same remote object;
+ * false
otherwise.
+ */
+ public boolean sameFile(URL other) {
+// return handler.sameFile(this, other);
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * Constructs a string representation of this URL
. The
+ * string is created by calling the toExternalForm
+ * method of the stream protocol handler for this object.
+ *
+ * @return a string representation of this object.
+ * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
+ * java.lang.String)
+ * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
+ */
+ public String toString() {
+ return toExternalForm();
+ }
+
+ /**
+ * Constructs a string representation of this URL
. The
+ * string is created by calling the toExternalForm
+ * method of the stream protocol handler for this object.
+ *
+ * @return a string representation of this object.
+ * @see java.net.URL#URL(java.lang.String, java.lang.String,
+ * int, java.lang.String)
+ * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
+ */
+ public String toExternalForm() {
+ throw new UnsupportedOperationException();
+// return handler.toExternalForm(this);
+ }
+
+ /**
+ * Returns a {@link java.net.URLConnection URLConnection} instance that
+ * represents a connection to the remote object referred to by the
+ * {@code URL}.
+ *
+ * URL
and returns an
+ * InputStream
for reading from that connection. This
+ * method is a shorthand for:
+ *
+ *
+ * @return an input stream for reading from the URL connection.
+ * @exception IOException if an I/O exception occurs.
+ * @see java.net.URL#openConnection()
+ * @see java.net.URLConnection#getInputStream()
+ */
+ public final InputStream openStream() throws java.io.IOException {
+ throw new IOException();
+// return openConnection().getInputStream();
+ }
+
+ /**
+ * Gets the contents of this URL. This method is a shorthand for:
+ *
+ * openConnection().getInputStream()
+ *
+ *
+ * @return the contents of this URL.
+ * @exception IOException if an I/O exception occurs.
+ * @see java.net.URLConnection#getContent()
+ */
+ public final Object getContent() throws java.io.IOException {
+ throw new IOException();
+// return openConnection().getContent();
+ }
+
+ /**
+ * Gets the contents of this URL. This method is a shorthand for:
+ *
+ * openConnection().getContent()
+ *
+ *
+ * @param classes an array of Java types
+ * @return the content object of this URL that is the first match of
+ * the types specified in the classes array.
+ * null if none of the requested types are supported.
+ * @exception IOException if an I/O exception occurs.
+ * @see java.net.URLConnection#getContent(Class[])
+ * @since 1.3
+ */
+ public final Object getContent(Class[] classes)
+ throws java.io.IOException {
+ throw new IOException();
+// return openConnection().getContent(classes);
+ }
+
+
+}
+
+class Parts {
+ String path, query, ref;
+
+ Parts(String file) {
+ int ind = file.indexOf('#');
+ ref = ind < 0 ? null: file.substring(ind + 1);
+ file = ind < 0 ? file: file.substring(0, ind);
+ int q = file.lastIndexOf('?');
+ if (q != -1) {
+ query = file.substring(q+1);
+ path = file.substring(0, q);
+ } else {
+ path = file;
+ }
+ }
+
+ String getPath() {
+ return path;
+ }
+
+ String getQuery() {
+ return query;
+ }
+
+ String getRef() {
+ return ref;
+ }
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/util/Enumeration.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/util/Enumeration.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util;
+
+/**
+ * An object that implements the Enumeration interface generates a
+ * series of elements, one at a time. Successive calls to the
+ *
+ * openConnection().getContent(Class[])
+ *
nextElement
method return successive elements of the
+ * series.
+ *
+ * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
+ * System.out.println(e.nextElement());
+ * SequenceInputStream
.
+ * true
if and only if this enumeration object
+ * contains at least one more element to provide;
+ * false
otherwise.
+ */
+ boolean hasMoreElements();
+
+ /**
+ * Returns the next element of this enumeration if this enumeration
+ * object has at least one more element to provide.
+ *
+ * @return the next element of this enumeration.
+ * @exception NoSuchElementException if no more elements exist.
+ */
+ E nextElement();
+}
diff -r 02618d8bec44 -r 0a582b5a2737 emul/src/main/java/java/util/NoSuchElementException.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/emul/src/main/java/java/util/NoSuchElementException.java Tue Oct 30 09:24:41 2012 +0100
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package java.util;
+
+/**
+ * Thrown by the nextElement
method of an
+ * Enumeration
to indicate that there are no more
+ * elements in the enumeration.
+ *
+ * @author unascribed
+ * @see java.util.Enumeration
+ * @see java.util.Enumeration#nextElement()
+ * @since JDK1.0
+ */
+public
+class NoSuchElementException extends RuntimeException {
+ private static final long serialVersionUID = 6769829250639411880L;
+
+ /**
+ * Constructs a NoSuchElementException
with null
+ * as its error message string.
+ */
+ public NoSuchElementException() {
+ super();
+ }
+
+ /**
+ * Constructs a NoSuchElementException
, saving a reference
+ * to the error message string s for later retrieval by the
+ * getMessage method.
+ *
+ * @param s the detail message.
+ */
+ public NoSuchElementException(String s) {
+ super(s);
+ }
+}