1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/emul/src/main/java/java/io/EOFException.java Sat Nov 10 17:38:35 2012 +0100
1.3 @@ -0,0 +1,65 @@
1.4 +/*
1.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.io;
1.30 +
1.31 +/**
1.32 + * Signals that an end of file or end of stream has been reached
1.33 + * unexpectedly during input.
1.34 + * <p>
1.35 + * This exception is mainly used by data input streams to signal end of
1.36 + * stream. Note that many other input operations return a special value on
1.37 + * end of stream rather than throwing an exception.
1.38 + * <p>
1.39 + *
1.40 + * @author Frank Yellin
1.41 + * @see java.io.DataInputStream
1.42 + * @see java.io.IOException
1.43 + * @since JDK1.0
1.44 + */
1.45 +public
1.46 +class EOFException extends IOException {
1.47 + private static final long serialVersionUID = 6433858223774886977L;
1.48 +
1.49 + /**
1.50 + * Constructs an <code>EOFException</code> with <code>null</code>
1.51 + * as its error detail message.
1.52 + */
1.53 + public EOFException() {
1.54 + super();
1.55 + }
1.56 +
1.57 + /**
1.58 + * Constructs an <code>EOFException</code> with the specified detail
1.59 + * message. The string <code>s</code> may later be retrieved by the
1.60 + * <code>{@link java.lang.Throwable#getMessage}</code> method of class
1.61 + * <code>java.lang.Throwable</code>.
1.62 + *
1.63 + * @param s the detail message.
1.64 + */
1.65 + public EOFException(String s) {
1.66 + super(s);
1.67 + }
1.68 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/src/main/java/java/io/PushbackInputStream.java Sat Nov 10 17:38:35 2012 +0100
2.3 @@ -0,0 +1,383 @@
2.4 +/*
2.5 + * Copyright (c) 1994, 2011, 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 + * A <code>PushbackInputStream</code> adds
2.33 + * functionality to another input stream, namely
2.34 + * the ability to "push back" or "unread"
2.35 + * one byte. This is useful in situations where
2.36 + * it is convenient for a fragment of code
2.37 + * to read an indefinite number of data bytes
2.38 + * that are delimited by a particular byte
2.39 + * value; after reading the terminating byte,
2.40 + * the code fragment can "unread" it, so that
2.41 + * the next read operation on the input stream
2.42 + * will reread the byte that was pushed back.
2.43 + * For example, bytes representing the characters
2.44 + * constituting an identifier might be terminated
2.45 + * by a byte representing an operator character;
2.46 + * a method whose job is to read just an identifier
2.47 + * can read until it sees the operator and
2.48 + * then push the operator back to be re-read.
2.49 + *
2.50 + * @author David Connelly
2.51 + * @author Jonathan Payne
2.52 + * @since JDK1.0
2.53 + */
2.54 +public
2.55 +class PushbackInputStream extends FilterInputStream {
2.56 + /**
2.57 + * The pushback buffer.
2.58 + * @since JDK1.1
2.59 + */
2.60 + protected byte[] buf;
2.61 +
2.62 + /**
2.63 + * The position within the pushback buffer from which the next byte will
2.64 + * be read. When the buffer is empty, <code>pos</code> is equal to
2.65 + * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
2.66 + * equal to zero.
2.67 + *
2.68 + * @since JDK1.1
2.69 + */
2.70 + protected int pos;
2.71 +
2.72 + /**
2.73 + * Check to make sure that this stream has not been closed
2.74 + */
2.75 + private void ensureOpen() throws IOException {
2.76 + if (in == null)
2.77 + throw new IOException("Stream closed");
2.78 + }
2.79 +
2.80 + /**
2.81 + * Creates a <code>PushbackInputStream</code>
2.82 + * with a pushback buffer of the specified <code>size</code>,
2.83 + * and saves its argument, the input stream
2.84 + * <code>in</code>, for later use. Initially,
2.85 + * there is no pushed-back byte (the field
2.86 + * <code>pushBack</code> is initialized to
2.87 + * <code>-1</code>).
2.88 + *
2.89 + * @param in the input stream from which bytes will be read.
2.90 + * @param size the size of the pushback buffer.
2.91 + * @exception IllegalArgumentException if size is <= 0
2.92 + * @since JDK1.1
2.93 + */
2.94 + public PushbackInputStream(InputStream in, int size) {
2.95 + super(in);
2.96 + if (size <= 0) {
2.97 + throw new IllegalArgumentException("size <= 0");
2.98 + }
2.99 + this.buf = new byte[size];
2.100 + this.pos = size;
2.101 + }
2.102 +
2.103 + /**
2.104 + * Creates a <code>PushbackInputStream</code>
2.105 + * and saves its argument, the input stream
2.106 + * <code>in</code>, for later use. Initially,
2.107 + * there is no pushed-back byte (the field
2.108 + * <code>pushBack</code> is initialized to
2.109 + * <code>-1</code>).
2.110 + *
2.111 + * @param in the input stream from which bytes will be read.
2.112 + */
2.113 + public PushbackInputStream(InputStream in) {
2.114 + this(in, 1);
2.115 + }
2.116 +
2.117 + /**
2.118 + * Reads the next byte of data from this input stream. The value
2.119 + * byte is returned as an <code>int</code> in the range
2.120 + * <code>0</code> to <code>255</code>. If no byte is available
2.121 + * because the end of the stream has been reached, the value
2.122 + * <code>-1</code> is returned. This method blocks until input data
2.123 + * is available, the end of the stream is detected, or an exception
2.124 + * is thrown.
2.125 + *
2.126 + * <p> This method returns the most recently pushed-back byte, if there is
2.127 + * one, and otherwise calls the <code>read</code> method of its underlying
2.128 + * input stream and returns whatever value that method returns.
2.129 + *
2.130 + * @return the next byte of data, or <code>-1</code> if the end of the
2.131 + * stream has been reached.
2.132 + * @exception IOException if this input stream has been closed by
2.133 + * invoking its {@link #close()} method,
2.134 + * or an I/O error occurs.
2.135 + * @see java.io.InputStream#read()
2.136 + */
2.137 + public int read() throws IOException {
2.138 + ensureOpen();
2.139 + if (pos < buf.length) {
2.140 + return buf[pos++] & 0xff;
2.141 + }
2.142 + return super.read();
2.143 + }
2.144 +
2.145 + /**
2.146 + * Reads up to <code>len</code> bytes of data from this input stream into
2.147 + * an array of bytes. This method first reads any pushed-back bytes; after
2.148 + * that, if fewer than <code>len</code> bytes have been read then it
2.149 + * reads from the underlying input stream. If <code>len</code> is not zero, the method
2.150 + * blocks until at least 1 byte of input is available; otherwise, no
2.151 + * bytes are read and <code>0</code> is returned.
2.152 + *
2.153 + * @param b the buffer into which the data is read.
2.154 + * @param off the start offset in the destination array <code>b</code>
2.155 + * @param len the maximum number of bytes read.
2.156 + * @return the total number of bytes read into the buffer, or
2.157 + * <code>-1</code> if there is no more data because the end of
2.158 + * the stream has been reached.
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 + * @exception IOException if this input stream has been closed by
2.164 + * invoking its {@link #close()} method,
2.165 + * or an I/O error occurs.
2.166 + * @see java.io.InputStream#read(byte[], int, int)
2.167 + */
2.168 + public int read(byte[] b, int off, int len) throws IOException {
2.169 + ensureOpen();
2.170 + if (b == null) {
2.171 + throw new NullPointerException();
2.172 + } else if (off < 0 || len < 0 || len > b.length - off) {
2.173 + throw new IndexOutOfBoundsException();
2.174 + } else if (len == 0) {
2.175 + return 0;
2.176 + }
2.177 +
2.178 + int avail = buf.length - pos;
2.179 + if (avail > 0) {
2.180 + if (len < avail) {
2.181 + avail = len;
2.182 + }
2.183 + System.arraycopy(buf, pos, b, off, avail);
2.184 + pos += avail;
2.185 + off += avail;
2.186 + len -= avail;
2.187 + }
2.188 + if (len > 0) {
2.189 + len = super.read(b, off, len);
2.190 + if (len == -1) {
2.191 + return avail == 0 ? -1 : avail;
2.192 + }
2.193 + return avail + len;
2.194 + }
2.195 + return avail;
2.196 + }
2.197 +
2.198 + /**
2.199 + * Pushes back a byte by copying it to the front of the pushback buffer.
2.200 + * After this method returns, the next byte to be read will have the value
2.201 + * <code>(byte)b</code>.
2.202 + *
2.203 + * @param b the <code>int</code> value whose low-order
2.204 + * byte is to be pushed back.
2.205 + * @exception IOException If there is not enough room in the pushback
2.206 + * buffer for the byte, or this input stream has been closed by
2.207 + * invoking its {@link #close()} method.
2.208 + */
2.209 + public void unread(int b) throws IOException {
2.210 + ensureOpen();
2.211 + if (pos == 0) {
2.212 + throw new IOException("Push back buffer is full");
2.213 + }
2.214 + buf[--pos] = (byte)b;
2.215 + }
2.216 +
2.217 + /**
2.218 + * Pushes back a portion of an array of bytes by copying it to the front
2.219 + * of the pushback buffer. After this method returns, the next byte to be
2.220 + * read will have the value <code>b[off]</code>, the byte after that will
2.221 + * have the value <code>b[off+1]</code>, and so forth.
2.222 + *
2.223 + * @param b the byte array to push back.
2.224 + * @param off the start offset of the data.
2.225 + * @param len the number of bytes to push back.
2.226 + * @exception IOException If there is not enough room in the pushback
2.227 + * buffer for the specified number of bytes,
2.228 + * or this input stream has been closed by
2.229 + * invoking its {@link #close()} method.
2.230 + * @since JDK1.1
2.231 + */
2.232 + public void unread(byte[] b, int off, int len) throws IOException {
2.233 + ensureOpen();
2.234 + if (len > pos) {
2.235 + throw new IOException("Push back buffer is full");
2.236 + }
2.237 + pos -= len;
2.238 + System.arraycopy(b, off, buf, pos, len);
2.239 + }
2.240 +
2.241 + /**
2.242 + * Pushes back an array of bytes by copying it to the front of the
2.243 + * pushback buffer. After this method returns, the next byte to be read
2.244 + * will have the value <code>b[0]</code>, the byte after that will have the
2.245 + * value <code>b[1]</code>, and so forth.
2.246 + *
2.247 + * @param b the byte array to push back
2.248 + * @exception IOException If there is not enough room in the pushback
2.249 + * buffer for the specified number of bytes,
2.250 + * or this input stream has been closed by
2.251 + * invoking its {@link #close()} method.
2.252 + * @since JDK1.1
2.253 + */
2.254 + public void unread(byte[] b) throws IOException {
2.255 + unread(b, 0, b.length);
2.256 + }
2.257 +
2.258 + /**
2.259 + * Returns an estimate of the number of bytes that can be read (or
2.260 + * skipped over) from this input stream without blocking by the next
2.261 + * invocation of a method for this input stream. The next invocation might be
2.262 + * the same thread or another thread. A single read or skip of this
2.263 + * many bytes will not block, but may read or skip fewer bytes.
2.264 + *
2.265 + * <p> The method returns the sum of the number of bytes that have been
2.266 + * pushed back and the value returned by {@link
2.267 + * java.io.FilterInputStream#available available}.
2.268 + *
2.269 + * @return the number of bytes that can be read (or skipped over) from
2.270 + * the input stream without blocking.
2.271 + * @exception IOException if this input stream has been closed by
2.272 + * invoking its {@link #close()} method,
2.273 + * or an I/O error occurs.
2.274 + * @see java.io.FilterInputStream#in
2.275 + * @see java.io.InputStream#available()
2.276 + */
2.277 + public int available() throws IOException {
2.278 + ensureOpen();
2.279 + int n = buf.length - pos;
2.280 + int avail = super.available();
2.281 + return n > (Integer.MAX_VALUE - avail)
2.282 + ? Integer.MAX_VALUE
2.283 + : n + avail;
2.284 + }
2.285 +
2.286 + /**
2.287 + * Skips over and discards <code>n</code> bytes of data from this
2.288 + * input stream. The <code>skip</code> method may, for a variety of
2.289 + * reasons, end up skipping over some smaller number of bytes,
2.290 + * possibly zero. If <code>n</code> is negative, no bytes are skipped.
2.291 + *
2.292 + * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
2.293 + * first skips over the bytes in the pushback buffer, if any. It then
2.294 + * calls the <code>skip</code> method of the underlying input stream if
2.295 + * more bytes need to be skipped. The actual number of bytes skipped
2.296 + * is returned.
2.297 + *
2.298 + * @param n {@inheritDoc}
2.299 + * @return {@inheritDoc}
2.300 + * @exception IOException if the stream does not support seek,
2.301 + * or the stream has been closed by
2.302 + * invoking its {@link #close()} method,
2.303 + * or an I/O error occurs.
2.304 + * @see java.io.FilterInputStream#in
2.305 + * @see java.io.InputStream#skip(long n)
2.306 + * @since 1.2
2.307 + */
2.308 + public long skip(long n) throws IOException {
2.309 + ensureOpen();
2.310 + if (n <= 0) {
2.311 + return 0;
2.312 + }
2.313 +
2.314 + long pskip = buf.length - pos;
2.315 + if (pskip > 0) {
2.316 + if (n < pskip) {
2.317 + pskip = n;
2.318 + }
2.319 + pos += pskip;
2.320 + n -= pskip;
2.321 + }
2.322 + if (n > 0) {
2.323 + pskip += super.skip(n);
2.324 + }
2.325 + return pskip;
2.326 + }
2.327 +
2.328 + /**
2.329 + * Tests if this input stream supports the <code>mark</code> and
2.330 + * <code>reset</code> methods, which it does not.
2.331 + *
2.332 + * @return <code>false</code>, since this class does not support the
2.333 + * <code>mark</code> and <code>reset</code> methods.
2.334 + * @see java.io.InputStream#mark(int)
2.335 + * @see java.io.InputStream#reset()
2.336 + */
2.337 + public boolean markSupported() {
2.338 + return false;
2.339 + }
2.340 +
2.341 + /**
2.342 + * Marks the current position in this input stream.
2.343 + *
2.344 + * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
2.345 + * does nothing.
2.346 + *
2.347 + * @param readlimit the maximum limit of bytes that can be read before
2.348 + * the mark position becomes invalid.
2.349 + * @see java.io.InputStream#reset()
2.350 + */
2.351 + public synchronized void mark(int readlimit) {
2.352 + }
2.353 +
2.354 + /**
2.355 + * Repositions this stream to the position at the time the
2.356 + * <code>mark</code> method was last called on this input stream.
2.357 + *
2.358 + * <p> The method <code>reset</code> for class
2.359 + * <code>PushbackInputStream</code> does nothing except throw an
2.360 + * <code>IOException</code>.
2.361 + *
2.362 + * @exception IOException if this method is invoked.
2.363 + * @see java.io.InputStream#mark(int)
2.364 + * @see java.io.IOException
2.365 + */
2.366 + public synchronized void reset() throws IOException {
2.367 + throw new IOException("mark/reset not supported");
2.368 + }
2.369 +
2.370 + /**
2.371 + * Closes this input stream and releases any system resources
2.372 + * associated with the stream.
2.373 + * Once the stream has been closed, further read(), unread(),
2.374 + * available(), reset(), or skip() invocations will throw an IOException.
2.375 + * Closing a previously closed stream has no effect.
2.376 + *
2.377 + * @exception IOException if an I/O error occurs.
2.378 + */
2.379 + public synchronized void close() throws IOException {
2.380 + if (in == null)
2.381 + return;
2.382 + in.close();
2.383 + in = null;
2.384 + buf = null;
2.385 + }
2.386 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/emul/src/main/java/java/io/UTFDataFormatException.java Sat Nov 10 17:38:35 2012 +0100
3.3 @@ -0,0 +1,69 @@
3.4 +/*
3.5 + * Copyright (c) 1995, 2008, 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.io;
3.30 +
3.31 +/**
3.32 + * Signals that a malformed string in
3.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
3.34 + * format has been read in a data
3.35 + * input stream or by any class that implements the data input
3.36 + * interface.
3.37 + * See the
3.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
3.39 + * class description for the format in
3.40 + * which modified UTF-8 strings are read and written.
3.41 + *
3.42 + * @author Frank Yellin
3.43 + * @see java.io.DataInput
3.44 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
3.45 + * @see java.io.IOException
3.46 + * @since JDK1.0
3.47 + */
3.48 +public
3.49 +class UTFDataFormatException extends IOException {
3.50 + private static final long serialVersionUID = 420743449228280612L;
3.51 +
3.52 + /**
3.53 + * Constructs a <code>UTFDataFormatException</code> with
3.54 + * <code>null</code> as its error detail message.
3.55 + */
3.56 + public UTFDataFormatException() {
3.57 + super();
3.58 + }
3.59 +
3.60 + /**
3.61 + * Constructs a <code>UTFDataFormatException</code> with the
3.62 + * specified detail message. The string <code>s</code> can be
3.63 + * retrieved later by the
3.64 + * <code>{@link java.lang.Throwable#getMessage}</code>
3.65 + * method of class <code>java.lang.Throwable</code>.
3.66 + *
3.67 + * @param s the detail message.
3.68 + */
3.69 + public UTFDataFormatException(String s) {
3.70 + super(s);
3.71 + }
3.72 +}