1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/emul/src/main/java/java/io/Closeable.java Tue Oct 30 09:24:41 2012 +0100
1.3 @@ -0,0 +1,48 @@
1.4 +/*
1.5 + * Copyright (c) 2003, 2010, 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.io;
1.30 +
1.31 +import java.io.IOException;
1.32 +
1.33 +/**
1.34 + * A {@code Closeable} is a source or destination of data that can be closed.
1.35 + * The close method is invoked to release resources that the object is
1.36 + * holding (such as open files).
1.37 + *
1.38 + * @since 1.5
1.39 + */
1.40 +
1.41 +public interface Closeable extends AutoCloseable {
1.42 +
1.43 + /**
1.44 + * Closes this stream and releases any system resources associated
1.45 + * with it. If the stream is already closed then invoking this
1.46 + * method has no effect.
1.47 + *
1.48 + * @throws IOException if an I/O error occurs
1.49 + */
1.50 + public void close() throws IOException;
1.51 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/src/main/java/java/io/InputStream.java Tue Oct 30 09:24:41 2012 +0100
2.3 @@ -0,0 +1,370 @@
2.4 +/*
2.5 + * Copyright (c) 1994, 2006, 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.io;
2.30 +
2.31 +/**
2.32 + * This abstract class is the superclass of all classes representing
2.33 + * an input stream of bytes.
2.34 + *
2.35 + * <p> Applications that need to define a subclass of <code>InputStream</code>
2.36 + * must always provide a method that returns the next byte of input.
2.37 + *
2.38 + * @author Arthur van Hoff
2.39 + * @see java.io.BufferedInputStream
2.40 + * @see java.io.ByteArrayInputStream
2.41 + * @see java.io.DataInputStream
2.42 + * @see java.io.FilterInputStream
2.43 + * @see java.io.InputStream#read()
2.44 + * @see java.io.OutputStream
2.45 + * @see java.io.PushbackInputStream
2.46 + * @since JDK1.0
2.47 + */
2.48 +public abstract class InputStream implements Closeable {
2.49 +
2.50 + // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
2.51 + private static final int SKIP_BUFFER_SIZE = 2048;
2.52 + // skipBuffer is initialized in skip(long), if needed.
2.53 + private static byte[] skipBuffer;
2.54 +
2.55 + /**
2.56 + * Reads the next byte of data from the input stream. The value byte is
2.57 + * returned as an <code>int</code> in the range <code>0</code> to
2.58 + * <code>255</code>. If no byte is available because the end of the stream
2.59 + * has been reached, the value <code>-1</code> is returned. This method
2.60 + * blocks until input data is available, the end of the stream is detected,
2.61 + * or an exception is thrown.
2.62 + *
2.63 + * <p> A subclass must provide an implementation of this method.
2.64 + *
2.65 + * @return the next byte of data, or <code>-1</code> if the end of the
2.66 + * stream is reached.
2.67 + * @exception IOException if an I/O error occurs.
2.68 + */
2.69 + public abstract int read() throws IOException;
2.70 +
2.71 + /**
2.72 + * Reads some number of bytes from the input stream and stores them into
2.73 + * the buffer array <code>b</code>. The number of bytes actually read is
2.74 + * returned as an integer. This method blocks until input data is
2.75 + * available, end of file is detected, or an exception is thrown.
2.76 + *
2.77 + * <p> If the length of <code>b</code> is zero, then no bytes are read and
2.78 + * <code>0</code> is returned; otherwise, there is an attempt to read at
2.79 + * least one byte. If no byte is available because the stream is at the
2.80 + * end of the file, the value <code>-1</code> is returned; otherwise, at
2.81 + * least one byte is read and stored into <code>b</code>.
2.82 + *
2.83 + * <p> The first byte read is stored into element <code>b[0]</code>, the
2.84 + * next one into <code>b[1]</code>, and so on. The number of bytes read is,
2.85 + * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
2.86 + * number of bytes actually read; these bytes will be stored in elements
2.87 + * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
2.88 + * leaving elements <code>b[</code><i>k</i><code>]</code> through
2.89 + * <code>b[b.length-1]</code> unaffected.
2.90 + *
2.91 + * <p> The <code>read(b)</code> method for class <code>InputStream</code>
2.92 + * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
2.93 + *
2.94 + * @param b the buffer into which the data is read.
2.95 + * @return the total number of bytes read into the buffer, or
2.96 + * <code>-1</code> if there is no more data because the end of
2.97 + * the stream has been reached.
2.98 + * @exception IOException If the first byte cannot be read for any reason
2.99 + * other than the end of the file, if the input stream has been closed, or
2.100 + * if some other I/O error occurs.
2.101 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
2.102 + * @see java.io.InputStream#read(byte[], int, int)
2.103 + */
2.104 + public int read(byte b[]) throws IOException {
2.105 + return read(b, 0, b.length);
2.106 + }
2.107 +
2.108 + /**
2.109 + * Reads up to <code>len</code> bytes of data from the input stream into
2.110 + * an array of bytes. An attempt is made to read as many as
2.111 + * <code>len</code> bytes, but a smaller number may be read.
2.112 + * The number of bytes actually read is returned as an integer.
2.113 + *
2.114 + * <p> This method blocks until input data is available, end of file is
2.115 + * detected, or an exception is thrown.
2.116 + *
2.117 + * <p> If <code>len</code> is zero, then no bytes are read and
2.118 + * <code>0</code> is returned; otherwise, there is an attempt to read at
2.119 + * least one byte. If no byte is available because the stream is at end of
2.120 + * file, the value <code>-1</code> is returned; otherwise, at least one
2.121 + * byte is read and stored into <code>b</code>.
2.122 + *
2.123 + * <p> The first byte read is stored into element <code>b[off]</code>, the
2.124 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
2.125 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
2.126 + * bytes actually read; these bytes will be stored in elements
2.127 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
2.128 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
2.129 + * <code>b[off+len-1]</code> unaffected.
2.130 + *
2.131 + * <p> In every case, elements <code>b[0]</code> through
2.132 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
2.133 + * <code>b[b.length-1]</code> are unaffected.
2.134 + *
2.135 + * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
2.136 + * for class <code>InputStream</code> simply calls the method
2.137 + * <code>read()</code> repeatedly. If the first such call results in an
2.138 + * <code>IOException</code>, that exception is returned from the call to
2.139 + * the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
2.140 + * any subsequent call to <code>read()</code> results in a
2.141 + * <code>IOException</code>, the exception is caught and treated as if it
2.142 + * were end of file; the bytes read up to that point are stored into
2.143 + * <code>b</code> and the number of bytes read before the exception
2.144 + * occurred is returned. The default implementation of this method blocks
2.145 + * until the requested amount of input data <code>len</code> has been read,
2.146 + * end of file is detected, or an exception is thrown. Subclasses are encouraged
2.147 + * to provide a more efficient implementation of this method.
2.148 + *
2.149 + * @param b the buffer into which the data is read.
2.150 + * @param off the start offset in array <code>b</code>
2.151 + * at which the data is written.
2.152 + * @param len the maximum number of bytes to read.
2.153 + * @return the total number of bytes read into the buffer, or
2.154 + * <code>-1</code> if there is no more data because the end of
2.155 + * the stream has been reached.
2.156 + * @exception IOException If the first byte cannot be read for any reason
2.157 + * other than end of file, or if the input stream has been closed, or if
2.158 + * some other I/O error occurs.
2.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
2.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
2.161 + * <code>len</code> is negative, or <code>len</code> is greater than
2.162 + * <code>b.length - off</code>
2.163 + * @see java.io.InputStream#read()
2.164 + */
2.165 + public int read(byte b[], int off, int len) throws IOException {
2.166 + if (b == null) {
2.167 + throw new NullPointerException();
2.168 + } else if (off < 0 || len < 0 || len > b.length - off) {
2.169 + throw new IndexOutOfBoundsException();
2.170 + } else if (len == 0) {
2.171 + return 0;
2.172 + }
2.173 +
2.174 + int c = read();
2.175 + if (c == -1) {
2.176 + return -1;
2.177 + }
2.178 + b[off] = (byte)c;
2.179 +
2.180 + int i = 1;
2.181 + try {
2.182 + for (; i < len ; i++) {
2.183 + c = read();
2.184 + if (c == -1) {
2.185 + break;
2.186 + }
2.187 + b[off + i] = (byte)c;
2.188 + }
2.189 + } catch (IOException ee) {
2.190 + }
2.191 + return i;
2.192 + }
2.193 +
2.194 + /**
2.195 + * Skips over and discards <code>n</code> bytes of data from this input
2.196 + * stream. The <code>skip</code> method may, for a variety of reasons, end
2.197 + * up skipping over some smaller number of bytes, possibly <code>0</code>.
2.198 + * This may result from any of a number of conditions; reaching end of file
2.199 + * before <code>n</code> bytes have been skipped is only one possibility.
2.200 + * The actual number of bytes skipped is returned. If <code>n</code> is
2.201 + * negative, no bytes are skipped.
2.202 + *
2.203 + * <p> The <code>skip</code> method of this class creates a
2.204 + * byte array and then repeatedly reads into it until <code>n</code> bytes
2.205 + * have been read or the end of the stream has been reached. Subclasses are
2.206 + * encouraged to provide a more efficient implementation of this method.
2.207 + * For instance, the implementation may depend on the ability to seek.
2.208 + *
2.209 + * @param n the number of bytes to be skipped.
2.210 + * @return the actual number of bytes skipped.
2.211 + * @exception IOException if the stream does not support seek,
2.212 + * or if some other I/O error occurs.
2.213 + */
2.214 + public long skip(long n) throws IOException {
2.215 +
2.216 + long remaining = n;
2.217 + int nr;
2.218 + if (skipBuffer == null)
2.219 + skipBuffer = new byte[SKIP_BUFFER_SIZE];
2.220 +
2.221 + byte[] localSkipBuffer = skipBuffer;
2.222 +
2.223 + if (n <= 0) {
2.224 + return 0;
2.225 + }
2.226 +
2.227 + while (remaining > 0) {
2.228 + nr = read(localSkipBuffer, 0,
2.229 + (int) Math.min(SKIP_BUFFER_SIZE, remaining));
2.230 + if (nr < 0) {
2.231 + break;
2.232 + }
2.233 + remaining -= nr;
2.234 + }
2.235 +
2.236 + return n - remaining;
2.237 + }
2.238 +
2.239 + /**
2.240 + * Returns an estimate of the number of bytes that can be read (or
2.241 + * skipped over) from this input stream without blocking by the next
2.242 + * invocation of a method for this input stream. The next invocation
2.243 + * might be the same thread or another thread. A single read or skip of this
2.244 + * many bytes will not block, but may read or skip fewer bytes.
2.245 + *
2.246 + * <p> Note that while some implementations of {@code InputStream} will return
2.247 + * the total number of bytes in the stream, many will not. It is
2.248 + * never correct to use the return value of this method to allocate
2.249 + * a buffer intended to hold all data in this stream.
2.250 + *
2.251 + * <p> A subclass' implementation of this method may choose to throw an
2.252 + * {@link IOException} if this input stream has been closed by
2.253 + * invoking the {@link #close()} method.
2.254 + *
2.255 + * <p> The {@code available} method for class {@code InputStream} always
2.256 + * returns {@code 0}.
2.257 + *
2.258 + * <p> This method should be overridden by subclasses.
2.259 + *
2.260 + * @return an estimate of the number of bytes that can be read (or skipped
2.261 + * over) from this input stream without blocking or {@code 0} when
2.262 + * it reaches the end of the input stream.
2.263 + * @exception IOException if an I/O error occurs.
2.264 + */
2.265 + public int available() throws IOException {
2.266 + return 0;
2.267 + }
2.268 +
2.269 + /**
2.270 + * Closes this input stream and releases any system resources associated
2.271 + * with the stream.
2.272 + *
2.273 + * <p> The <code>close</code> method of <code>InputStream</code> does
2.274 + * nothing.
2.275 + *
2.276 + * @exception IOException if an I/O error occurs.
2.277 + */
2.278 + public void close() throws IOException {}
2.279 +
2.280 + /**
2.281 + * Marks the current position in this input stream. A subsequent call to
2.282 + * the <code>reset</code> method repositions this stream at the last marked
2.283 + * position so that subsequent reads re-read the same bytes.
2.284 + *
2.285 + * <p> The <code>readlimit</code> arguments tells this input stream to
2.286 + * allow that many bytes to be read before the mark position gets
2.287 + * invalidated.
2.288 + *
2.289 + * <p> The general contract of <code>mark</code> is that, if the method
2.290 + * <code>markSupported</code> returns <code>true</code>, the stream somehow
2.291 + * remembers all the bytes read after the call to <code>mark</code> and
2.292 + * stands ready to supply those same bytes again if and whenever the method
2.293 + * <code>reset</code> is called. However, the stream is not required to
2.294 + * remember any data at all if more than <code>readlimit</code> bytes are
2.295 + * read from the stream before <code>reset</code> is called.
2.296 + *
2.297 + * <p> Marking a closed stream should not have any effect on the stream.
2.298 + *
2.299 + * <p> The <code>mark</code> method of <code>InputStream</code> does
2.300 + * nothing.
2.301 + *
2.302 + * @param readlimit the maximum limit of bytes that can be read before
2.303 + * the mark position becomes invalid.
2.304 + * @see java.io.InputStream#reset()
2.305 + */
2.306 + public synchronized void mark(int readlimit) {}
2.307 +
2.308 + /**
2.309 + * Repositions this stream to the position at the time the
2.310 + * <code>mark</code> method was last called on this input stream.
2.311 + *
2.312 + * <p> The general contract of <code>reset</code> is:
2.313 + *
2.314 + * <p><ul>
2.315 + *
2.316 + * <li> If the method <code>markSupported</code> returns
2.317 + * <code>true</code>, then:
2.318 + *
2.319 + * <ul><li> If the method <code>mark</code> has not been called since
2.320 + * the stream was created, or the number of bytes read from the stream
2.321 + * since <code>mark</code> was last called is larger than the argument
2.322 + * to <code>mark</code> at that last call, then an
2.323 + * <code>IOException</code> might be thrown.
2.324 + *
2.325 + * <li> If such an <code>IOException</code> is not thrown, then the
2.326 + * stream is reset to a state such that all the bytes read since the
2.327 + * most recent call to <code>mark</code> (or since the start of the
2.328 + * file, if <code>mark</code> has not been called) will be resupplied
2.329 + * to subsequent callers of the <code>read</code> method, followed by
2.330 + * any bytes that otherwise would have been the next input data as of
2.331 + * the time of the call to <code>reset</code>. </ul>
2.332 + *
2.333 + * <li> If the method <code>markSupported</code> returns
2.334 + * <code>false</code>, then:
2.335 + *
2.336 + * <ul><li> The call to <code>reset</code> may throw an
2.337 + * <code>IOException</code>.
2.338 + *
2.339 + * <li> If an <code>IOException</code> is not thrown, then the stream
2.340 + * is reset to a fixed state that depends on the particular type of the
2.341 + * input stream and how it was created. The bytes that will be supplied
2.342 + * to subsequent callers of the <code>read</code> method depend on the
2.343 + * particular type of the input stream. </ul></ul>
2.344 + *
2.345 + * <p>The method <code>reset</code> for class <code>InputStream</code>
2.346 + * does nothing except throw an <code>IOException</code>.
2.347 + *
2.348 + * @exception IOException if this stream has not been marked or if the
2.349 + * mark has been invalidated.
2.350 + * @see java.io.InputStream#mark(int)
2.351 + * @see java.io.IOException
2.352 + */
2.353 + public synchronized void reset() throws IOException {
2.354 + throw new IOException("mark/reset not supported");
2.355 + }
2.356 +
2.357 + /**
2.358 + * Tests if this input stream supports the <code>mark</code> and
2.359 + * <code>reset</code> methods. Whether or not <code>mark</code> and
2.360 + * <code>reset</code> are supported is an invariant property of a
2.361 + * particular input stream instance. The <code>markSupported</code> method
2.362 + * of <code>InputStream</code> returns <code>false</code>.
2.363 + *
2.364 + * @return <code>true</code> if this stream instance supports the mark
2.365 + * and reset methods; <code>false</code> otherwise.
2.366 + * @see java.io.InputStream#mark(int)
2.367 + * @see java.io.InputStream#reset()
2.368 + */
2.369 + public boolean markSupported() {
2.370 + return false;
2.371 + }
2.372 +
2.373 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/emul/src/main/java/java/lang/AutoCloseable.java Tue Oct 30 09:24:41 2012 +0100
3.3 @@ -0,0 +1,72 @@
3.4 +/*
3.5 + * Copyright (c) 2009, 2011, 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 +
3.29 +package java.lang;
3.30 +
3.31 +/**
3.32 + * A resource that must be closed when it is no longer needed.
3.33 + *
3.34 + * @author Josh Bloch
3.35 + * @since 1.7
3.36 + */
3.37 +public interface AutoCloseable {
3.38 + /**
3.39 + * Closes this resource, relinquishing any underlying resources.
3.40 + * This method is invoked automatically on objects managed by the
3.41 + * {@code try}-with-resources statement.
3.42 + *
3.43 + * <p>While this interface method is declared to throw {@code
3.44 + * Exception}, implementers are <em>strongly</em> encouraged to
3.45 + * declare concrete implementations of the {@code close} method to
3.46 + * throw more specific exceptions, or to throw no exception at all
3.47 + * if the close operation cannot fail.
3.48 + *
3.49 + * <p><em>Implementers of this interface are also strongly advised
3.50 + * to not have the {@code close} method throw {@link
3.51 + * InterruptedException}.</em>
3.52 + *
3.53 + * This exception interacts with a thread's interrupted status,
3.54 + * and runtime misbehavior is likely to occur if an {@code
3.55 + * InterruptedException} is {@linkplain Throwable#addSuppressed
3.56 + * suppressed}.
3.57 + *
3.58 + * More generally, if it would cause problems for an
3.59 + * exception to be suppressed, the {@code AutoCloseable.close}
3.60 + * method should not throw it.
3.61 + *
3.62 + * <p>Note that unlike the {@link java.io.Closeable#close close}
3.63 + * method of {@link java.io.Closeable}, this {@code close} method
3.64 + * is <em>not</em> required to be idempotent. In other words,
3.65 + * calling this {@code close} method more than once may have some
3.66 + * visible side effect, unlike {@code Closeable.close} which is
3.67 + * required to have no effect if called more than once.
3.68 + *
3.69 + * However, implementers of this interface are strongly encouraged
3.70 + * to make their {@code close} methods idempotent.
3.71 + *
3.72 + * @throws Exception if this resource cannot be closed
3.73 + */
3.74 + void close() throws Exception;
3.75 +}
4.1 --- a/emul/src/main/java/java/lang/Class.java Mon Oct 29 13:05:56 2012 +0100
4.2 +++ b/emul/src/main/java/java/lang/Class.java Tue Oct 30 09:24:41 2012 +0100
4.3 @@ -25,6 +25,7 @@
4.4
4.5 package java.lang;
4.6
4.7 +import java.io.InputStream;
4.8 import java.lang.annotation.Annotation;
4.9
4.10 /**
4.11 @@ -552,15 +553,15 @@
4.12 * @throws NullPointerException If {@code name} is {@code null}
4.13 * @since JDK1.1
4.14 */
4.15 -// public InputStream getResourceAsStream(String name) {
4.16 -// name = resolveName(name);
4.17 -// ClassLoader cl = getClassLoader0();
4.18 -// if (cl==null) {
4.19 -// // A system class.
4.20 -// return ClassLoader.getSystemResourceAsStream(name);
4.21 -// }
4.22 -// return cl.getResourceAsStream(name);
4.23 -// }
4.24 + public InputStream getResourceAsStream(String name) {
4.25 + name = resolveName(name);
4.26 + ClassLoader cl = getClassLoader0();
4.27 + if (cl==null) {
4.28 + // A system class.
4.29 + return ClassLoader.getSystemResourceAsStream(name);
4.30 + }
4.31 + return cl.getResourceAsStream(name);
4.32 + }
4.33
4.34 /**
4.35 * Finds a resource with a given name. The rules for searching resources
4.36 @@ -596,18 +597,86 @@
4.37 * resource with this name is found
4.38 * @since JDK1.1
4.39 */
4.40 -// public java.net.URL getResource(String name) {
4.41 -// name = resolveName(name);
4.42 -// ClassLoader cl = getClassLoader0();
4.43 -// if (cl==null) {
4.44 -// // A system class.
4.45 -// return ClassLoader.getSystemResource(name);
4.46 -// }
4.47 -// return cl.getResource(name);
4.48 -// }
4.49 + public java.net.URL getResource(String name) {
4.50 + name = resolveName(name);
4.51 + ClassLoader cl = getClassLoader0();
4.52 + if (cl==null) {
4.53 + // A system class.
4.54 + return ClassLoader.getSystemResource(name);
4.55 + }
4.56 + return cl.getResource(name);
4.57 + }
4.58
4.59
4.60 + /**
4.61 + * Add a package name prefix if the name is not absolute Remove leading "/"
4.62 + * if name is absolute
4.63 + */
4.64 + private String resolveName(String name) {
4.65 + if (name == null) {
4.66 + return name;
4.67 + }
4.68 + if (!name.startsWith("/")) {
4.69 + Class<?> c = this;
4.70 + while (c.isArray()) {
4.71 + c = c.getComponentType();
4.72 + }
4.73 + String baseName = c.getName();
4.74 + int index = baseName.lastIndexOf('.');
4.75 + if (index != -1) {
4.76 + name = baseName.substring(0, index).replace('.', '/')
4.77 + +"/"+name;
4.78 + }
4.79 + } else {
4.80 + name = name.substring(1);
4.81 + }
4.82 + return name;
4.83 + }
4.84 +
4.85 + /**
4.86 + * Returns the class loader for the class. Some implementations may use
4.87 + * null to represent the bootstrap class loader. This method will return
4.88 + * null in such implementations if this class was loaded by the bootstrap
4.89 + * class loader.
4.90 + *
4.91 + * <p> If a security manager is present, and the caller's class loader is
4.92 + * not null and the caller's class loader is not the same as or an ancestor of
4.93 + * the class loader for the class whose class loader is requested, then
4.94 + * this method calls the security manager's {@code checkPermission}
4.95 + * method with a {@code RuntimePermission("getClassLoader")}
4.96 + * permission to ensure it's ok to access the class loader for the class.
4.97 + *
4.98 + * <p>If this object
4.99 + * represents a primitive type or void, null is returned.
4.100 + *
4.101 + * @return the class loader that loaded the class or interface
4.102 + * represented by this object.
4.103 + * @throws SecurityException
4.104 + * if a security manager exists and its
4.105 + * {@code checkPermission} method denies
4.106 + * access to the class loader for the class.
4.107 + * @see java.lang.ClassLoader
4.108 + * @see SecurityManager#checkPermission
4.109 + * @see java.lang.RuntimePermission
4.110 + */
4.111 + public ClassLoader getClassLoader() {
4.112 + throw new SecurityException();
4.113 + }
4.114 +
4.115 + // Package-private to allow ClassLoader access
4.116 + native ClassLoader getClassLoader0();
4.117
4.118 + /**
4.119 + * Returns the {@code Class} representing the component type of an
4.120 + * array. If this class does not represent an array class this method
4.121 + * returns null.
4.122 + *
4.123 + * @return the {@code Class} representing the component type of this
4.124 + * class if this class is an array
4.125 + * @see java.lang.reflect.Array
4.126 + * @since JDK1.1
4.127 + */
4.128 + public native Class<?> getComponentType();
4.129
4.130 /**
4.131 * Returns true if and only if this class was declared as an enum in the
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/emul/src/main/java/java/lang/ClassFormatError.java Tue Oct 30 09:24:41 2012 +0100
5.3 @@ -0,0 +1,56 @@
5.4 +/*
5.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5.7 + *
5.8 + * This code is free software; you can redistribute it and/or modify it
5.9 + * under the terms of the GNU General Public License version 2 only, as
5.10 + * published by the Free Software Foundation. Oracle designates this
5.11 + * particular file as subject to the "Classpath" exception as provided
5.12 + * by Oracle in the LICENSE file that accompanied this code.
5.13 + *
5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5.17 + * version 2 for more details (a copy is included in the LICENSE file that
5.18 + * accompanied this code).
5.19 + *
5.20 + * You should have received a copy of the GNU General Public License version
5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5.23 + *
5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5.25 + * or visit www.oracle.com if you need additional information or have any
5.26 + * questions.
5.27 + */
5.28 +
5.29 +package java.lang;
5.30 +
5.31 +/**
5.32 + * Thrown when the Java Virtual Machine attempts to read a class
5.33 + * file and determines that the file is malformed or otherwise cannot
5.34 + * be interpreted as a class file.
5.35 + *
5.36 + * @author unascribed
5.37 + * @since JDK1.0
5.38 + */
5.39 +public
5.40 +class ClassFormatError extends LinkageError {
5.41 + private static final long serialVersionUID = -8420114879011949195L;
5.42 +
5.43 + /**
5.44 + * Constructs a <code>ClassFormatError</code> with no detail message.
5.45 + */
5.46 + public ClassFormatError() {
5.47 + super();
5.48 + }
5.49 +
5.50 + /**
5.51 + * Constructs a <code>ClassFormatError</code> with the specified
5.52 + * detail message.
5.53 + *
5.54 + * @param s the detail message.
5.55 + */
5.56 + public ClassFormatError(String s) {
5.57 + super(s);
5.58 + }
5.59 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/src/main/java/java/lang/ClassLoader.java Tue Oct 30 09:24:41 2012 +0100
6.3 @@ -0,0 +1,912 @@
6.4 +/*
6.5 + * Copyright (c) 1994, 2011, 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 +package java.lang;
6.29 +
6.30 +import java.io.InputStream;
6.31 +import java.io.IOException;
6.32 +import java.net.URL;
6.33 +import java.util.Enumeration;
6.34 +import java.util.NoSuchElementException;
6.35 +
6.36 +/**
6.37 + * A class loader is an object that is responsible for loading classes. The
6.38 + * class <tt>ClassLoader</tt> is an abstract class. Given the <a
6.39 + * href="#name">binary name</a> of a class, a class loader should attempt to
6.40 + * locate or generate data that constitutes a definition for the class. A
6.41 + * typical strategy is to transform the name into a file name and then read a
6.42 + * "class file" of that name from a file system.
6.43 + *
6.44 + * <p> Every {@link Class <tt>Class</tt>} object contains a {@link
6.45 + * Class#getClassLoader() reference} to the <tt>ClassLoader</tt> that defined
6.46 + * it.
6.47 + *
6.48 + * <p> <tt>Class</tt> objects for array classes are not created by class
6.49 + * loaders, but are created automatically as required by the Java runtime.
6.50 + * The class loader for an array class, as returned by {@link
6.51 + * Class#getClassLoader()} is the same as the class loader for its element
6.52 + * type; if the element type is a primitive type, then the array class has no
6.53 + * class loader.
6.54 + *
6.55 + * <p> Applications implement subclasses of <tt>ClassLoader</tt> in order to
6.56 + * extend the manner in which the Java virtual machine dynamically loads
6.57 + * classes.
6.58 + *
6.59 + * <p> Class loaders may typically be used by security managers to indicate
6.60 + * security domains.
6.61 + *
6.62 + * <p> The <tt>ClassLoader</tt> class uses a delegation model to search for
6.63 + * classes and resources. Each instance of <tt>ClassLoader</tt> has an
6.64 + * associated parent class loader. When requested to find a class or
6.65 + * resource, a <tt>ClassLoader</tt> instance will delegate the search for the
6.66 + * class or resource to its parent class loader before attempting to find the
6.67 + * class or resource itself. The virtual machine's built-in class loader,
6.68 + * called the "bootstrap class loader", does not itself have a parent but may
6.69 + * serve as the parent of a <tt>ClassLoader</tt> instance.
6.70 + *
6.71 + * <p> Class loaders that support concurrent loading of classes are known as
6.72 + * <em>parallel capable</em> class loaders and are required to register
6.73 + * themselves at their class initialization time by invoking the
6.74 + * {@link
6.75 + * #registerAsParallelCapable <tt>ClassLoader.registerAsParallelCapable</tt>}
6.76 + * method. Note that the <tt>ClassLoader</tt> class is registered as parallel
6.77 + * capable by default. However, its subclasses still need to register themselves
6.78 + * if they are parallel capable. <br>
6.79 + * In environments in which the delegation model is not strictly
6.80 + * hierarchical, class loaders need to be parallel capable, otherwise class
6.81 + * loading can lead to deadlocks because the loader lock is held for the
6.82 + * duration of the class loading process (see {@link #loadClass
6.83 + * <tt>loadClass</tt>} methods).
6.84 + *
6.85 + * <p> Normally, the Java virtual machine loads classes from the local file
6.86 + * system in a platform-dependent manner. For example, on UNIX systems, the
6.87 + * virtual machine loads classes from the directory defined by the
6.88 + * <tt>CLASSPATH</tt> environment variable.
6.89 + *
6.90 + * <p> However, some classes may not originate from a file; they may originate
6.91 + * from other sources, such as the network, or they could be constructed by an
6.92 + * application. The method {@link #defineClass(String, byte[], int, int)
6.93 + * <tt>defineClass</tt>} converts an array of bytes into an instance of class
6.94 + * <tt>Class</tt>. Instances of this newly defined class can be created using
6.95 + * {@link Class#newInstance <tt>Class.newInstance</tt>}.
6.96 + *
6.97 + * <p> The methods and constructors of objects created by a class loader may
6.98 + * reference other classes. To determine the class(es) referred to, the Java
6.99 + * virtual machine invokes the {@link #loadClass <tt>loadClass</tt>} method of
6.100 + * the class loader that originally created the class.
6.101 + *
6.102 + * <p> For example, an application could create a network class loader to
6.103 + * download class files from a server. Sample code might look like:
6.104 + *
6.105 + * <blockquote><pre>
6.106 + * ClassLoader loader = new NetworkClassLoader(host, port);
6.107 + * Object main = loader.loadClass("Main", true).newInstance();
6.108 + * . . .
6.109 + * </pre></blockquote>
6.110 + *
6.111 + * <p> The network class loader subclass must define the methods {@link
6.112 + * #findClass <tt>findClass</tt>} and <tt>loadClassData</tt> to load a class
6.113 + * from the network. Once it has downloaded the bytes that make up the class,
6.114 + * it should use the method {@link #defineClass <tt>defineClass</tt>} to
6.115 + * create a class instance. A sample implementation is:
6.116 + *
6.117 + * <blockquote><pre>
6.118 + * class NetworkClassLoader extends ClassLoader {
6.119 + * String host;
6.120 + * int port;
6.121 + *
6.122 + * public Class findClass(String name) {
6.123 + * byte[] b = loadClassData(name);
6.124 + * return defineClass(name, b, 0, b.length);
6.125 + * }
6.126 + *
6.127 + * private byte[] loadClassData(String name) {
6.128 + * // load the class data from the connection
6.129 + * . . .
6.130 + * }
6.131 + * }
6.132 + * </pre></blockquote>
6.133 + *
6.134 + * <h4> <a name="name">Binary names</a> </h4>
6.135 + *
6.136 + * <p> Any class name provided as a {@link String} parameter to methods in
6.137 + * <tt>ClassLoader</tt> must be a binary name as defined by
6.138 + * <cite>The Java™ Language Specification</cite>.
6.139 + *
6.140 + * <p> Examples of valid class names include:
6.141 + * <blockquote><pre>
6.142 + * "java.lang.String"
6.143 + * "javax.swing.JSpinner$DefaultEditor"
6.144 + * "java.security.KeyStore$Builder$FileBuilder$1"
6.145 + * "java.net.URLClassLoader$3$1"
6.146 + * </pre></blockquote>
6.147 + *
6.148 + * @see #resolveClass(Class)
6.149 + * @since 1.0
6.150 + */
6.151 +public abstract class ClassLoader {
6.152 +
6.153 + private static native void registerNatives();
6.154 + static {
6.155 + registerNatives();
6.156 + }
6.157 +
6.158 + // The parent class loader for delegation
6.159 + // Note: VM hardcoded the offset of this field, thus all new fields
6.160 + // must be added *after* it.
6.161 + private final ClassLoader parent;
6.162 +
6.163 +
6.164 + /**
6.165 + * Creates a new class loader using the specified parent class loader for
6.166 + * delegation.
6.167 + *
6.168 + * <p> If there is a security manager, its {@link
6.169 + * SecurityManager#checkCreateClassLoader()
6.170 + * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
6.171 + * a security exception. </p>
6.172 + *
6.173 + * @param parent
6.174 + * The parent class loader
6.175 + *
6.176 + * @throws SecurityException
6.177 + * If a security manager exists and its
6.178 + * <tt>checkCreateClassLoader</tt> method doesn't allow creation
6.179 + * of a new class loader.
6.180 + *
6.181 + * @since 1.2
6.182 + */
6.183 + protected ClassLoader(ClassLoader parent) {
6.184 + throw new SecurityException();
6.185 + }
6.186 +
6.187 + /**
6.188 + * Creates a new class loader using the <tt>ClassLoader</tt> returned by
6.189 + * the method {@link #getSystemClassLoader()
6.190 + * <tt>getSystemClassLoader()</tt>} as the parent class loader.
6.191 + *
6.192 + * <p> If there is a security manager, its {@link
6.193 + * SecurityManager#checkCreateClassLoader()
6.194 + * <tt>checkCreateClassLoader</tt>} method is invoked. This may result in
6.195 + * a security exception. </p>
6.196 + *
6.197 + * @throws SecurityException
6.198 + * If a security manager exists and its
6.199 + * <tt>checkCreateClassLoader</tt> method doesn't allow creation
6.200 + * of a new class loader.
6.201 + */
6.202 + protected ClassLoader() {
6.203 + throw new SecurityException();
6.204 + }
6.205 +
6.206 + // -- Class --
6.207 +
6.208 + /**
6.209 + * Loads the class with the specified <a href="#name">binary name</a>.
6.210 + * This method searches for classes in the same manner as the {@link
6.211 + * #loadClass(String, boolean)} method. It is invoked by the Java virtual
6.212 + * machine to resolve class references. Invoking this method is equivalent
6.213 + * to invoking {@link #loadClass(String, boolean) <tt>loadClass(name,
6.214 + * false)</tt>}. </p>
6.215 + *
6.216 + * @param name
6.217 + * The <a href="#name">binary name</a> of the class
6.218 + *
6.219 + * @return The resulting <tt>Class</tt> object
6.220 + *
6.221 + * @throws ClassNotFoundException
6.222 + * If the class was not found
6.223 + */
6.224 + public Class<?> loadClass(String name) throws ClassNotFoundException {
6.225 + return loadClass(name, false);
6.226 + }
6.227 +
6.228 + /**
6.229 + * Loads the class with the specified <a href="#name">binary name</a>. The
6.230 + * default implementation of this method searches for classes in the
6.231 + * following order:
6.232 + *
6.233 + * <p><ol>
6.234 + *
6.235 + * <li><p> Invoke {@link #findLoadedClass(String)} to check if the class
6.236 + * has already been loaded. </p></li>
6.237 + *
6.238 + * <li><p> Invoke the {@link #loadClass(String) <tt>loadClass</tt>} method
6.239 + * on the parent class loader. If the parent is <tt>null</tt> the class
6.240 + * loader built-in to the virtual machine is used, instead. </p></li>
6.241 + *
6.242 + * <li><p> Invoke the {@link #findClass(String)} method to find the
6.243 + * class. </p></li>
6.244 + *
6.245 + * </ol>
6.246 + *
6.247 + * <p> If the class was found using the above steps, and the
6.248 + * <tt>resolve</tt> flag is true, this method will then invoke the {@link
6.249 + * #resolveClass(Class)} method on the resulting <tt>Class</tt> object.
6.250 + *
6.251 + * <p> Subclasses of <tt>ClassLoader</tt> are encouraged to override {@link
6.252 + * #findClass(String)}, rather than this method. </p>
6.253 + *
6.254 + * <p> Unless overridden, this method synchronizes on the result of
6.255 + * {@link #getClassLoadingLock <tt>getClassLoadingLock</tt>} method
6.256 + * during the entire class loading process.
6.257 + *
6.258 + * @param name
6.259 + * The <a href="#name">binary name</a> of the class
6.260 + *
6.261 + * @param resolve
6.262 + * If <tt>true</tt> then resolve the class
6.263 + *
6.264 + * @return The resulting <tt>Class</tt> object
6.265 + *
6.266 + * @throws ClassNotFoundException
6.267 + * If the class could not be found
6.268 + */
6.269 + protected Class<?> loadClass(String name, boolean resolve)
6.270 + throws ClassNotFoundException
6.271 + {
6.272 + synchronized (getClassLoadingLock(name)) {
6.273 + // First, check if the class has already been loaded
6.274 + Class c = findLoadedClass(name);
6.275 + if (c == null) {
6.276 + try {
6.277 + if (parent != null) {
6.278 + c = parent.loadClass(name, false);
6.279 + } else {
6.280 + c = findBootstrapClassOrNull(name);
6.281 + }
6.282 + } catch (ClassNotFoundException e) {
6.283 + // ClassNotFoundException thrown if class not found
6.284 + // from the non-null parent class loader
6.285 + }
6.286 +
6.287 + if (c == null) {
6.288 + // If still not found, then invoke findClass in order
6.289 + // to find the class.
6.290 + c = findClass(name);
6.291 +
6.292 +// // this is the defining class loader; record the stats
6.293 +// sun.misc.PerfCounter.getParentDelegationTime().addTime(t1 - t0);
6.294 +// sun.misc.PerfCounter.getFindClassTime().addElapsedTimeFrom(t1);
6.295 +// sun.misc.PerfCounter.getFindClasses().increment();
6.296 + }
6.297 + }
6.298 + if (resolve) {
6.299 + resolveClass(c);
6.300 + }
6.301 + return c;
6.302 + }
6.303 + }
6.304 +
6.305 + /**
6.306 + * Returns the lock object for class loading operations.
6.307 + * For backward compatibility, the default implementation of this method
6.308 + * behaves as follows. If this ClassLoader object is registered as
6.309 + * parallel capable, the method returns a dedicated object associated
6.310 + * with the specified class name. Otherwise, the method returns this
6.311 + * ClassLoader object. </p>
6.312 + *
6.313 + * @param className
6.314 + * The name of the to-be-loaded class
6.315 + *
6.316 + * @return the lock for class loading operations
6.317 + *
6.318 + * @throws NullPointerException
6.319 + * If registered as parallel capable and <tt>className</tt> is null
6.320 + *
6.321 + * @see #loadClass(String, boolean)
6.322 + *
6.323 + * @since 1.7
6.324 + */
6.325 + protected Object getClassLoadingLock(String className) {
6.326 + Object lock = this;
6.327 + return lock;
6.328 + }
6.329 +
6.330 + /**
6.331 + * Finds the class with the specified <a href="#name">binary name</a>.
6.332 + * This method should be overridden by class loader implementations that
6.333 + * follow the delegation model for loading classes, and will be invoked by
6.334 + * the {@link #loadClass <tt>loadClass</tt>} method after checking the
6.335 + * parent class loader for the requested class. The default implementation
6.336 + * throws a <tt>ClassNotFoundException</tt>. </p>
6.337 + *
6.338 + * @param name
6.339 + * The <a href="#name">binary name</a> of the class
6.340 + *
6.341 + * @return The resulting <tt>Class</tt> object
6.342 + *
6.343 + * @throws ClassNotFoundException
6.344 + * If the class could not be found
6.345 + *
6.346 + * @since 1.2
6.347 + */
6.348 + protected Class<?> findClass(String name) throws ClassNotFoundException {
6.349 + throw new ClassNotFoundException(name);
6.350 + }
6.351 +
6.352 + /**
6.353 + * Converts an array of bytes into an instance of class <tt>Class</tt>.
6.354 + * Before the <tt>Class</tt> can be used it must be resolved. This method
6.355 + * is deprecated in favor of the version that takes a <a
6.356 + * href="#name">binary name</a> as its first argument, and is more secure.
6.357 + *
6.358 + * @param b
6.359 + * The bytes that make up the class data. The bytes in positions
6.360 + * <tt>off</tt> through <tt>off+len-1</tt> should have the format
6.361 + * of a valid class file as defined by
6.362 + * <cite>The Java™ Virtual Machine Specification</cite>.
6.363 + *
6.364 + * @param off
6.365 + * The start offset in <tt>b</tt> of the class data
6.366 + *
6.367 + * @param len
6.368 + * The length of the class data
6.369 + *
6.370 + * @return The <tt>Class</tt> object that was created from the specified
6.371 + * class data
6.372 + *
6.373 + * @throws ClassFormatError
6.374 + * If the data did not contain a valid class
6.375 + *
6.376 + * @throws IndexOutOfBoundsException
6.377 + * If either <tt>off</tt> or <tt>len</tt> is negative, or if
6.378 + * <tt>off+len</tt> is greater than <tt>b.length</tt>.
6.379 + *
6.380 + * @throws SecurityException
6.381 + * If an attempt is made to add this class to a package that
6.382 + * contains classes that were signed by a different set of
6.383 + * certificates than this class, or if an attempt is made
6.384 + * to define a class in a package with a fully-qualified name
6.385 + * that starts with "{@code java.}".
6.386 + *
6.387 + * @see #loadClass(String, boolean)
6.388 + * @see #resolveClass(Class)
6.389 + *
6.390 + * @deprecated Replaced by {@link #defineClass(String, byte[], int, int)
6.391 + * defineClass(String, byte[], int, int)}
6.392 + */
6.393 + @Deprecated
6.394 + protected final Class<?> defineClass(byte[] b, int off, int len)
6.395 + throws ClassFormatError
6.396 + {
6.397 + throw new SecurityException();
6.398 + }
6.399 +
6.400 + /**
6.401 + * Converts an array of bytes into an instance of class <tt>Class</tt>.
6.402 + * Before the <tt>Class</tt> can be used it must be resolved.
6.403 + *
6.404 + * <p> This method assigns a default {@link java.security.ProtectionDomain
6.405 + * <tt>ProtectionDomain</tt>} to the newly defined class. The
6.406 + * <tt>ProtectionDomain</tt> is effectively granted the same set of
6.407 + * permissions returned when {@link
6.408 + * java.security.Policy#getPermissions(java.security.CodeSource)
6.409 + * <tt>Policy.getPolicy().getPermissions(new CodeSource(null, null))</tt>}
6.410 + * is invoked. The default domain is created on the first invocation of
6.411 + * {@link #defineClass(String, byte[], int, int) <tt>defineClass</tt>},
6.412 + * and re-used on subsequent invocations.
6.413 + *
6.414 + * <p> To assign a specific <tt>ProtectionDomain</tt> to the class, use
6.415 + * the {@link #defineClass(String, byte[], int, int,
6.416 + * java.security.ProtectionDomain) <tt>defineClass</tt>} method that takes a
6.417 + * <tt>ProtectionDomain</tt> as one of its arguments. </p>
6.418 + *
6.419 + * @param name
6.420 + * The expected <a href="#name">binary name</a> of the class, or
6.421 + * <tt>null</tt> if not known
6.422 + *
6.423 + * @param b
6.424 + * The bytes that make up the class data. The bytes in positions
6.425 + * <tt>off</tt> through <tt>off+len-1</tt> should have the format
6.426 + * of a valid class file as defined by
6.427 + * <cite>The Java™ Virtual Machine Specification</cite>.
6.428 + *
6.429 + * @param off
6.430 + * The start offset in <tt>b</tt> of the class data
6.431 + *
6.432 + * @param len
6.433 + * The length of the class data
6.434 + *
6.435 + * @return The <tt>Class</tt> object that was created from the specified
6.436 + * class data.
6.437 + *
6.438 + * @throws ClassFormatError
6.439 + * If the data did not contain a valid class
6.440 + *
6.441 + * @throws IndexOutOfBoundsException
6.442 + * If either <tt>off</tt> or <tt>len</tt> is negative, or if
6.443 + * <tt>off+len</tt> is greater than <tt>b.length</tt>.
6.444 + *
6.445 + * @throws SecurityException
6.446 + * If an attempt is made to add this class to a package that
6.447 + * contains classes that were signed by a different set of
6.448 + * certificates than this class (which is unsigned), or if
6.449 + * <tt>name</tt> begins with "<tt>java.</tt>".
6.450 + *
6.451 + * @see #loadClass(String, boolean)
6.452 + * @see #resolveClass(Class)
6.453 + * @see java.security.CodeSource
6.454 + * @see java.security.SecureClassLoader
6.455 + *
6.456 + * @since 1.1
6.457 + */
6.458 + protected final Class<?> defineClass(String name, byte[] b, int off, int len)
6.459 + throws ClassFormatError
6.460 + {
6.461 + throw new SecurityException();
6.462 + }
6.463 +
6.464 + /**
6.465 + * Links the specified class. This (misleadingly named) method may be
6.466 + * used by a class loader to link a class. If the class <tt>c</tt> has
6.467 + * already been linked, then this method simply returns. Otherwise, the
6.468 + * class is linked as described in the "Execution" chapter of
6.469 + * <cite>The Java™ Language Specification</cite>.
6.470 + * </p>
6.471 + *
6.472 + * @param c
6.473 + * The class to link
6.474 + *
6.475 + * @throws NullPointerException
6.476 + * If <tt>c</tt> is <tt>null</tt>.
6.477 + *
6.478 + * @see #defineClass(String, byte[], int, int)
6.479 + */
6.480 + protected final void resolveClass(Class<?> c) {
6.481 + resolveClass0(c);
6.482 + }
6.483 +
6.484 + private native void resolveClass0(Class c);
6.485 +
6.486 +
6.487 + /**
6.488 + * Returns the class with the given <a href="#name">binary name</a> if this
6.489 + * loader has been recorded by the Java virtual machine as an initiating
6.490 + * loader of a class with that <a href="#name">binary name</a>. Otherwise
6.491 + * <tt>null</tt> is returned. </p>
6.492 + *
6.493 + * @param name
6.494 + * The <a href="#name">binary name</a> of the class
6.495 + *
6.496 + * @return The <tt>Class</tt> object, or <tt>null</tt> if the class has
6.497 + * not been loaded
6.498 + *
6.499 + * @since 1.1
6.500 + */
6.501 + protected final Class<?> findLoadedClass(String name) {
6.502 + if (!checkName(name))
6.503 + return null;
6.504 + return findLoadedClass0(name);
6.505 + }
6.506 +
6.507 + private native final Class findLoadedClass0(String name);
6.508 +
6.509 + /**
6.510 + * Sets the signers of a class. This should be invoked after defining a
6.511 + * class. </p>
6.512 + *
6.513 + * @param c
6.514 + * The <tt>Class</tt> object
6.515 + *
6.516 + * @param signers
6.517 + * The signers for the class
6.518 + *
6.519 + * @since 1.1
6.520 + */
6.521 + protected final void setSigners(Class<?> c, Object[] signers) {
6.522 + //c.setSigners(signers);
6.523 + throw new UnsupportedOperationException();
6.524 + }
6.525 +
6.526 +
6.527 + // -- Resource --
6.528 +
6.529 + /**
6.530 + * Finds the resource with the given name. A resource is some data
6.531 + * (images, audio, text, etc) that can be accessed by class code in a way
6.532 + * that is independent of the location of the code.
6.533 + *
6.534 + * <p> The name of a resource is a '<tt>/</tt>'-separated path name that
6.535 + * identifies the resource.
6.536 + *
6.537 + * <p> This method will first search the parent class loader for the
6.538 + * resource; if the parent is <tt>null</tt> the path of the class loader
6.539 + * built-in to the virtual machine is searched. That failing, this method
6.540 + * will invoke {@link #findResource(String)} to find the resource. </p>
6.541 + *
6.542 + * @param name
6.543 + * The resource name
6.544 + *
6.545 + * @return A <tt>URL</tt> object for reading the resource, or
6.546 + * <tt>null</tt> if the resource could not be found or the invoker
6.547 + * doesn't have adequate privileges to get the resource.
6.548 + *
6.549 + * @since 1.1
6.550 + */
6.551 + public URL getResource(String name) {
6.552 + URL url;
6.553 + if (parent != null) {
6.554 + url = parent.getResource(name);
6.555 + } else {
6.556 + url = getBootstrapResource(name);
6.557 + }
6.558 + if (url == null) {
6.559 + url = findResource(name);
6.560 + }
6.561 + return url;
6.562 + }
6.563 +
6.564 + /**
6.565 + * Finds all the resources with the given name. A resource is some data
6.566 + * (images, audio, text, etc) that can be accessed by class code in a way
6.567 + * that is independent of the location of the code.
6.568 + *
6.569 + * <p>The name of a resource is a <tt>/</tt>-separated path name that
6.570 + * identifies the resource.
6.571 + *
6.572 + * <p> The search order is described in the documentation for {@link
6.573 + * #getResource(String)}. </p>
6.574 + *
6.575 + * @param name
6.576 + * The resource name
6.577 + *
6.578 + * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
6.579 + * the resource. If no resources could be found, the enumeration
6.580 + * will be empty. Resources that the class loader doesn't have
6.581 + * access to will not be in the enumeration.
6.582 + *
6.583 + * @throws IOException
6.584 + * If I/O errors occur
6.585 + *
6.586 + * @see #findResources(String)
6.587 + *
6.588 + * @since 1.2
6.589 + */
6.590 + public Enumeration<URL> getResources(String name) throws IOException {
6.591 + Enumeration[] tmp = new Enumeration[2];
6.592 + if (parent != null) {
6.593 + tmp[0] = parent.getResources(name);
6.594 + } else {
6.595 + tmp[0] = getBootstrapResources(name);
6.596 + }
6.597 + tmp[1] = findResources(name);
6.598 +
6.599 + return new CompoundEnumeration(tmp);
6.600 + }
6.601 +
6.602 + /**
6.603 + * Finds the resource with the given name. Class loader implementations
6.604 + * should override this method to specify where to find resources. </p>
6.605 + *
6.606 + * @param name
6.607 + * The resource name
6.608 + *
6.609 + * @return A <tt>URL</tt> object for reading the resource, or
6.610 + * <tt>null</tt> if the resource could not be found
6.611 + *
6.612 + * @since 1.2
6.613 + */
6.614 + protected URL findResource(String name) {
6.615 + return null;
6.616 + }
6.617 +
6.618 + /**
6.619 + * Returns an enumeration of {@link java.net.URL <tt>URL</tt>} objects
6.620 + * representing all the resources with the given name. Class loader
6.621 + * implementations should override this method to specify where to load
6.622 + * resources from. </p>
6.623 + *
6.624 + * @param name
6.625 + * The resource name
6.626 + *
6.627 + * @return An enumeration of {@link java.net.URL <tt>URL</tt>} objects for
6.628 + * the resources
6.629 + *
6.630 + * @throws IOException
6.631 + * If I/O errors occur
6.632 + *
6.633 + * @since 1.2
6.634 + */
6.635 + protected Enumeration<URL> findResources(String name) throws IOException {
6.636 + return new CompoundEnumeration(new Enumeration[0]);
6.637 + }
6.638 +
6.639 + // index 0: java.lang.ClassLoader.class
6.640 + // index 1: the immediate caller of index 0.
6.641 + // index 2: the immediate caller of index 1.
6.642 + private static native Class<? extends ClassLoader> getCaller(int index);
6.643 +
6.644 + /**
6.645 + * Registers the caller as parallel capable.</p>
6.646 + * The registration succeeds if and only if all of the following
6.647 + * conditions are met: <br>
6.648 + * 1. no instance of the caller has been created</p>
6.649 + * 2. all of the super classes (except class Object) of the caller are
6.650 + * registered as parallel capable</p>
6.651 + * Note that once a class loader is registered as parallel capable, there
6.652 + * is no way to change it back. </p>
6.653 + *
6.654 + * @return true if the caller is successfully registered as
6.655 + * parallel capable and false if otherwise.
6.656 + *
6.657 + * @since 1.7
6.658 + */
6.659 +// protected static boolean registerAsParallelCapable() {
6.660 +// return false;
6.661 +// }
6.662 +
6.663 + /**
6.664 + * Find a resource of the specified name from the search path used to load
6.665 + * classes. This method locates the resource through the system class
6.666 + * loader (see {@link #getSystemClassLoader()}). </p>
6.667 + *
6.668 + * @param name
6.669 + * The resource name
6.670 + *
6.671 + * @return A {@link java.net.URL <tt>URL</tt>} object for reading the
6.672 + * resource, or <tt>null</tt> if the resource could not be found
6.673 + *
6.674 + * @since 1.1
6.675 + */
6.676 + public static URL getSystemResource(String name) {
6.677 + ClassLoader system = getSystemClassLoader();
6.678 + if (system == null) {
6.679 + return getBootstrapResource(name);
6.680 + }
6.681 + return system.getResource(name);
6.682 + }
6.683 +
6.684 + /**
6.685 + * Finds all resources of the specified name from the search path used to
6.686 + * load classes. The resources thus found are returned as an
6.687 + * {@link java.util.Enumeration <tt>Enumeration</tt>} of {@link
6.688 + * java.net.URL <tt>URL</tt>} objects.
6.689 + *
6.690 + * <p> The search order is described in the documentation for {@link
6.691 + * #getSystemResource(String)}. </p>
6.692 + *
6.693 + * @param name
6.694 + * The resource name
6.695 + *
6.696 + * @return An enumeration of resource {@link java.net.URL <tt>URL</tt>}
6.697 + * objects
6.698 + *
6.699 + * @throws IOException
6.700 + * If I/O errors occur
6.701 +
6.702 + * @since 1.2
6.703 + */
6.704 + public static Enumeration<URL> getSystemResources(String name)
6.705 + throws IOException
6.706 + {
6.707 + ClassLoader system = getSystemClassLoader();
6.708 + if (system == null) {
6.709 + return getBootstrapResources(name);
6.710 + }
6.711 + return system.getResources(name);
6.712 + }
6.713 +
6.714 +
6.715 +
6.716 + /**
6.717 + * Returns an input stream for reading the specified resource.
6.718 + *
6.719 + * <p> The search order is described in the documentation for {@link
6.720 + * #getResource(String)}. </p>
6.721 + *
6.722 + * @param name
6.723 + * The resource name
6.724 + *
6.725 + * @return An input stream for reading the resource, or <tt>null</tt>
6.726 + * if the resource could not be found
6.727 + *
6.728 + * @since 1.1
6.729 + */
6.730 + public InputStream getResourceAsStream(String name) {
6.731 + URL url = getResource(name);
6.732 + try {
6.733 + return url != null ? url.openStream() : null;
6.734 + } catch (IOException e) {
6.735 + return null;
6.736 + }
6.737 + }
6.738 +
6.739 + /**
6.740 + * Open for reading, a resource of the specified name from the search path
6.741 + * used to load classes. This method locates the resource through the
6.742 + * system class loader (see {@link #getSystemClassLoader()}). </p>
6.743 + *
6.744 + * @param name
6.745 + * The resource name
6.746 + *
6.747 + * @return An input stream for reading the resource, or <tt>null</tt>
6.748 + * if the resource could not be found
6.749 + *
6.750 + * @since 1.1
6.751 + */
6.752 + public static InputStream getSystemResourceAsStream(String name) {
6.753 + URL url = getSystemResource(name);
6.754 + try {
6.755 + return url != null ? url.openStream() : null;
6.756 + } catch (IOException e) {
6.757 + return null;
6.758 + }
6.759 + }
6.760 +
6.761 +
6.762 + // -- Hierarchy --
6.763 +
6.764 + /**
6.765 + * Returns the parent class loader for delegation. Some implementations may
6.766 + * use <tt>null</tt> to represent the bootstrap class loader. This method
6.767 + * will return <tt>null</tt> in such implementations if this class loader's
6.768 + * parent is the bootstrap class loader.
6.769 + *
6.770 + * <p> If a security manager is present, and the invoker's class loader is
6.771 + * not <tt>null</tt> and is not an ancestor of this class loader, then this
6.772 + * method invokes the security manager's {@link
6.773 + * SecurityManager#checkPermission(java.security.Permission)
6.774 + * <tt>checkPermission</tt>} method with a {@link
6.775 + * RuntimePermission#RuntimePermission(String)
6.776 + * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
6.777 + * access to the parent class loader is permitted. If not, a
6.778 + * <tt>SecurityException</tt> will be thrown. </p>
6.779 + *
6.780 + * @return The parent <tt>ClassLoader</tt>
6.781 + *
6.782 + * @throws SecurityException
6.783 + * If a security manager exists and its <tt>checkPermission</tt>
6.784 + * method doesn't allow access to this class loader's parent class
6.785 + * loader.
6.786 + *
6.787 + * @since 1.2
6.788 + */
6.789 + public final ClassLoader getParent() {
6.790 + throw new SecurityException();
6.791 + }
6.792 +
6.793 + /**
6.794 + * Returns the system class loader for delegation. This is the default
6.795 + * delegation parent for new <tt>ClassLoader</tt> instances, and is
6.796 + * typically the class loader used to start the application.
6.797 + *
6.798 + * <p> This method is first invoked early in the runtime's startup
6.799 + * sequence, at which point it creates the system class loader and sets it
6.800 + * as the context class loader of the invoking <tt>Thread</tt>.
6.801 + *
6.802 + * <p> The default system class loader is an implementation-dependent
6.803 + * instance of this class.
6.804 + *
6.805 + * <p> If the system property "<tt>java.system.class.loader</tt>" is defined
6.806 + * when this method is first invoked then the value of that property is
6.807 + * taken to be the name of a class that will be returned as the system
6.808 + * class loader. The class is loaded using the default system class loader
6.809 + * and must define a public constructor that takes a single parameter of
6.810 + * type <tt>ClassLoader</tt> which is used as the delegation parent. An
6.811 + * instance is then created using this constructor with the default system
6.812 + * class loader as the parameter. The resulting class loader is defined
6.813 + * to be the system class loader.
6.814 + *
6.815 + * <p> If a security manager is present, and the invoker's class loader is
6.816 + * not <tt>null</tt> and the invoker's class loader is not the same as or
6.817 + * an ancestor of the system class loader, then this method invokes the
6.818 + * security manager's {@link
6.819 + * SecurityManager#checkPermission(java.security.Permission)
6.820 + * <tt>checkPermission</tt>} method with a {@link
6.821 + * RuntimePermission#RuntimePermission(String)
6.822 + * <tt>RuntimePermission("getClassLoader")</tt>} permission to verify
6.823 + * access to the system class loader. If not, a
6.824 + * <tt>SecurityException</tt> will be thrown. </p>
6.825 + *
6.826 + * @return The system <tt>ClassLoader</tt> for delegation, or
6.827 + * <tt>null</tt> if none
6.828 + *
6.829 + * @throws SecurityException
6.830 + * If a security manager exists and its <tt>checkPermission</tt>
6.831 + * method doesn't allow access to the system class loader.
6.832 + *
6.833 + * @throws IllegalStateException
6.834 + * If invoked recursively during the construction of the class
6.835 + * loader specified by the "<tt>java.system.class.loader</tt>"
6.836 + * property.
6.837 + *
6.838 + * @throws Error
6.839 + * If the system property "<tt>java.system.class.loader</tt>"
6.840 + * is defined but the named class could not be loaded, the
6.841 + * provider class does not define the required constructor, or an
6.842 + * exception is thrown by that constructor when it is invoked. The
6.843 + * underlying cause of the error can be retrieved via the
6.844 + * {@link Throwable#getCause()} method.
6.845 + *
6.846 + * @revised 1.4
6.847 + */
6.848 + public static ClassLoader getSystemClassLoader() {
6.849 + throw new SecurityException();
6.850 + }
6.851 +
6.852 + // Returns true if the specified class loader can be found in this class
6.853 + // loader's delegation chain.
6.854 + boolean isAncestor(ClassLoader cl) {
6.855 + ClassLoader acl = this;
6.856 + do {
6.857 + acl = acl.parent;
6.858 + if (cl == acl) {
6.859 + return true;
6.860 + }
6.861 + } while (acl != null);
6.862 + return false;
6.863 + }
6.864 +
6.865 + private boolean checkName(String name) {
6.866 + throw new UnsupportedOperationException();
6.867 + }
6.868 +
6.869 + private Class findBootstrapClassOrNull(String name) {
6.870 + throw new UnsupportedOperationException();
6.871 + }
6.872 +
6.873 + private static URL getBootstrapResource(String name) {
6.874 + throw new UnsupportedOperationException();
6.875 + }
6.876 +
6.877 + private static Enumeration<URL> getBootstrapResources(String name) {
6.878 + throw new UnsupportedOperationException();
6.879 + }
6.880 +
6.881 + private static class CompoundEnumeration implements Enumeration<URL> {
6.882 + private URL next;
6.883 + private int index;
6.884 + private final Enumeration[] arr;
6.885 +
6.886 + public CompoundEnumeration(Enumeration[] arr) {
6.887 + this.arr = arr;
6.888 + this.index = 0;
6.889 + }
6.890 +
6.891 + public boolean hasMoreElements() {
6.892 + if (next == null) {
6.893 + if (arr[index].hasMoreElements()) {
6.894 + next = (URL) arr[index].nextElement();
6.895 + } else {
6.896 + if (index < arr.length) {
6.897 + index++;
6.898 + return hasMoreElements();
6.899 + }
6.900 + }
6.901 + }
6.902 + return next != null;
6.903 + }
6.904 +
6.905 + public URL nextElement() {
6.906 + if (!hasMoreElements()) {
6.907 + throw new NoSuchElementException();
6.908 + }
6.909 + URL r = next;
6.910 + next = null;
6.911 + return r;
6.912 + }
6.913 +
6.914 + }
6.915 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/emul/src/main/java/java/lang/LinkageError.java Tue Oct 30 09:24:41 2012 +0100
7.3 @@ -0,0 +1,69 @@
7.4 +/*
7.5 + * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.lang;
7.30 +
7.31 +/**
7.32 + * Subclasses of {@code LinkageError} indicate that a class has
7.33 + * some dependency on another class; however, the latter class has
7.34 + * incompatibly changed after the compilation of the former class.
7.35 + *
7.36 + *
7.37 + * @author Frank Yellin
7.38 + * @since JDK1.0
7.39 + */
7.40 +public
7.41 +class LinkageError extends Error {
7.42 + private static final long serialVersionUID = 3579600108157160122L;
7.43 +
7.44 + /**
7.45 + * Constructs a {@code LinkageError} with no detail message.
7.46 + */
7.47 + public LinkageError() {
7.48 + super();
7.49 + }
7.50 +
7.51 + /**
7.52 + * Constructs a {@code LinkageError} with the specified detail
7.53 + * message.
7.54 + *
7.55 + * @param s the detail message.
7.56 + */
7.57 + public LinkageError(String s) {
7.58 + super(s);
7.59 + }
7.60 +
7.61 + /**
7.62 + * Constructs a {@code LinkageError} with the specified detail
7.63 + * message and cause.
7.64 + *
7.65 + * @param s the detail message.
7.66 + * @param cause the cause, may be {@code null}
7.67 + * @since 1.7
7.68 + */
7.69 + public LinkageError(String s, Throwable cause) {
7.70 + super(s, cause);
7.71 + }
7.72 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/emul/src/main/java/java/lang/SecurityException.java Tue Oct 30 09:24:41 2012 +0100
8.3 @@ -0,0 +1,84 @@
8.4 +/*
8.5 + * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8.7 + *
8.8 + * This code is free software; you can redistribute it and/or modify it
8.9 + * under the terms of the GNU General Public License version 2 only, as
8.10 + * published by the Free Software Foundation. Oracle designates this
8.11 + * particular file as subject to the "Classpath" exception as provided
8.12 + * by Oracle in the LICENSE file that accompanied this code.
8.13 + *
8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8.17 + * version 2 for more details (a copy is included in the LICENSE file that
8.18 + * accompanied this code).
8.19 + *
8.20 + * You should have received a copy of the GNU General Public License version
8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8.23 + *
8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8.25 + * or visit www.oracle.com if you need additional information or have any
8.26 + * questions.
8.27 + */
8.28 +package java.lang;
8.29 +
8.30 +/**
8.31 + * Thrown by the security manager to indicate a security violation.
8.32 + *
8.33 + * @author unascribed
8.34 + * @see java.lang.SecurityManager
8.35 + * @since JDK1.0
8.36 + */
8.37 +public class SecurityException extends RuntimeException {
8.38 +
8.39 + private static final long serialVersionUID = 6878364983674394167L;
8.40 +
8.41 + /**
8.42 + * Constructs a <code>SecurityException</code> with no detail message.
8.43 + */
8.44 + public SecurityException() {
8.45 + super();
8.46 + }
8.47 +
8.48 + /**
8.49 + * Constructs a <code>SecurityException</code> with the specified
8.50 + * detail message.
8.51 + *
8.52 + * @param s the detail message.
8.53 + */
8.54 + public SecurityException(String s) {
8.55 + super(s);
8.56 + }
8.57 +
8.58 + /**
8.59 + * Creates a <code>SecurityException</code> with the specified
8.60 + * detail message and cause.
8.61 + *
8.62 + * @param message the detail message (which is saved for later retrieval
8.63 + * by the {@link #getMessage()} method).
8.64 + * @param cause the cause (which is saved for later retrieval by the
8.65 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
8.66 + * and indicates that the cause is nonexistent or unknown.)
8.67 + * @since 1.5
8.68 + */
8.69 + public SecurityException(String message, Throwable cause) {
8.70 + super(message, cause);
8.71 + }
8.72 +
8.73 + /**
8.74 + * Creates a <code>SecurityException</code> with the specified cause
8.75 + * and a detail message of <tt>(cause==null ? null : cause.toString())</tt>
8.76 + * (which typically contains the class and detail message of
8.77 + * <tt>cause</tt>).
8.78 + *
8.79 + * @param cause the cause (which is saved for later retrieval by the
8.80 + * {@link #getCause()} method). (A <tt>null</tt> value is permitted,
8.81 + * and indicates that the cause is nonexistent or unknown.)
8.82 + * @since 1.5
8.83 + */
8.84 + public SecurityException(Throwable cause) {
8.85 + super(cause);
8.86 + }
8.87 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/emul/src/main/java/java/net/MalformedURLException.java Tue Oct 30 09:24:41 2012 +0100
9.3 @@ -0,0 +1,56 @@
9.4 +/*
9.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9.7 + *
9.8 + * This code is free software; you can redistribute it and/or modify it
9.9 + * under the terms of the GNU General Public License version 2 only, as
9.10 + * published by the Free Software Foundation. Oracle designates this
9.11 + * particular file as subject to the "Classpath" exception as provided
9.12 + * by Oracle in the LICENSE file that accompanied this code.
9.13 + *
9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9.17 + * version 2 for more details (a copy is included in the LICENSE file that
9.18 + * accompanied this code).
9.19 + *
9.20 + * You should have received a copy of the GNU General Public License version
9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9.23 + *
9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9.25 + * or visit www.oracle.com if you need additional information or have any
9.26 + * questions.
9.27 + */
9.28 +
9.29 +package java.net;
9.30 +
9.31 +import java.io.IOException;
9.32 +
9.33 +/**
9.34 + * Thrown to indicate that a malformed URL has occurred. Either no
9.35 + * legal protocol could be found in a specification string or the
9.36 + * string could not be parsed.
9.37 + *
9.38 + * @author Arthur van Hoff
9.39 + * @since JDK1.0
9.40 + */
9.41 +public class MalformedURLException extends IOException {
9.42 + private static final long serialVersionUID = -182787522200415866L;
9.43 +
9.44 + /**
9.45 + * Constructs a <code>MalformedURLException</code> with no detail message.
9.46 + */
9.47 + public MalformedURLException() {
9.48 + }
9.49 +
9.50 + /**
9.51 + * Constructs a <code>MalformedURLException</code> with the
9.52 + * specified detail message.
9.53 + *
9.54 + * @param msg the detail message.
9.55 + */
9.56 + public MalformedURLException(String msg) {
9.57 + super(msg);
9.58 + }
9.59 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/emul/src/main/java/java/net/URL.java Tue Oct 30 09:24:41 2012 +0100
10.3 @@ -0,0 +1,958 @@
10.4 +/*
10.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 + *
10.8 + * This code is free software; you can redistribute it and/or modify it
10.9 + * under the terms of the GNU General Public License version 2 only, as
10.10 + * published by the Free Software Foundation. Oracle designates this
10.11 + * particular file as subject to the "Classpath" exception as provided
10.12 + * by Oracle in the LICENSE file that accompanied this code.
10.13 + *
10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 + * version 2 for more details (a copy is included in the LICENSE file that
10.18 + * accompanied this code).
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License version
10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 + *
10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10.25 + * or visit www.oracle.com if you need additional information or have any
10.26 + * questions.
10.27 + */
10.28 +
10.29 +package java.net;
10.30 +
10.31 +import java.io.IOException;
10.32 +import java.io.InputStream;
10.33 +
10.34 +/**
10.35 + * Class <code>URL</code> represents a Uniform Resource
10.36 + * Locator, a pointer to a "resource" on the World
10.37 + * Wide Web. A resource can be something as simple as a file or a
10.38 + * directory, or it can be a reference to a more complicated object,
10.39 + * such as a query to a database or to a search engine. More
10.40 + * information on the types of URLs and their formats can be found at:
10.41 + * <blockquote>
10.42 + * <a href="http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html">
10.43 + * <i>http://www.socs.uts.edu.au/MosaicDocs-old/url-primer.html</i></a>
10.44 + * </blockquote>
10.45 + * <p>
10.46 + * In general, a URL can be broken into several parts. The previous
10.47 + * example of a URL indicates that the protocol to use is
10.48 + * <code>http</code> (HyperText Transfer Protocol) and that the
10.49 + * information resides on a host machine named
10.50 + * <code>www.socs.uts.edu.au</code>. The information on that host
10.51 + * machine is named <code>/MosaicDocs-old/url-primer.html</code>. The exact
10.52 + * meaning of this name on the host machine is both protocol
10.53 + * dependent and host dependent. The information normally resides in
10.54 + * a file, but it could be generated on the fly. This component of
10.55 + * the URL is called the <i>path</i> component.
10.56 + * <p>
10.57 + * A URL can optionally specify a "port", which is the
10.58 + * port number to which the TCP connection is made on the remote host
10.59 + * machine. If the port is not specified, the default port for
10.60 + * the protocol is used instead. For example, the default port for
10.61 + * <code>http</code> is <code>80</code>. An alternative port could be
10.62 + * specified as:
10.63 + * <blockquote><pre>
10.64 + * http://www.socs.uts.edu.au:80/MosaicDocs-old/url-primer.html
10.65 + * </pre></blockquote>
10.66 + * <p>
10.67 + * The syntax of <code>URL</code> is defined by <a
10.68 + * href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC 2396: Uniform
10.69 + * Resource Identifiers (URI): Generic Syntax</i></a>, amended by <a
10.70 + * href="http://www.ietf.org/rfc/rfc2732.txt"><i>RFC 2732: Format for
10.71 + * Literal IPv6 Addresses in URLs</i></a>. The Literal IPv6 address format
10.72 + * also supports scope_ids. The syntax and usage of scope_ids is described
10.73 + * <a href="Inet6Address.html#scoped">here</a>.
10.74 + * <p>
10.75 + * A URL may have appended to it a "fragment", also known
10.76 + * as a "ref" or a "reference". The fragment is indicated by the sharp
10.77 + * sign character "#" followed by more characters. For example,
10.78 + * <blockquote><pre>
10.79 + * http://java.sun.com/index.html#chapter1
10.80 + * </pre></blockquote>
10.81 + * <p>
10.82 + * This fragment is not technically part of the URL. Rather, it
10.83 + * indicates that after the specified resource is retrieved, the
10.84 + * application is specifically interested in that part of the
10.85 + * document that has the tag <code>chapter1</code> attached to it. The
10.86 + * meaning of a tag is resource specific.
10.87 + * <p>
10.88 + * An application can also specify a "relative URL",
10.89 + * which contains only enough information to reach the resource
10.90 + * relative to another URL. Relative URLs are frequently used within
10.91 + * HTML pages. For example, if the contents of the URL:
10.92 + * <blockquote><pre>
10.93 + * http://java.sun.com/index.html
10.94 + * </pre></blockquote>
10.95 + * contained within it the relative URL:
10.96 + * <blockquote><pre>
10.97 + * FAQ.html
10.98 + * </pre></blockquote>
10.99 + * it would be a shorthand for:
10.100 + * <blockquote><pre>
10.101 + * http://java.sun.com/FAQ.html
10.102 + * </pre></blockquote>
10.103 + * <p>
10.104 + * The relative URL need not specify all the components of a URL. If
10.105 + * the protocol, host name, or port number is missing, the value is
10.106 + * inherited from the fully specified URL. The file component must be
10.107 + * specified. The optional fragment is not inherited.
10.108 + * <p>
10.109 + * The URL class does not itself encode or decode any URL components
10.110 + * according to the escaping mechanism defined in RFC2396. It is the
10.111 + * responsibility of the caller to encode any fields, which need to be
10.112 + * escaped prior to calling URL, and also to decode any escaped fields,
10.113 + * that are returned from URL. Furthermore, because URL has no knowledge
10.114 + * of URL escaping, it does not recognise equivalence between the encoded
10.115 + * or decoded form of the same URL. For example, the two URLs:<br>
10.116 + * <pre> http://foo.com/hello world/ and http://foo.com/hello%20world</pre>
10.117 + * would be considered not equal to each other.
10.118 + * <p>
10.119 + * Note, the {@link java.net.URI} class does perform escaping of its
10.120 + * component fields in certain circumstances. The recommended way
10.121 + * to manage the encoding and decoding of URLs is to use {@link java.net.URI},
10.122 + * and to convert between these two classes using {@link #toURI()} and
10.123 + * {@link URI#toURL()}.
10.124 + * <p>
10.125 + * The {@link URLEncoder} and {@link URLDecoder} classes can also be
10.126 + * used, but only for HTML form encoding, which is not the same
10.127 + * as the encoding scheme defined in RFC2396.
10.128 + *
10.129 + * @author James Gosling
10.130 + * @since JDK1.0
10.131 + */
10.132 +public final class URL implements java.io.Serializable {
10.133 +
10.134 + static final long serialVersionUID = -7627629688361524110L;
10.135 +
10.136 + /**
10.137 + * The property which specifies the package prefix list to be scanned
10.138 + * for protocol handlers. The value of this property (if any) should
10.139 + * be a vertical bar delimited list of package names to search through
10.140 + * for a protocol handler to load. The policy of this class is that
10.141 + * all protocol handlers will be in a class called <protocolname>.Handler,
10.142 + * and each package in the list is examined in turn for a matching
10.143 + * handler. If none are found (or the property is not specified), the
10.144 + * default package prefix, sun.net.www.protocol, is used. The search
10.145 + * proceeds from the first package in the list to the last and stops
10.146 + * when a match is found.
10.147 + */
10.148 + private static final String protocolPathProp = "java.protocol.handler.pkgs";
10.149 +
10.150 + /**
10.151 + * The protocol to use (ftp, http, nntp, ... etc.) .
10.152 + * @serial
10.153 + */
10.154 + private String protocol;
10.155 +
10.156 + /**
10.157 + * The host name to connect to.
10.158 + * @serial
10.159 + */
10.160 + private String host;
10.161 +
10.162 + /**
10.163 + * The protocol port to connect to.
10.164 + * @serial
10.165 + */
10.166 + private int port = -1;
10.167 +
10.168 + /**
10.169 + * The specified file name on that host. <code>file</code> is
10.170 + * defined as <code>path[?query]</code>
10.171 + * @serial
10.172 + */
10.173 + private String file;
10.174 +
10.175 + /**
10.176 + * The query part of this URL.
10.177 + */
10.178 + private transient String query;
10.179 +
10.180 + /**
10.181 + * The authority part of this URL.
10.182 + * @serial
10.183 + */
10.184 + private String authority;
10.185 +
10.186 + /**
10.187 + * The path part of this URL.
10.188 + */
10.189 + private transient String path;
10.190 +
10.191 + /**
10.192 + * The userinfo part of this URL.
10.193 + */
10.194 + private transient String userInfo;
10.195 +
10.196 + /**
10.197 + * # reference.
10.198 + * @serial
10.199 + */
10.200 + private String ref;
10.201 +
10.202 + /* Our hash code.
10.203 + * @serial
10.204 + */
10.205 + private int hashCode = -1;
10.206 +
10.207 + /**
10.208 + * Creates a <code>URL</code> object from the specified
10.209 + * <code>protocol</code>, <code>host</code>, <code>port</code>
10.210 + * number, and <code>file</code>.<p>
10.211 + *
10.212 + * <code>host</code> can be expressed as a host name or a literal
10.213 + * IP address. If IPv6 literal address is used, it should be
10.214 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>), as
10.215 + * specified by <a
10.216 + * href="http://www.ietf.org/rfc/rfc2732.txt">RFC 2732</a>;
10.217 + * However, the literal IPv6 address format defined in <a
10.218 + * href="http://www.ietf.org/rfc/rfc2373.txt"><i>RFC 2373: IP
10.219 + * Version 6 Addressing Architecture</i></a> is also accepted.<p>
10.220 + *
10.221 + * Specifying a <code>port</code> number of <code>-1</code>
10.222 + * indicates that the URL should use the default port for the
10.223 + * protocol.<p>
10.224 + *
10.225 + * If this is the first URL object being created with the specified
10.226 + * protocol, a <i>stream protocol handler</i> object, an instance of
10.227 + * class <code>URLStreamHandler</code>, is created for that protocol:
10.228 + * <ol>
10.229 + * <li>If the application has previously set up an instance of
10.230 + * <code>URLStreamHandlerFactory</code> as the stream handler factory,
10.231 + * then the <code>createURLStreamHandler</code> method of that instance
10.232 + * is called with the protocol string as an argument to create the
10.233 + * stream protocol handler.
10.234 + * <li>If no <code>URLStreamHandlerFactory</code> has yet been set up,
10.235 + * or if the factory's <code>createURLStreamHandler</code> method
10.236 + * returns <code>null</code>, then the constructor finds the
10.237 + * value of the system property:
10.238 + * <blockquote><pre>
10.239 + * java.protocol.handler.pkgs
10.240 + * </pre></blockquote>
10.241 + * If the value of that system property is not <code>null</code>,
10.242 + * it is interpreted as a list of packages separated by a vertical
10.243 + * slash character '<code>|</code>'. The constructor tries to load
10.244 + * the class named:
10.245 + * <blockquote><pre>
10.246 + * <<i>package</i>>.<<i>protocol</i>>.Handler
10.247 + * </pre></blockquote>
10.248 + * where <<i>package</i>> is replaced by the name of the package
10.249 + * and <<i>protocol</i>> is replaced by the name of the protocol.
10.250 + * If this class does not exist, or if the class exists but it is not
10.251 + * a subclass of <code>URLStreamHandler</code>, then the next package
10.252 + * in the list is tried.
10.253 + * <li>If the previous step fails to find a protocol handler, then the
10.254 + * constructor tries to load from a system default package.
10.255 + * <blockquote><pre>
10.256 + * <<i>system default package</i>>.<<i>protocol</i>>.Handler
10.257 + * </pre></blockquote>
10.258 + * If this class does not exist, or if the class exists but it is not a
10.259 + * subclass of <code>URLStreamHandler</code>, then a
10.260 + * <code>MalformedURLException</code> is thrown.
10.261 + * </ol>
10.262 + *
10.263 + * <p>Protocol handlers for the following protocols are guaranteed
10.264 + * to exist on the search path :-
10.265 + * <blockquote><pre>
10.266 + * http, https, ftp, file, and jar
10.267 + * </pre></blockquote>
10.268 + * Protocol handlers for additional protocols may also be
10.269 + * available.
10.270 + *
10.271 + * <p>No validation of the inputs is performed by this constructor.
10.272 + *
10.273 + * @param protocol the name of the protocol to use.
10.274 + * @param host the name of the host.
10.275 + * @param port the port number on the host.
10.276 + * @param file the file on the host
10.277 + * @exception MalformedURLException if an unknown protocol is specified.
10.278 + * @see java.lang.System#getProperty(java.lang.String)
10.279 + * @see java.net.URL#setURLStreamHandlerFactory(
10.280 + * java.net.URLStreamHandlerFactory)
10.281 + * @see java.net.URLStreamHandler
10.282 + * @see java.net.URLStreamHandlerFactory#createURLStreamHandler(
10.283 + * java.lang.String)
10.284 + */
10.285 + public URL(String protocol, String host, int port, String file)
10.286 + throws MalformedURLException
10.287 + {
10.288 + this(protocol, host, port, file, null);
10.289 + }
10.290 +
10.291 + /**
10.292 + * Creates a URL from the specified <code>protocol</code>
10.293 + * name, <code>host</code> name, and <code>file</code> name. The
10.294 + * default port for the specified protocol is used.
10.295 + * <p>
10.296 + * This method is equivalent to calling the four-argument
10.297 + * constructor with the arguments being <code>protocol</code>,
10.298 + * <code>host</code>, <code>-1</code>, and <code>file</code>.
10.299 + *
10.300 + * No validation of the inputs is performed by this constructor.
10.301 + *
10.302 + * @param protocol the name of the protocol to use.
10.303 + * @param host the name of the host.
10.304 + * @param file the file on the host.
10.305 + * @exception MalformedURLException if an unknown protocol is specified.
10.306 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
10.307 + * int, java.lang.String)
10.308 + */
10.309 + public URL(String protocol, String host, String file)
10.310 + throws MalformedURLException {
10.311 + this(protocol, host, -1, file);
10.312 + }
10.313 +
10.314 + private URL(String protocol, String host, int port, String file,
10.315 + Object handler) throws MalformedURLException {
10.316 + if (handler != null) {
10.317 + throw new SecurityException();
10.318 + }
10.319 +
10.320 + protocol = protocol.toLowerCase();
10.321 + this.protocol = protocol;
10.322 + if (host != null) {
10.323 +
10.324 + /**
10.325 + * if host is a literal IPv6 address,
10.326 + * we will make it conform to RFC 2732
10.327 + */
10.328 + if (host.indexOf(':') >= 0 && !host.startsWith("[")) {
10.329 + host = "["+host+"]";
10.330 + }
10.331 + this.host = host;
10.332 +
10.333 + if (port < -1) {
10.334 + throw new MalformedURLException("Invalid port number :" +
10.335 + port);
10.336 + }
10.337 + this.port = port;
10.338 + authority = (port == -1) ? host : host + ":" + port;
10.339 + }
10.340 +
10.341 + Parts parts = new Parts(file);
10.342 + path = parts.getPath();
10.343 + query = parts.getQuery();
10.344 +
10.345 + if (query != null) {
10.346 + this.file = path + "?" + query;
10.347 + } else {
10.348 + this.file = path;
10.349 + }
10.350 + ref = parts.getRef();
10.351 +
10.352 + // Note: we don't do validation of the URL here. Too risky to change
10.353 + // right now, but worth considering for future reference. -br
10.354 +// if (handler == null &&
10.355 +// (handler = getURLStreamHandler(protocol)) == null) {
10.356 +// throw new MalformedURLException("unknown protocol: " + protocol);
10.357 +// }
10.358 + }
10.359 +
10.360 + /**
10.361 + * Creates a <code>URL</code> object from the <code>String</code>
10.362 + * representation.
10.363 + * <p>
10.364 + * This constructor is equivalent to a call to the two-argument
10.365 + * constructor with a <code>null</code> first argument.
10.366 + *
10.367 + * @param spec the <code>String</code> to parse as a URL.
10.368 + * @exception MalformedURLException if no protocol is specified, or an
10.369 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
10.370 + * @see java.net.URL#URL(java.net.URL, java.lang.String)
10.371 + */
10.372 + public URL(String spec) throws MalformedURLException {
10.373 + this(null, spec);
10.374 + }
10.375 +
10.376 + /**
10.377 + * Creates a URL by parsing the given spec within a specified context.
10.378 + *
10.379 + * The new URL is created from the given context URL and the spec
10.380 + * argument as described in
10.381 + * RFC2396 "Uniform Resource Identifiers : Generic * Syntax" :
10.382 + * <blockquote><pre>
10.383 + * <scheme>://<authority><path>?<query>#<fragment>
10.384 + * </pre></blockquote>
10.385 + * The reference is parsed into the scheme, authority, path, query and
10.386 + * fragment parts. If the path component is empty and the scheme,
10.387 + * authority, and query components are undefined, then the new URL is a
10.388 + * reference to the current document. Otherwise, the fragment and query
10.389 + * parts present in the spec are used in the new URL.
10.390 + * <p>
10.391 + * If the scheme component is defined in the given spec and does not match
10.392 + * the scheme of the context, then the new URL is created as an absolute
10.393 + * URL based on the spec alone. Otherwise the scheme component is inherited
10.394 + * from the context URL.
10.395 + * <p>
10.396 + * If the authority component is present in the spec then the spec is
10.397 + * treated as absolute and the spec authority and path will replace the
10.398 + * context authority and path. If the authority component is absent in the
10.399 + * spec then the authority of the new URL will be inherited from the
10.400 + * context.
10.401 + * <p>
10.402 + * If the spec's path component begins with a slash character
10.403 + * "/" then the
10.404 + * path is treated as absolute and the spec path replaces the context path.
10.405 + * <p>
10.406 + * Otherwise, the path is treated as a relative path and is appended to the
10.407 + * context path, as described in RFC2396. Also, in this case,
10.408 + * the path is canonicalized through the removal of directory
10.409 + * changes made by occurences of ".." and ".".
10.410 + * <p>
10.411 + * For a more detailed description of URL parsing, refer to RFC2396.
10.412 + *
10.413 + * @param context the context in which to parse the specification.
10.414 + * @param spec the <code>String</code> to parse as a URL.
10.415 + * @exception MalformedURLException if no protocol is specified, or an
10.416 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
10.417 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
10.418 + * int, java.lang.String)
10.419 + * @see java.net.URLStreamHandler
10.420 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
10.421 + * java.lang.String, int, int)
10.422 + */
10.423 + public URL(URL context, String spec) throws MalformedURLException {
10.424 + this(context, spec, null);
10.425 + }
10.426 +
10.427 + /**
10.428 + * Creates a URL by parsing the given spec with the specified handler
10.429 + * within a specified context. If the handler is null, the parsing
10.430 + * occurs as with the two argument constructor.
10.431 + *
10.432 + * @param context the context in which to parse the specification.
10.433 + * @param spec the <code>String</code> to parse as a URL.
10.434 + * @param handler the stream handler for the URL.
10.435 + * @exception MalformedURLException if no protocol is specified, or an
10.436 + * unknown protocol is found, or <tt>spec</tt> is <tt>null</tt>.
10.437 + * @exception SecurityException
10.438 + * if a security manager exists and its
10.439 + * <code>checkPermission</code> method doesn't allow
10.440 + * specifying a stream handler.
10.441 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
10.442 + * int, java.lang.String)
10.443 + * @see java.net.URLStreamHandler
10.444 + * @see java.net.URLStreamHandler#parseURL(java.net.URL,
10.445 + * java.lang.String, int, int)
10.446 + */
10.447 + private URL(URL context, String spec, Object handler)
10.448 + throws MalformedURLException
10.449 + {
10.450 + String original = spec;
10.451 + int i, limit, c;
10.452 + int start = 0;
10.453 + String newProtocol = null;
10.454 + boolean aRef=false;
10.455 + boolean isRelative = false;
10.456 +
10.457 + // Check for permission to specify a handler
10.458 + if (handler != null) {
10.459 + throw new SecurityException();
10.460 + }
10.461 +
10.462 + try {
10.463 + limit = spec.length();
10.464 + while ((limit > 0) && (spec.charAt(limit - 1) <= ' ')) {
10.465 + limit--; //eliminate trailing whitespace
10.466 + }
10.467 + while ((start < limit) && (spec.charAt(start) <= ' ')) {
10.468 + start++; // eliminate leading whitespace
10.469 + }
10.470 +
10.471 + if (spec.regionMatches(true, start, "url:", 0, 4)) {
10.472 + start += 4;
10.473 + }
10.474 + if (start < spec.length() && spec.charAt(start) == '#') {
10.475 + /* we're assuming this is a ref relative to the context URL.
10.476 + * This means protocols cannot start w/ '#', but we must parse
10.477 + * ref URL's like: "hello:there" w/ a ':' in them.
10.478 + */
10.479 + aRef=true;
10.480 + }
10.481 + for (i = start ; !aRef && (i < limit) &&
10.482 + ((c = spec.charAt(i)) != '/') ; i++) {
10.483 + if (c == ':') {
10.484 +
10.485 + String s = spec.substring(start, i).toLowerCase();
10.486 + if (isValidProtocol(s)) {
10.487 + newProtocol = s;
10.488 + start = i + 1;
10.489 + }
10.490 + break;
10.491 + }
10.492 + }
10.493 +
10.494 + // Only use our context if the protocols match.
10.495 + protocol = newProtocol;
10.496 + if ((context != null) && ((newProtocol == null) ||
10.497 + newProtocol.equalsIgnoreCase(context.protocol))) {
10.498 + // inherit the protocol handler from the context
10.499 + // if not specified to the constructor
10.500 +// if (handler == null) {
10.501 +// handler = context.handler;
10.502 +// }
10.503 +
10.504 + // If the context is a hierarchical URL scheme and the spec
10.505 + // contains a matching scheme then maintain backwards
10.506 + // compatibility and treat it as if the spec didn't contain
10.507 + // the scheme; see 5.2.3 of RFC2396
10.508 + if (context.path != null && context.path.startsWith("/"))
10.509 + newProtocol = null;
10.510 +
10.511 + if (newProtocol == null) {
10.512 + protocol = context.protocol;
10.513 + authority = context.authority;
10.514 + userInfo = context.userInfo;
10.515 + host = context.host;
10.516 + port = context.port;
10.517 + file = context.file;
10.518 + path = context.path;
10.519 + isRelative = true;
10.520 + }
10.521 + }
10.522 +
10.523 + if (protocol == null) {
10.524 + throw new MalformedURLException("no protocol: "+original);
10.525 + }
10.526 +
10.527 + // Get the protocol handler if not specified or the protocol
10.528 + // of the context could not be used
10.529 +// if (handler == null &&
10.530 +// (handler = getURLStreamHandler(protocol)) == null) {
10.531 +// throw new MalformedURLException("unknown protocol: "+protocol);
10.532 +// }
10.533 +
10.534 +// this.handler = handler;
10.535 +
10.536 + i = spec.indexOf('#', start);
10.537 + if (i >= 0) {
10.538 + ref = spec.substring(i + 1, limit);
10.539 + limit = i;
10.540 + }
10.541 +
10.542 + /*
10.543 + * Handle special case inheritance of query and fragment
10.544 + * implied by RFC2396 section 5.2.2.
10.545 + */
10.546 + if (isRelative && start == limit) {
10.547 + query = context.query;
10.548 + if (ref == null) {
10.549 + ref = context.ref;
10.550 + }
10.551 + }
10.552 +
10.553 +// handler.parseURL(this, spec, start, limit);
10.554 +
10.555 + } catch(MalformedURLException e) {
10.556 + throw e;
10.557 + } catch(Exception e) {
10.558 + MalformedURLException exception = new MalformedURLException(e.getMessage());
10.559 + exception.initCause(e);
10.560 + throw exception;
10.561 + }
10.562 + }
10.563 +
10.564 + /*
10.565 + * Returns true if specified string is a valid protocol name.
10.566 + */
10.567 + private boolean isValidProtocol(String protocol) {
10.568 + int len = protocol.length();
10.569 + if (len < 1)
10.570 + return false;
10.571 + char c = protocol.charAt(0);
10.572 + if (!Character.isLetter(c))
10.573 + return false;
10.574 + for (int i = 1; i < len; i++) {
10.575 + c = protocol.charAt(i);
10.576 + if (!Character.isLetterOrDigit(c) && c != '.' && c != '+' &&
10.577 + c != '-') {
10.578 + return false;
10.579 + }
10.580 + }
10.581 + return true;
10.582 + }
10.583 +
10.584 + /**
10.585 + * Sets the fields of the URL. This is not a public method so that
10.586 + * only URLStreamHandlers can modify URL fields. URLs are
10.587 + * otherwise constant.
10.588 + *
10.589 + * @param protocol the name of the protocol to use
10.590 + * @param host the name of the host
10.591 + @param port the port number on the host
10.592 + * @param file the file on the host
10.593 + * @param ref the internal reference in the URL
10.594 + */
10.595 + protected void set(String protocol, String host,
10.596 + int port, String file, String ref) {
10.597 + synchronized (this) {
10.598 + this.protocol = protocol;
10.599 + this.host = host;
10.600 + authority = port == -1 ? host : host + ":" + port;
10.601 + this.port = port;
10.602 + this.file = file;
10.603 + this.ref = ref;
10.604 + /* This is very important. We must recompute this after the
10.605 + * URL has been changed. */
10.606 + hashCode = -1;
10.607 + int q = file.lastIndexOf('?');
10.608 + if (q != -1) {
10.609 + query = file.substring(q+1);
10.610 + path = file.substring(0, q);
10.611 + } else
10.612 + path = file;
10.613 + }
10.614 + }
10.615 +
10.616 + /**
10.617 + * Sets the specified 8 fields of the URL. This is not a public method so
10.618 + * that only URLStreamHandlers can modify URL fields. URLs are otherwise
10.619 + * constant.
10.620 + *
10.621 + * @param protocol the name of the protocol to use
10.622 + * @param host the name of the host
10.623 + * @param port the port number on the host
10.624 + * @param authority the authority part for the url
10.625 + * @param userInfo the username and password
10.626 + * @param path the file on the host
10.627 + * @param ref the internal reference in the URL
10.628 + * @param query the query part of this URL
10.629 + * @since 1.3
10.630 + */
10.631 + protected void set(String protocol, String host, int port,
10.632 + String authority, String userInfo, String path,
10.633 + String query, String ref) {
10.634 + synchronized (this) {
10.635 + this.protocol = protocol;
10.636 + this.host = host;
10.637 + this.port = port;
10.638 + this.file = query == null ? path : path + "?" + query;
10.639 + this.userInfo = userInfo;
10.640 + this.path = path;
10.641 + this.ref = ref;
10.642 + /* This is very important. We must recompute this after the
10.643 + * URL has been changed. */
10.644 + hashCode = -1;
10.645 + this.query = query;
10.646 + this.authority = authority;
10.647 + }
10.648 + }
10.649 +
10.650 + /**
10.651 + * Gets the query part of this <code>URL</code>.
10.652 + *
10.653 + * @return the query part of this <code>URL</code>,
10.654 + * or <CODE>null</CODE> if one does not exist
10.655 + * @since 1.3
10.656 + */
10.657 + public String getQuery() {
10.658 + return query;
10.659 + }
10.660 +
10.661 + /**
10.662 + * Gets the path part of this <code>URL</code>.
10.663 + *
10.664 + * @return the path part of this <code>URL</code>, or an
10.665 + * empty string if one does not exist
10.666 + * @since 1.3
10.667 + */
10.668 + public String getPath() {
10.669 + return path;
10.670 + }
10.671 +
10.672 + /**
10.673 + * Gets the userInfo part of this <code>URL</code>.
10.674 + *
10.675 + * @return the userInfo part of this <code>URL</code>, or
10.676 + * <CODE>null</CODE> if one does not exist
10.677 + * @since 1.3
10.678 + */
10.679 + public String getUserInfo() {
10.680 + return userInfo;
10.681 + }
10.682 +
10.683 + /**
10.684 + * Gets the authority part of this <code>URL</code>.
10.685 + *
10.686 + * @return the authority part of this <code>URL</code>
10.687 + * @since 1.3
10.688 + */
10.689 + public String getAuthority() {
10.690 + return authority;
10.691 + }
10.692 +
10.693 + /**
10.694 + * Gets the port number of this <code>URL</code>.
10.695 + *
10.696 + * @return the port number, or -1 if the port is not set
10.697 + */
10.698 + public int getPort() {
10.699 + return port;
10.700 + }
10.701 +
10.702 + /**
10.703 + * Gets the protocol name of this <code>URL</code>.
10.704 + *
10.705 + * @return the protocol of this <code>URL</code>.
10.706 + */
10.707 + public String getProtocol() {
10.708 + return protocol;
10.709 + }
10.710 +
10.711 + /**
10.712 + * Gets the host name of this <code>URL</code>, if applicable.
10.713 + * The format of the host conforms to RFC 2732, i.e. for a
10.714 + * literal IPv6 address, this method will return the IPv6 address
10.715 + * enclosed in square brackets (<tt>'['</tt> and <tt>']'</tt>).
10.716 + *
10.717 + * @return the host name of this <code>URL</code>.
10.718 + */
10.719 + public String getHost() {
10.720 + return host;
10.721 + }
10.722 +
10.723 + /**
10.724 + * Gets the file name of this <code>URL</code>.
10.725 + * The returned file portion will be
10.726 + * the same as <CODE>getPath()</CODE>, plus the concatenation of
10.727 + * the value of <CODE>getQuery()</CODE>, if any. If there is
10.728 + * no query portion, this method and <CODE>getPath()</CODE> will
10.729 + * return identical results.
10.730 + *
10.731 + * @return the file name of this <code>URL</code>,
10.732 + * or an empty string if one does not exist
10.733 + */
10.734 + public String getFile() {
10.735 + return file;
10.736 + }
10.737 +
10.738 + /**
10.739 + * Gets the anchor (also known as the "reference") of this
10.740 + * <code>URL</code>.
10.741 + *
10.742 + * @return the anchor (also known as the "reference") of this
10.743 + * <code>URL</code>, or <CODE>null</CODE> if one does not exist
10.744 + */
10.745 + public String getRef() {
10.746 + return ref;
10.747 + }
10.748 +
10.749 + /**
10.750 + * Compares this URL for equality with another object.<p>
10.751 + *
10.752 + * If the given object is not a URL then this method immediately returns
10.753 + * <code>false</code>.<p>
10.754 + *
10.755 + * Two URL objects are equal if they have the same protocol, reference
10.756 + * equivalent hosts, have the same port number on the host, and the same
10.757 + * file and fragment of the file.<p>
10.758 + *
10.759 + * Two hosts are considered equivalent if both host names can be resolved
10.760 + * into the same IP addresses; else if either host name can't be
10.761 + * resolved, the host names must be equal without regard to case; or both
10.762 + * host names equal to null.<p>
10.763 + *
10.764 + * Since hosts comparison requires name resolution, this operation is a
10.765 + * blocking operation. <p>
10.766 + *
10.767 + * Note: The defined behavior for <code>equals</code> is known to
10.768 + * be inconsistent with virtual hosting in HTTP.
10.769 + *
10.770 + * @param obj the URL to compare against.
10.771 + * @return <code>true</code> if the objects are the same;
10.772 + * <code>false</code> otherwise.
10.773 + */
10.774 + public boolean equals(Object obj) {
10.775 + if (!(obj instanceof URL))
10.776 + return false;
10.777 + URL u2 = (URL)obj;
10.778 +
10.779 + // return handler.equals(this, u2);
10.780 + return u2 == this;
10.781 + }
10.782 +
10.783 + /**
10.784 + * Creates an integer suitable for hash table indexing.<p>
10.785 + *
10.786 + * The hash code is based upon all the URL components relevant for URL
10.787 + * comparison. As such, this operation is a blocking operation.<p>
10.788 + *
10.789 + * @return a hash code for this <code>URL</code>.
10.790 + */
10.791 + public synchronized int hashCode() {
10.792 + if (hashCode != -1)
10.793 + return hashCode;
10.794 +
10.795 + // hashCode = handler.hashCode(this);
10.796 + return hashCode;
10.797 + }
10.798 +
10.799 + /**
10.800 + * Compares two URLs, excluding the fragment component.<p>
10.801 + *
10.802 + * Returns <code>true</code> if this <code>URL</code> and the
10.803 + * <code>other</code> argument are equal without taking the
10.804 + * fragment component into consideration.
10.805 + *
10.806 + * @param other the <code>URL</code> to compare against.
10.807 + * @return <code>true</code> if they reference the same remote object;
10.808 + * <code>false</code> otherwise.
10.809 + */
10.810 + public boolean sameFile(URL other) {
10.811 +// return handler.sameFile(this, other);
10.812 + throw new UnsupportedOperationException();
10.813 + }
10.814 +
10.815 + /**
10.816 + * Constructs a string representation of this <code>URL</code>. The
10.817 + * string is created by calling the <code>toExternalForm</code>
10.818 + * method of the stream protocol handler for this object.
10.819 + *
10.820 + * @return a string representation of this object.
10.821 + * @see java.net.URL#URL(java.lang.String, java.lang.String, int,
10.822 + * java.lang.String)
10.823 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
10.824 + */
10.825 + public String toString() {
10.826 + return toExternalForm();
10.827 + }
10.828 +
10.829 + /**
10.830 + * Constructs a string representation of this <code>URL</code>. The
10.831 + * string is created by calling the <code>toExternalForm</code>
10.832 + * method of the stream protocol handler for this object.
10.833 + *
10.834 + * @return a string representation of this object.
10.835 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
10.836 + * int, java.lang.String)
10.837 + * @see java.net.URLStreamHandler#toExternalForm(java.net.URL)
10.838 + */
10.839 + public String toExternalForm() {
10.840 + throw new UnsupportedOperationException();
10.841 +// return handler.toExternalForm(this);
10.842 + }
10.843 +
10.844 + /**
10.845 + * Returns a {@link java.net.URLConnection URLConnection} instance that
10.846 + * represents a connection to the remote object referred to by the
10.847 + * {@code URL}.
10.848 + *
10.849 + * <P>A new instance of {@linkplain java.net.URLConnection URLConnection} is
10.850 + * created every time when invoking the
10.851 + * {@linkplain java.net.URLStreamHandler#openConnection(URL)
10.852 + * URLStreamHandler.openConnection(URL)} method of the protocol handler for
10.853 + * this URL.</P>
10.854 + *
10.855 + * <P>It should be noted that a URLConnection instance does not establish
10.856 + * the actual network connection on creation. This will happen only when
10.857 + * calling {@linkplain java.net.URLConnection#connect() URLConnection.connect()}.</P>
10.858 + *
10.859 + * <P>If for the URL's protocol (such as HTTP or JAR), there
10.860 + * exists a public, specialized URLConnection subclass belonging
10.861 + * to one of the following packages or one of their subpackages:
10.862 + * java.lang, java.io, java.util, java.net, the connection
10.863 + * returned will be of that subclass. For example, for HTTP an
10.864 + * HttpURLConnection will be returned, and for JAR a
10.865 + * JarURLConnection will be returned.</P>
10.866 + *
10.867 + * @return a {@link java.net.URLConnection URLConnection} linking
10.868 + * to the URL.
10.869 + * @exception IOException if an I/O exception occurs.
10.870 + * @see java.net.URL#URL(java.lang.String, java.lang.String,
10.871 + * int, java.lang.String)
10.872 + */
10.873 +// public URLConnection openConnection() throws java.io.IOException {
10.874 +// return handler.openConnection(this);
10.875 +// }
10.876 +
10.877 +
10.878 + /**
10.879 + * Opens a connection to this <code>URL</code> and returns an
10.880 + * <code>InputStream</code> for reading from that connection. This
10.881 + * method is a shorthand for:
10.882 + * <blockquote><pre>
10.883 + * openConnection().getInputStream()
10.884 + * </pre></blockquote>
10.885 + *
10.886 + * @return an input stream for reading from the URL connection.
10.887 + * @exception IOException if an I/O exception occurs.
10.888 + * @see java.net.URL#openConnection()
10.889 + * @see java.net.URLConnection#getInputStream()
10.890 + */
10.891 + public final InputStream openStream() throws java.io.IOException {
10.892 + throw new IOException();
10.893 +// return openConnection().getInputStream();
10.894 + }
10.895 +
10.896 + /**
10.897 + * Gets the contents of this URL. This method is a shorthand for:
10.898 + * <blockquote><pre>
10.899 + * openConnection().getContent()
10.900 + * </pre></blockquote>
10.901 + *
10.902 + * @return the contents of this URL.
10.903 + * @exception IOException if an I/O exception occurs.
10.904 + * @see java.net.URLConnection#getContent()
10.905 + */
10.906 + public final Object getContent() throws java.io.IOException {
10.907 + throw new IOException();
10.908 +// return openConnection().getContent();
10.909 + }
10.910 +
10.911 + /**
10.912 + * Gets the contents of this URL. This method is a shorthand for:
10.913 + * <blockquote><pre>
10.914 + * openConnection().getContent(Class[])
10.915 + * </pre></blockquote>
10.916 + *
10.917 + * @param classes an array of Java types
10.918 + * @return the content object of this URL that is the first match of
10.919 + * the types specified in the classes array.
10.920 + * null if none of the requested types are supported.
10.921 + * @exception IOException if an I/O exception occurs.
10.922 + * @see java.net.URLConnection#getContent(Class[])
10.923 + * @since 1.3
10.924 + */
10.925 + public final Object getContent(Class[] classes)
10.926 + throws java.io.IOException {
10.927 + throw new IOException();
10.928 +// return openConnection().getContent(classes);
10.929 + }
10.930 +
10.931 +
10.932 +}
10.933 +
10.934 +class Parts {
10.935 + String path, query, ref;
10.936 +
10.937 + Parts(String file) {
10.938 + int ind = file.indexOf('#');
10.939 + ref = ind < 0 ? null: file.substring(ind + 1);
10.940 + file = ind < 0 ? file: file.substring(0, ind);
10.941 + int q = file.lastIndexOf('?');
10.942 + if (q != -1) {
10.943 + query = file.substring(q+1);
10.944 + path = file.substring(0, q);
10.945 + } else {
10.946 + path = file;
10.947 + }
10.948 + }
10.949 +
10.950 + String getPath() {
10.951 + return path;
10.952 + }
10.953 +
10.954 + String getQuery() {
10.955 + return query;
10.956 + }
10.957 +
10.958 + String getRef() {
10.959 + return ref;
10.960 + }
10.961 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/emul/src/main/java/java/util/Enumeration.java Tue Oct 30 09:24:41 2012 +0100
11.3 @@ -0,0 +1,79 @@
11.4 +/*
11.5 + * Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Oracle designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Oracle in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
11.25 + * or visit www.oracle.com if you need additional information or have any
11.26 + * questions.
11.27 + */
11.28 +
11.29 +package java.util;
11.30 +
11.31 +/**
11.32 + * An object that implements the Enumeration interface generates a
11.33 + * series of elements, one at a time. Successive calls to the
11.34 + * <code>nextElement</code> method return successive elements of the
11.35 + * series.
11.36 + * <p>
11.37 + * For example, to print all elements of a <tt>Vector<E></tt> <i>v</i>:
11.38 + * <pre>
11.39 + * for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
11.40 + * System.out.println(e.nextElement());</pre>
11.41 + * <p>
11.42 + * Methods are provided to enumerate through the elements of a
11.43 + * vector, the keys of a hashtable, and the values in a hashtable.
11.44 + * Enumerations are also used to specify the input streams to a
11.45 + * <code>SequenceInputStream</code>.
11.46 + * <p>
11.47 + * NOTE: The functionality of this interface is duplicated by the Iterator
11.48 + * interface. In addition, Iterator adds an optional remove operation, and
11.49 + * has shorter method names. New implementations should consider using
11.50 + * Iterator in preference to Enumeration.
11.51 + *
11.52 + * @see java.util.Iterator
11.53 + * @see java.io.SequenceInputStream
11.54 + * @see java.util.Enumeration#nextElement()
11.55 + * @see java.util.Hashtable
11.56 + * @see java.util.Hashtable#elements()
11.57 + * @see java.util.Hashtable#keys()
11.58 + * @see java.util.Vector
11.59 + * @see java.util.Vector#elements()
11.60 + *
11.61 + * @author Lee Boynton
11.62 + * @since JDK1.0
11.63 + */
11.64 +public interface Enumeration<E> {
11.65 + /**
11.66 + * Tests if this enumeration contains more elements.
11.67 + *
11.68 + * @return <code>true</code> if and only if this enumeration object
11.69 + * contains at least one more element to provide;
11.70 + * <code>false</code> otherwise.
11.71 + */
11.72 + boolean hasMoreElements();
11.73 +
11.74 + /**
11.75 + * Returns the next element of this enumeration if this enumeration
11.76 + * object has at least one more element to provide.
11.77 + *
11.78 + * @return the next element of this enumeration.
11.79 + * @exception NoSuchElementException if no more elements exist.
11.80 + */
11.81 + E nextElement();
11.82 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/emul/src/main/java/java/util/NoSuchElementException.java Tue Oct 30 09:24:41 2012 +0100
12.3 @@ -0,0 +1,60 @@
12.4 +/*
12.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12.7 + *
12.8 + * This code is free software; you can redistribute it and/or modify it
12.9 + * under the terms of the GNU General Public License version 2 only, as
12.10 + * published by the Free Software Foundation. Oracle designates this
12.11 + * particular file as subject to the "Classpath" exception as provided
12.12 + * by Oracle in the LICENSE file that accompanied this code.
12.13 + *
12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12.17 + * version 2 for more details (a copy is included in the LICENSE file that
12.18 + * accompanied this code).
12.19 + *
12.20 + * You should have received a copy of the GNU General Public License version
12.21 + * 2 along with this work; if not, write to the Free Software Foundation,
12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12.23 + *
12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12.25 + * or visit www.oracle.com if you need additional information or have any
12.26 + * questions.
12.27 + */
12.28 +
12.29 +package java.util;
12.30 +
12.31 +/**
12.32 + * Thrown by the <code>nextElement</code> method of an
12.33 + * <code>Enumeration</code> to indicate that there are no more
12.34 + * elements in the enumeration.
12.35 + *
12.36 + * @author unascribed
12.37 + * @see java.util.Enumeration
12.38 + * @see java.util.Enumeration#nextElement()
12.39 + * @since JDK1.0
12.40 + */
12.41 +public
12.42 +class NoSuchElementException extends RuntimeException {
12.43 + private static final long serialVersionUID = 6769829250639411880L;
12.44 +
12.45 + /**
12.46 + * Constructs a <code>NoSuchElementException</code> with <tt>null</tt>
12.47 + * as its error message string.
12.48 + */
12.49 + public NoSuchElementException() {
12.50 + super();
12.51 + }
12.52 +
12.53 + /**
12.54 + * Constructs a <code>NoSuchElementException</code>, saving a reference
12.55 + * to the error message string <tt>s</tt> for later retrieval by the
12.56 + * <tt>getMessage</tt> method.
12.57 + *
12.58 + * @param s the detail message.
12.59 + */
12.60 + public NoSuchElementException(String s) {
12.61 + super(s);
12.62 + }
12.63 +}