1.1 --- a/benchmarks/matrix-multiplication/pom.xml Wed Jan 23 20:16:48 2013 +0100
1.2 +++ b/benchmarks/matrix-multiplication/pom.xml Wed Jan 23 20:39:23 2013 +0100
1.3 @@ -31,7 +31,7 @@
1.4 <dependencies>
1.5 <dependency>
1.6 <groupId>org.apidesign.bck2brwsr</groupId>
1.7 - <artifactId>emul</artifactId>
1.8 + <artifactId>emul.mini</artifactId>
1.9 <version>0.3-SNAPSHOT</version>
1.10 </dependency>
1.11 <dependency>
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/emul/mini/pom.xml Wed Jan 23 20:39:23 2013 +0100
2.3 @@ -0,0 +1,42 @@
2.4 +<?xml version="1.0"?>
2.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
2.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2.7 + <modelVersion>4.0.0</modelVersion>
2.8 + <parent>
2.9 + <groupId>org.apidesign.bck2brwsr</groupId>
2.10 + <artifactId>emul.pom</artifactId>
2.11 + <version>0.3-SNAPSHOT</version>
2.12 + </parent>
2.13 + <groupId>org.apidesign.bck2brwsr</groupId>
2.14 + <artifactId>emul.mini</artifactId>
2.15 + <version>0.3-SNAPSHOT</version>
2.16 + <name>Minimal API Profile</name>
2.17 + <url>http://maven.apache.org</url>
2.18 + <properties>
2.19 + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2.20 + </properties>
2.21 + <dependencies>
2.22 + <dependency>
2.23 + <groupId>org.apidesign.bck2brwsr</groupId>
2.24 + <artifactId>core</artifactId>
2.25 + <version>0.3-SNAPSHOT</version>
2.26 + <type>jar</type>
2.27 + </dependency>
2.28 + </dependencies>
2.29 + <build>
2.30 + <plugins>
2.31 + <plugin>
2.32 + <groupId>org.apache.maven.plugins</groupId>
2.33 + <artifactId>maven-compiler-plugin</artifactId>
2.34 + <version>2.5.1</version>
2.35 + <configuration>
2.36 + <compilerArguments>
2.37 + <bootclasspath>netbeans.ignore.jdk.bootsclasspath</bootclasspath>
2.38 + </compilerArguments>
2.39 + <source>1.7</source>
2.40 + <target>1.7</target>
2.41 + </configuration>
2.42 + </plugin>
2.43 + </plugins>
2.44 + </build>
2.45 +</project>
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/emul/mini/src/main/java/java/io/ByteArrayInputStream.java Wed Jan 23 20:39:23 2013 +0100
3.3 @@ -0,0 +1,283 @@
3.4 +/*
3.5 + * Copyright (c) 1994, 2010, 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 + * A <code>ByteArrayInputStream</code> contains
3.33 + * an internal buffer that contains bytes that
3.34 + * may be read from the stream. An internal
3.35 + * counter keeps track of the next byte to
3.36 + * be supplied by the <code>read</code> method.
3.37 + * <p>
3.38 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
3.39 + * this class can be called after the stream has been closed without
3.40 + * generating an <tt>IOException</tt>.
3.41 + *
3.42 + * @author Arthur van Hoff
3.43 + * @see java.io.StringBufferInputStream
3.44 + * @since JDK1.0
3.45 + */
3.46 +public
3.47 +class ByteArrayInputStream extends InputStream {
3.48 +
3.49 + /**
3.50 + * An array of bytes that was provided
3.51 + * by the creator of the stream. Elements <code>buf[0]</code>
3.52 + * through <code>buf[count-1]</code> are the
3.53 + * only bytes that can ever be read from the
3.54 + * stream; element <code>buf[pos]</code> is
3.55 + * the next byte to be read.
3.56 + */
3.57 + protected byte buf[];
3.58 +
3.59 + /**
3.60 + * The index of the next character to read from the input stream buffer.
3.61 + * This value should always be nonnegative
3.62 + * and not larger than the value of <code>count</code>.
3.63 + * The next byte to be read from the input stream buffer
3.64 + * will be <code>buf[pos]</code>.
3.65 + */
3.66 + protected int pos;
3.67 +
3.68 + /**
3.69 + * The currently marked position in the stream.
3.70 + * ByteArrayInputStream objects are marked at position zero by
3.71 + * default when constructed. They may be marked at another
3.72 + * position within the buffer by the <code>mark()</code> method.
3.73 + * The current buffer position is set to this point by the
3.74 + * <code>reset()</code> method.
3.75 + * <p>
3.76 + * If no mark has been set, then the value of mark is the offset
3.77 + * passed to the constructor (or 0 if the offset was not supplied).
3.78 + *
3.79 + * @since JDK1.1
3.80 + */
3.81 + protected int mark = 0;
3.82 +
3.83 + /**
3.84 + * The index one greater than the last valid character in the input
3.85 + * stream buffer.
3.86 + * This value should always be nonnegative
3.87 + * and not larger than the length of <code>buf</code>.
3.88 + * It is one greater than the position of
3.89 + * the last byte within <code>buf</code> that
3.90 + * can ever be read from the input stream buffer.
3.91 + */
3.92 + protected int count;
3.93 +
3.94 + /**
3.95 + * Creates a <code>ByteArrayInputStream</code>
3.96 + * so that it uses <code>buf</code> as its
3.97 + * buffer array.
3.98 + * The buffer array is not copied.
3.99 + * The initial value of <code>pos</code>
3.100 + * is <code>0</code> and the initial value
3.101 + * of <code>count</code> is the length of
3.102 + * <code>buf</code>.
3.103 + *
3.104 + * @param buf the input buffer.
3.105 + */
3.106 + public ByteArrayInputStream(byte buf[]) {
3.107 + this.buf = buf;
3.108 + this.pos = 0;
3.109 + this.count = buf.length;
3.110 + }
3.111 +
3.112 + /**
3.113 + * Creates <code>ByteArrayInputStream</code>
3.114 + * that uses <code>buf</code> as its
3.115 + * buffer array. The initial value of <code>pos</code>
3.116 + * is <code>offset</code> and the initial value
3.117 + * of <code>count</code> is the minimum of <code>offset+length</code>
3.118 + * and <code>buf.length</code>.
3.119 + * The buffer array is not copied. The buffer's mark is
3.120 + * set to the specified offset.
3.121 + *
3.122 + * @param buf the input buffer.
3.123 + * @param offset the offset in the buffer of the first byte to read.
3.124 + * @param length the maximum number of bytes to read from the buffer.
3.125 + */
3.126 + public ByteArrayInputStream(byte buf[], int offset, int length) {
3.127 + this.buf = buf;
3.128 + this.pos = offset;
3.129 + this.count = Math.min(offset + length, buf.length);
3.130 + this.mark = offset;
3.131 + }
3.132 +
3.133 + /**
3.134 + * Reads the next byte of data from this input stream. The value
3.135 + * byte is returned as an <code>int</code> in the range
3.136 + * <code>0</code> to <code>255</code>. If no byte is available
3.137 + * because the end of the stream has been reached, the value
3.138 + * <code>-1</code> is returned.
3.139 + * <p>
3.140 + * This <code>read</code> method
3.141 + * cannot block.
3.142 + *
3.143 + * @return the next byte of data, or <code>-1</code> if the end of the
3.144 + * stream has been reached.
3.145 + */
3.146 + public synchronized int read() {
3.147 + return (pos < count) ? (buf[pos++] & 0xff) : -1;
3.148 + }
3.149 +
3.150 + /**
3.151 + * Reads up to <code>len</code> bytes of data into an array of bytes
3.152 + * from this input stream.
3.153 + * If <code>pos</code> equals <code>count</code>,
3.154 + * then <code>-1</code> is returned to indicate
3.155 + * end of file. Otherwise, the number <code>k</code>
3.156 + * of bytes read is equal to the smaller of
3.157 + * <code>len</code> and <code>count-pos</code>.
3.158 + * If <code>k</code> is positive, then bytes
3.159 + * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
3.160 + * are copied into <code>b[off]</code> through
3.161 + * <code>b[off+k-1]</code> in the manner performed
3.162 + * by <code>System.arraycopy</code>. The
3.163 + * value <code>k</code> is added into <code>pos</code>
3.164 + * and <code>k</code> is returned.
3.165 + * <p>
3.166 + * This <code>read</code> method cannot block.
3.167 + *
3.168 + * @param b the buffer into which the data is read.
3.169 + * @param off the start offset in the destination array <code>b</code>
3.170 + * @param len the maximum number of bytes read.
3.171 + * @return the total number of bytes read into the buffer, or
3.172 + * <code>-1</code> if there is no more data because the end of
3.173 + * the stream has been reached.
3.174 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
3.175 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
3.176 + * <code>len</code> is negative, or <code>len</code> is greater than
3.177 + * <code>b.length - off</code>
3.178 + */
3.179 + public synchronized int read(byte b[], int off, int len) {
3.180 + if (b == null) {
3.181 + throw new NullPointerException();
3.182 + } else if (off < 0 || len < 0 || len > b.length - off) {
3.183 + throw new IndexOutOfBoundsException();
3.184 + }
3.185 +
3.186 + if (pos >= count) {
3.187 + return -1;
3.188 + }
3.189 +
3.190 + int avail = count - pos;
3.191 + if (len > avail) {
3.192 + len = avail;
3.193 + }
3.194 + if (len <= 0) {
3.195 + return 0;
3.196 + }
3.197 + PushbackInputStream.arraycopy(buf, pos, b, off, len);
3.198 + pos += len;
3.199 + return len;
3.200 + }
3.201 +
3.202 + /**
3.203 + * Skips <code>n</code> bytes of input from this input stream. Fewer
3.204 + * bytes might be skipped if the end of the input stream is reached.
3.205 + * The actual number <code>k</code>
3.206 + * of bytes to be skipped is equal to the smaller
3.207 + * of <code>n</code> and <code>count-pos</code>.
3.208 + * The value <code>k</code> is added into <code>pos</code>
3.209 + * and <code>k</code> is returned.
3.210 + *
3.211 + * @param n the number of bytes to be skipped.
3.212 + * @return the actual number of bytes skipped.
3.213 + */
3.214 + public synchronized long skip(long n) {
3.215 + long k = count - pos;
3.216 + if (n < k) {
3.217 + k = n < 0 ? 0 : n;
3.218 + }
3.219 +
3.220 + pos += k;
3.221 + return k;
3.222 + }
3.223 +
3.224 + /**
3.225 + * Returns the number of remaining bytes that can be read (or skipped over)
3.226 + * from this input stream.
3.227 + * <p>
3.228 + * The value returned is <code>count - pos</code>,
3.229 + * which is the number of bytes remaining to be read from the input buffer.
3.230 + *
3.231 + * @return the number of remaining bytes that can be read (or skipped
3.232 + * over) from this input stream without blocking.
3.233 + */
3.234 + public synchronized int available() {
3.235 + return count - pos;
3.236 + }
3.237 +
3.238 + /**
3.239 + * Tests if this <code>InputStream</code> supports mark/reset. The
3.240 + * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
3.241 + * always returns <code>true</code>.
3.242 + *
3.243 + * @since JDK1.1
3.244 + */
3.245 + public boolean markSupported() {
3.246 + return true;
3.247 + }
3.248 +
3.249 + /**
3.250 + * Set the current marked position in the stream.
3.251 + * ByteArrayInputStream objects are marked at position zero by
3.252 + * default when constructed. They may be marked at another
3.253 + * position within the buffer by this method.
3.254 + * <p>
3.255 + * If no mark has been set, then the value of the mark is the
3.256 + * offset passed to the constructor (or 0 if the offset was not
3.257 + * supplied).
3.258 + *
3.259 + * <p> Note: The <code>readAheadLimit</code> for this class
3.260 + * has no meaning.
3.261 + *
3.262 + * @since JDK1.1
3.263 + */
3.264 + public void mark(int readAheadLimit) {
3.265 + mark = pos;
3.266 + }
3.267 +
3.268 + /**
3.269 + * Resets the buffer to the marked position. The marked position
3.270 + * is 0 unless another position was marked or an offset was specified
3.271 + * in the constructor.
3.272 + */
3.273 + public synchronized void reset() {
3.274 + pos = mark;
3.275 + }
3.276 +
3.277 + /**
3.278 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
3.279 + * this class can be called after the stream has been closed without
3.280 + * generating an <tt>IOException</tt>.
3.281 + * <p>
3.282 + */
3.283 + public void close() throws IOException {
3.284 + }
3.285 +
3.286 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/emul/mini/src/main/java/java/io/Closeable.java Wed Jan 23 20:39:23 2013 +0100
4.3 @@ -0,0 +1,48 @@
4.4 +/*
4.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4.7 + *
4.8 + * This code is free software; you can redistribute it and/or modify it
4.9 + * under the terms of the GNU General Public License version 2 only, as
4.10 + * published by the Free Software Foundation. Oracle designates this
4.11 + * particular file as subject to the "Classpath" exception as provided
4.12 + * by Oracle in the LICENSE file that accompanied this code.
4.13 + *
4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4.17 + * version 2 for more details (a copy is included in the LICENSE file that
4.18 + * accompanied this code).
4.19 + *
4.20 + * You should have received a copy of the GNU General Public License version
4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4.23 + *
4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4.25 + * or visit www.oracle.com if you need additional information or have any
4.26 + * questions.
4.27 + */
4.28 +
4.29 +package java.io;
4.30 +
4.31 +import java.io.IOException;
4.32 +
4.33 +/**
4.34 + * A {@code Closeable} is a source or destination of data that can be closed.
4.35 + * The close method is invoked to release resources that the object is
4.36 + * holding (such as open files).
4.37 + *
4.38 + * @since 1.5
4.39 + */
4.40 +
4.41 +public interface Closeable extends AutoCloseable {
4.42 +
4.43 + /**
4.44 + * Closes this stream and releases any system resources associated
4.45 + * with it. If the stream is already closed then invoking this
4.46 + * method has no effect.
4.47 + *
4.48 + * @throws IOException if an I/O error occurs
4.49 + */
4.50 + public void close() throws IOException;
4.51 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/emul/mini/src/main/java/java/io/DataInput.java Wed Jan 23 20:39:23 2013 +0100
5.3 @@ -0,0 +1,635 @@
5.4 +/*
5.5 + * Copyright (c) 1995, 2006, 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.io;
5.30 +
5.31 +/**
5.32 + * The <code>DataInput</code> interface provides
5.33 + * for reading bytes from a binary stream and
5.34 + * reconstructing from them data in any of
5.35 + * the Java primitive types. There is also
5.36 + * a
5.37 + * facility for reconstructing a <code>String</code>
5.38 + * from data in
5.39 + * <a href="#modified-utf-8">modified UTF-8</a>
5.40 + * format.
5.41 + * <p>
5.42 + * It is generally true of all the reading
5.43 + * routines in this interface that if end of
5.44 + * file is reached before the desired number
5.45 + * of bytes has been read, an <code>EOFException</code>
5.46 + * (which is a kind of <code>IOException</code>)
5.47 + * is thrown. If any byte cannot be read for
5.48 + * any reason other than end of file, an <code>IOException</code>
5.49 + * other than <code>EOFException</code> is
5.50 + * thrown. In particular, an <code>IOException</code>
5.51 + * may be thrown if the input stream has been
5.52 + * closed.
5.53 + *
5.54 + * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
5.55 + * <p>
5.56 + * Implementations of the DataInput and DataOutput interfaces represent
5.57 + * Unicode strings in a format that is a slight modification of UTF-8.
5.58 + * (For information regarding the standard UTF-8 format, see section
5.59 + * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
5.60 + * 4.0</i>).
5.61 + * Note that in the following tables, the most significant bit appears in the
5.62 + * far left-hand column.
5.63 + * <p>
5.64 + * All characters in the range <code>'\u0001'</code> to
5.65 + * <code>'\u007F'</code> are represented by a single byte:
5.66 + *
5.67 + * <blockquote>
5.68 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
5.69 + * summary="Bit values and bytes">
5.70 + * <tr>
5.71 + * <td></td>
5.72 + * <th id="bit">Bit Values</th>
5.73 + * </tr>
5.74 + * <tr>
5.75 + * <th id="byte1">Byte 1</th>
5.76 + * <td>
5.77 + * <table border="1" cellspacing="0" width="100%">
5.78 + * <tr>
5.79 + * <td width="12%"><center>0</center>
5.80 + * <td colspan="7"><center>bits 6-0</center>
5.81 + * </tr>
5.82 + * </table>
5.83 + * </td>
5.84 + * </tr>
5.85 + * </table>
5.86 + * </blockquote>
5.87 + *
5.88 + * <p>
5.89 + * The null character <code>'\u0000'</code> and characters in the
5.90 + * range <code>'\u0080'</code> to <code>'\u07FF'</code> are
5.91 + * represented by a pair of bytes:
5.92 + *
5.93 + * <blockquote>
5.94 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
5.95 + * summary="Bit values and bytes">
5.96 + * <tr>
5.97 + * <td></td>
5.98 + * <th id="bit">Bit Values</th>
5.99 + * </tr>
5.100 + * <tr>
5.101 + * <th id="byte1">Byte 1</th>
5.102 + * <td>
5.103 + * <table border="1" cellspacing="0" width="100%">
5.104 + * <tr>
5.105 + * <td width="12%"><center>1</center>
5.106 + * <td width="13%"><center>1</center>
5.107 + * <td width="12%"><center>0</center>
5.108 + * <td colspan="5"><center>bits 10-6</center>
5.109 + * </tr>
5.110 + * </table>
5.111 + * </td>
5.112 + * </tr>
5.113 + * <tr>
5.114 + * <th id="byte2">Byte 2</th>
5.115 + * <td>
5.116 + * <table border="1" cellspacing="0" width="100%">
5.117 + * <tr>
5.118 + * <td width="12%"><center>1</center>
5.119 + * <td width="13%"><center>0</center>
5.120 + * <td colspan="6"><center>bits 5-0</center>
5.121 + * </tr>
5.122 + * </table>
5.123 + * </td>
5.124 + * </tr>
5.125 + * </table>
5.126 + * </blockquote>
5.127 + *
5.128 + * <br>
5.129 + * <code>char</code> values in the range <code>'\u0800'</code> to
5.130 + * <code>'\uFFFF'</code> are represented by three bytes:
5.131 + *
5.132 + * <blockquote>
5.133 + * <table border="1" cellspacing="0" cellpadding="8" width="50%"
5.134 + * summary="Bit values and bytes">
5.135 + * <tr>
5.136 + * <td></td>
5.137 + * <th id="bit">Bit Values</th>
5.138 + * </tr>
5.139 + * <tr>
5.140 + * <th id="byte1">Byte 1</th>
5.141 + * <td>
5.142 + * <table border="1" cellspacing="0" width="100%">
5.143 + * <tr>
5.144 + * <td width="12%"><center>1</center>
5.145 + * <td width="13%"><center>1</center>
5.146 + * <td width="12%"><center>1</center>
5.147 + * <td width="13%"><center>0</center>
5.148 + * <td colspan="4"><center>bits 15-12</center>
5.149 + * </tr>
5.150 + * </table>
5.151 + * </td>
5.152 + * </tr>
5.153 + * <tr>
5.154 + * <th id="byte2">Byte 2</th>
5.155 + * <td>
5.156 + * <table border="1" cellspacing="0" width="100%">
5.157 + * <tr>
5.158 + * <td width="12%"><center>1</center>
5.159 + * <td width="13%"><center>0</center>
5.160 + * <td colspan="6"><center>bits 11-6</center>
5.161 + * </tr>
5.162 + * </table>
5.163 + * </td>
5.164 + * </tr>
5.165 + * <tr>
5.166 + * <th id="byte3">Byte 3</th>
5.167 + * <td>
5.168 + * <table border="1" cellspacing="0" width="100%">
5.169 + * <tr>
5.170 + * <td width="12%"><center>1</center>
5.171 + * <td width="13%"><center>0</center>
5.172 + * <td colspan="6"><center>bits 5-0</center>
5.173 + * </tr>
5.174 + * </table>
5.175 + * </td>
5.176 + * </tr>
5.177 + * </table>
5.178 + * </blockquote>
5.179 + *
5.180 + * <p>
5.181 + * The differences between this format and the
5.182 + * standard UTF-8 format are the following:
5.183 + * <ul>
5.184 + * <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
5.185 + * rather than 1-byte, so that the encoded strings never have
5.186 + * embedded nulls.
5.187 + * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
5.188 + * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
5.189 + * are represented in the form of surrogate pairs.
5.190 + * </ul>
5.191 + * @author Frank Yellin
5.192 + * @see java.io.DataInputStream
5.193 + * @see java.io.DataOutput
5.194 + * @since JDK1.0
5.195 + */
5.196 +public
5.197 +interface DataInput {
5.198 + /**
5.199 + * Reads some bytes from an input
5.200 + * stream and stores them into the buffer
5.201 + * array <code>b</code>. The number of bytes
5.202 + * read is equal
5.203 + * to the length of <code>b</code>.
5.204 + * <p>
5.205 + * This method blocks until one of the
5.206 + * following conditions occurs:<p>
5.207 + * <ul>
5.208 + * <li><code>b.length</code>
5.209 + * bytes of input data are available, in which
5.210 + * case a normal return is made.
5.211 + *
5.212 + * <li>End of
5.213 + * file is detected, in which case an <code>EOFException</code>
5.214 + * is thrown.
5.215 + *
5.216 + * <li>An I/O error occurs, in
5.217 + * which case an <code>IOException</code> other
5.218 + * than <code>EOFException</code> is thrown.
5.219 + * </ul>
5.220 + * <p>
5.221 + * If <code>b</code> is <code>null</code>,
5.222 + * a <code>NullPointerException</code> is thrown.
5.223 + * If <code>b.length</code> is zero, then
5.224 + * no bytes are read. Otherwise, the first
5.225 + * byte read is stored into element <code>b[0]</code>,
5.226 + * the next one into <code>b[1]</code>, and
5.227 + * so on.
5.228 + * If an exception is thrown from
5.229 + * this method, then it may be that some but
5.230 + * not all bytes of <code>b</code> have been
5.231 + * updated with data from the input stream.
5.232 + *
5.233 + * @param b the buffer into which the data is read.
5.234 + * @exception EOFException if this stream reaches the end before reading
5.235 + * all the bytes.
5.236 + * @exception IOException if an I/O error occurs.
5.237 + */
5.238 + void readFully(byte b[]) throws IOException;
5.239 +
5.240 + /**
5.241 + *
5.242 + * Reads <code>len</code>
5.243 + * bytes from
5.244 + * an input stream.
5.245 + * <p>
5.246 + * This method
5.247 + * blocks until one of the following conditions
5.248 + * occurs:<p>
5.249 + * <ul>
5.250 + * <li><code>len</code> bytes
5.251 + * of input data are available, in which case
5.252 + * a normal return is made.
5.253 + *
5.254 + * <li>End of file
5.255 + * is detected, in which case an <code>EOFException</code>
5.256 + * is thrown.
5.257 + *
5.258 + * <li>An I/O error occurs, in
5.259 + * which case an <code>IOException</code> other
5.260 + * than <code>EOFException</code> is thrown.
5.261 + * </ul>
5.262 + * <p>
5.263 + * If <code>b</code> is <code>null</code>,
5.264 + * a <code>NullPointerException</code> is thrown.
5.265 + * If <code>off</code> is negative, or <code>len</code>
5.266 + * is negative, or <code>off+len</code> is
5.267 + * greater than the length of the array <code>b</code>,
5.268 + * then an <code>IndexOutOfBoundsException</code>
5.269 + * is thrown.
5.270 + * If <code>len</code> is zero,
5.271 + * then no bytes are read. Otherwise, the first
5.272 + * byte read is stored into element <code>b[off]</code>,
5.273 + * the next one into <code>b[off+1]</code>,
5.274 + * and so on. The number of bytes read is,
5.275 + * at most, equal to <code>len</code>.
5.276 + *
5.277 + * @param b the buffer into which the data is read.
5.278 + * @param off an int specifying the offset into the data.
5.279 + * @param len an int specifying the number of bytes to read.
5.280 + * @exception EOFException if this stream reaches the end before reading
5.281 + * all the bytes.
5.282 + * @exception IOException if an I/O error occurs.
5.283 + */
5.284 + void readFully(byte b[], int off, int len) throws IOException;
5.285 +
5.286 + /**
5.287 + * Makes an attempt to skip over
5.288 + * <code>n</code> bytes
5.289 + * of data from the input
5.290 + * stream, discarding the skipped bytes. However,
5.291 + * it may skip
5.292 + * over some smaller number of
5.293 + * bytes, possibly zero. This may result from
5.294 + * any of a
5.295 + * number of conditions; reaching
5.296 + * end of file before <code>n</code> bytes
5.297 + * have been skipped is
5.298 + * only one possibility.
5.299 + * This method never throws an <code>EOFException</code>.
5.300 + * The actual
5.301 + * number of bytes skipped is returned.
5.302 + *
5.303 + * @param n the number of bytes to be skipped.
5.304 + * @return the number of bytes actually skipped.
5.305 + * @exception IOException if an I/O error occurs.
5.306 + */
5.307 + int skipBytes(int n) throws IOException;
5.308 +
5.309 + /**
5.310 + * Reads one input byte and returns
5.311 + * <code>true</code> if that byte is nonzero,
5.312 + * <code>false</code> if that byte is zero.
5.313 + * This method is suitable for reading
5.314 + * the byte written by the <code>writeBoolean</code>
5.315 + * method of interface <code>DataOutput</code>.
5.316 + *
5.317 + * @return the <code>boolean</code> value read.
5.318 + * @exception EOFException if this stream reaches the end before reading
5.319 + * all the bytes.
5.320 + * @exception IOException if an I/O error occurs.
5.321 + */
5.322 + boolean readBoolean() throws IOException;
5.323 +
5.324 + /**
5.325 + * Reads and returns one input byte.
5.326 + * The byte is treated as a signed value in
5.327 + * the range <code>-128</code> through <code>127</code>,
5.328 + * inclusive.
5.329 + * This method is suitable for
5.330 + * reading the byte written by the <code>writeByte</code>
5.331 + * method of interface <code>DataOutput</code>.
5.332 + *
5.333 + * @return the 8-bit value read.
5.334 + * @exception EOFException if this stream reaches the end before reading
5.335 + * all the bytes.
5.336 + * @exception IOException if an I/O error occurs.
5.337 + */
5.338 + byte readByte() throws IOException;
5.339 +
5.340 + /**
5.341 + * Reads one input byte, zero-extends
5.342 + * it to type <code>int</code>, and returns
5.343 + * the result, which is therefore in the range
5.344 + * <code>0</code>
5.345 + * through <code>255</code>.
5.346 + * This method is suitable for reading
5.347 + * the byte written by the <code>writeByte</code>
5.348 + * method of interface <code>DataOutput</code>
5.349 + * if the argument to <code>writeByte</code>
5.350 + * was intended to be a value in the range
5.351 + * <code>0</code> through <code>255</code>.
5.352 + *
5.353 + * @return the unsigned 8-bit value read.
5.354 + * @exception EOFException if this stream reaches the end before reading
5.355 + * all the bytes.
5.356 + * @exception IOException if an I/O error occurs.
5.357 + */
5.358 + int readUnsignedByte() throws IOException;
5.359 +
5.360 + /**
5.361 + * Reads two input bytes and returns
5.362 + * a <code>short</code> value. Let <code>a</code>
5.363 + * be the first byte read and <code>b</code>
5.364 + * be the second byte. The value
5.365 + * returned
5.366 + * is:
5.367 + * <p><pre><code>(short)((a << 8) | (b & 0xff))
5.368 + * </code></pre>
5.369 + * This method
5.370 + * is suitable for reading the bytes written
5.371 + * by the <code>writeShort</code> method of
5.372 + * interface <code>DataOutput</code>.
5.373 + *
5.374 + * @return the 16-bit value read.
5.375 + * @exception EOFException if this stream reaches the end before reading
5.376 + * all the bytes.
5.377 + * @exception IOException if an I/O error occurs.
5.378 + */
5.379 + short readShort() throws IOException;
5.380 +
5.381 + /**
5.382 + * Reads two input bytes and returns
5.383 + * an <code>int</code> value in the range <code>0</code>
5.384 + * through <code>65535</code>. Let <code>a</code>
5.385 + * be the first byte read and
5.386 + * <code>b</code>
5.387 + * be the second byte. The value returned is:
5.388 + * <p><pre><code>(((a & 0xff) << 8) | (b & 0xff))
5.389 + * </code></pre>
5.390 + * This method is suitable for reading the bytes
5.391 + * written by the <code>writeShort</code> method
5.392 + * of interface <code>DataOutput</code> if
5.393 + * the argument to <code>writeShort</code>
5.394 + * was intended to be a value in the range
5.395 + * <code>0</code> through <code>65535</code>.
5.396 + *
5.397 + * @return the unsigned 16-bit value read.
5.398 + * @exception EOFException if this stream reaches the end before reading
5.399 + * all the bytes.
5.400 + * @exception IOException if an I/O error occurs.
5.401 + */
5.402 + int readUnsignedShort() throws IOException;
5.403 +
5.404 + /**
5.405 + * Reads two input bytes and returns a <code>char</code> value.
5.406 + * Let <code>a</code>
5.407 + * be the first byte read and <code>b</code>
5.408 + * be the second byte. The value
5.409 + * returned is:
5.410 + * <p><pre><code>(char)((a << 8) | (b & 0xff))
5.411 + * </code></pre>
5.412 + * This method
5.413 + * is suitable for reading bytes written by
5.414 + * the <code>writeChar</code> method of interface
5.415 + * <code>DataOutput</code>.
5.416 + *
5.417 + * @return the <code>char</code> value read.
5.418 + * @exception EOFException if this stream reaches the end before reading
5.419 + * all the bytes.
5.420 + * @exception IOException if an I/O error occurs.
5.421 + */
5.422 + char readChar() throws IOException;
5.423 +
5.424 + /**
5.425 + * Reads four input bytes and returns an
5.426 + * <code>int</code> value. Let <code>a-d</code>
5.427 + * be the first through fourth bytes read. The value returned is:
5.428 + * <p><pre>
5.429 + * <code>
5.430 + * (((a & 0xff) << 24) | ((b & 0xff) << 16) |
5.431 + *  ((c & 0xff) << 8) | (d & 0xff))
5.432 + * </code></pre>
5.433 + * This method is suitable
5.434 + * for reading bytes written by the <code>writeInt</code>
5.435 + * method of interface <code>DataOutput</code>.
5.436 + *
5.437 + * @return the <code>int</code> value read.
5.438 + * @exception EOFException if this stream reaches the end before reading
5.439 + * all the bytes.
5.440 + * @exception IOException if an I/O error occurs.
5.441 + */
5.442 + int readInt() throws IOException;
5.443 +
5.444 + /**
5.445 + * Reads eight input bytes and returns
5.446 + * a <code>long</code> value. Let <code>a-h</code>
5.447 + * be the first through eighth bytes read.
5.448 + * The value returned is:
5.449 + * <p><pre> <code>
5.450 + * (((long)(a & 0xff) << 56) |
5.451 + * ((long)(b & 0xff) << 48) |
5.452 + * ((long)(c & 0xff) << 40) |
5.453 + * ((long)(d & 0xff) << 32) |
5.454 + * ((long)(e & 0xff) << 24) |
5.455 + * ((long)(f & 0xff) << 16) |
5.456 + * ((long)(g & 0xff) << 8) |
5.457 + * ((long)(h & 0xff)))
5.458 + * </code></pre>
5.459 + * <p>
5.460 + * This method is suitable
5.461 + * for reading bytes written by the <code>writeLong</code>
5.462 + * method of interface <code>DataOutput</code>.
5.463 + *
5.464 + * @return the <code>long</code> value read.
5.465 + * @exception EOFException if this stream reaches the end before reading
5.466 + * all the bytes.
5.467 + * @exception IOException if an I/O error occurs.
5.468 + */
5.469 + long readLong() throws IOException;
5.470 +
5.471 + /**
5.472 + * Reads four input bytes and returns
5.473 + * a <code>float</code> value. It does this
5.474 + * by first constructing an <code>int</code>
5.475 + * value in exactly the manner
5.476 + * of the <code>readInt</code>
5.477 + * method, then converting this <code>int</code>
5.478 + * value to a <code>float</code> in
5.479 + * exactly the manner of the method <code>Float.intBitsToFloat</code>.
5.480 + * This method is suitable for reading
5.481 + * bytes written by the <code>writeFloat</code>
5.482 + * method of interface <code>DataOutput</code>.
5.483 + *
5.484 + * @return the <code>float</code> value read.
5.485 + * @exception EOFException if this stream reaches the end before reading
5.486 + * all the bytes.
5.487 + * @exception IOException if an I/O error occurs.
5.488 + */
5.489 + float readFloat() throws IOException;
5.490 +
5.491 + /**
5.492 + * Reads eight input bytes and returns
5.493 + * a <code>double</code> value. It does this
5.494 + * by first constructing a <code>long</code>
5.495 + * value in exactly the manner
5.496 + * of the <code>readlong</code>
5.497 + * method, then converting this <code>long</code>
5.498 + * value to a <code>double</code> in exactly
5.499 + * the manner of the method <code>Double.longBitsToDouble</code>.
5.500 + * This method is suitable for reading
5.501 + * bytes written by the <code>writeDouble</code>
5.502 + * method of interface <code>DataOutput</code>.
5.503 + *
5.504 + * @return the <code>double</code> value read.
5.505 + * @exception EOFException if this stream reaches the end before reading
5.506 + * all the bytes.
5.507 + * @exception IOException if an I/O error occurs.
5.508 + */
5.509 + double readDouble() throws IOException;
5.510 +
5.511 + /**
5.512 + * Reads the next line of text from the input stream.
5.513 + * It reads successive bytes, converting
5.514 + * each byte separately into a character,
5.515 + * until it encounters a line terminator or
5.516 + * end of
5.517 + * file; the characters read are then
5.518 + * returned as a <code>String</code>. Note
5.519 + * that because this
5.520 + * method processes bytes,
5.521 + * it does not support input of the full Unicode
5.522 + * character set.
5.523 + * <p>
5.524 + * If end of file is encountered
5.525 + * before even one byte can be read, then <code>null</code>
5.526 + * is returned. Otherwise, each byte that is
5.527 + * read is converted to type <code>char</code>
5.528 + * by zero-extension. If the character <code>'\n'</code>
5.529 + * is encountered, it is discarded and reading
5.530 + * ceases. If the character <code>'\r'</code>
5.531 + * is encountered, it is discarded and, if
5.532 + * the following byte converts  to the
5.533 + * character <code>'\n'</code>, then that is
5.534 + * discarded also; reading then ceases. If
5.535 + * end of file is encountered before either
5.536 + * of the characters <code>'\n'</code> and
5.537 + * <code>'\r'</code> is encountered, reading
5.538 + * ceases. Once reading has ceased, a <code>String</code>
5.539 + * is returned that contains all the characters
5.540 + * read and not discarded, taken in order.
5.541 + * Note that every character in this string
5.542 + * will have a value less than <code>\u0100</code>,
5.543 + * that is, <code>(char)256</code>.
5.544 + *
5.545 + * @return the next line of text from the input stream,
5.546 + * or <CODE>null</CODE> if the end of file is
5.547 + * encountered before a byte can be read.
5.548 + * @exception IOException if an I/O error occurs.
5.549 + */
5.550 + String readLine() throws IOException;
5.551 +
5.552 + /**
5.553 + * Reads in a string that has been encoded using a
5.554 + * <a href="#modified-utf-8">modified UTF-8</a>
5.555 + * format.
5.556 + * The general contract of <code>readUTF</code>
5.557 + * is that it reads a representation of a Unicode
5.558 + * character string encoded in modified
5.559 + * UTF-8 format; this string of characters
5.560 + * is then returned as a <code>String</code>.
5.561 + * <p>
5.562 + * First, two bytes are read and used to
5.563 + * construct an unsigned 16-bit integer in
5.564 + * exactly the manner of the <code>readUnsignedShort</code>
5.565 + * method . This integer value is called the
5.566 + * <i>UTF length</i> and specifies the number
5.567 + * of additional bytes to be read. These bytes
5.568 + * are then converted to characters by considering
5.569 + * them in groups. The length of each group
5.570 + * is computed from the value of the first
5.571 + * byte of the group. The byte following a
5.572 + * group, if any, is the first byte of the
5.573 + * next group.
5.574 + * <p>
5.575 + * If the first byte of a group
5.576 + * matches the bit pattern <code>0xxxxxxx</code>
5.577 + * (where <code>x</code> means "may be <code>0</code>
5.578 + * or <code>1</code>"), then the group consists
5.579 + * of just that byte. The byte is zero-extended
5.580 + * to form a character.
5.581 + * <p>
5.582 + * If the first byte
5.583 + * of a group matches the bit pattern <code>110xxxxx</code>,
5.584 + * then the group consists of that byte <code>a</code>
5.585 + * and a second byte <code>b</code>. If there
5.586 + * is no byte <code>b</code> (because byte
5.587 + * <code>a</code> was the last of the bytes
5.588 + * to be read), or if byte <code>b</code> does
5.589 + * not match the bit pattern <code>10xxxxxx</code>,
5.590 + * then a <code>UTFDataFormatException</code>
5.591 + * is thrown. Otherwise, the group is converted
5.592 + * to the character:<p>
5.593 + * <pre><code>(char)(((a& 0x1F) << 6) | (b & 0x3F))
5.594 + * </code></pre>
5.595 + * If the first byte of a group
5.596 + * matches the bit pattern <code>1110xxxx</code>,
5.597 + * then the group consists of that byte <code>a</code>
5.598 + * and two more bytes <code>b</code> and <code>c</code>.
5.599 + * If there is no byte <code>c</code> (because
5.600 + * byte <code>a</code> was one of the last
5.601 + * two of the bytes to be read), or either
5.602 + * byte <code>b</code> or byte <code>c</code>
5.603 + * does not match the bit pattern <code>10xxxxxx</code>,
5.604 + * then a <code>UTFDataFormatException</code>
5.605 + * is thrown. Otherwise, the group is converted
5.606 + * to the character:<p>
5.607 + * <pre><code>
5.608 + * (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
5.609 + * </code></pre>
5.610 + * If the first byte of a group matches the
5.611 + * pattern <code>1111xxxx</code> or the pattern
5.612 + * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
5.613 + * is thrown.
5.614 + * <p>
5.615 + * If end of file is encountered
5.616 + * at any time during this entire process,
5.617 + * then an <code>EOFException</code> is thrown.
5.618 + * <p>
5.619 + * After every group has been converted to
5.620 + * a character by this process, the characters
5.621 + * are gathered, in the same order in which
5.622 + * their corresponding groups were read from
5.623 + * the input stream, to form a <code>String</code>,
5.624 + * which is returned.
5.625 + * <p>
5.626 + * The <code>writeUTF</code>
5.627 + * method of interface <code>DataOutput</code>
5.628 + * may be used to write data that is suitable
5.629 + * for reading by this method.
5.630 + * @return a Unicode string.
5.631 + * @exception EOFException if this stream reaches the end
5.632 + * before reading all the bytes.
5.633 + * @exception IOException if an I/O error occurs.
5.634 + * @exception UTFDataFormatException if the bytes do not represent a
5.635 + * valid modified UTF-8 encoding of a string.
5.636 + */
5.637 + String readUTF() throws IOException;
5.638 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/mini/src/main/java/java/io/DataInputStream.java Wed Jan 23 20:39:23 2013 +0100
6.3 @@ -0,0 +1,704 @@
6.4 +/*
6.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +package java.io;
6.30 +
6.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
6.32 +
6.33 +/**
6.34 + * A data input stream lets an application read primitive Java data
6.35 + * types from an underlying input stream in a machine-independent
6.36 + * way. An application uses a data output stream to write data that
6.37 + * can later be read by a data input stream.
6.38 + * <p>
6.39 + * DataInputStream is not necessarily safe for multithreaded access.
6.40 + * Thread safety is optional and is the responsibility of users of
6.41 + * methods in this class.
6.42 + *
6.43 + * @author Arthur van Hoff
6.44 + * @see java.io.DataOutputStream
6.45 + * @since JDK1.0
6.46 + */
6.47 +public
6.48 +class DataInputStream extends FilterInputStream implements DataInput {
6.49 +
6.50 + /**
6.51 + * Creates a DataInputStream that uses the specified
6.52 + * underlying InputStream.
6.53 + *
6.54 + * @param in the specified input stream
6.55 + */
6.56 + public DataInputStream(InputStream in) {
6.57 + super(in);
6.58 + }
6.59 +
6.60 + /**
6.61 + * working arrays initialized on demand by readUTF
6.62 + */
6.63 + private byte bytearr[] = new byte[80];
6.64 + private char chararr[] = new char[80];
6.65 +
6.66 + /**
6.67 + * Reads some number of bytes from the contained input stream and
6.68 + * stores them into the buffer array <code>b</code>. The number of
6.69 + * bytes actually read is returned as an integer. This method blocks
6.70 + * until input data is available, end of file is detected, or an
6.71 + * exception is thrown.
6.72 + *
6.73 + * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
6.74 + * thrown. If the length of <code>b</code> is zero, then no bytes are
6.75 + * read and <code>0</code> is returned; otherwise, there is an attempt
6.76 + * to read at least one byte. If no byte is available because the
6.77 + * stream is at end of file, the value <code>-1</code> is returned;
6.78 + * otherwise, at least one byte is read and stored into <code>b</code>.
6.79 + *
6.80 + * <p>The first byte read is stored into element <code>b[0]</code>, the
6.81 + * next one into <code>b[1]</code>, and so on. The number of bytes read
6.82 + * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
6.83 + * be the number of bytes actually read; these bytes will be stored in
6.84 + * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
6.85 + * elements <code>b[k]</code> through <code>b[b.length-1]</code>
6.86 + * unaffected.
6.87 + *
6.88 + * <p>The <code>read(b)</code> method has the same effect as:
6.89 + * <blockquote><pre>
6.90 + * read(b, 0, b.length)
6.91 + * </pre></blockquote>
6.92 + *
6.93 + * @param b the buffer into which the data is read.
6.94 + * @return the total number of bytes read into the buffer, or
6.95 + * <code>-1</code> if there is no more data because the end
6.96 + * of the stream has been reached.
6.97 + * @exception IOException if the first byte cannot be read for any reason
6.98 + * other than end of file, the stream has been closed and the underlying
6.99 + * input stream does not support reading after close, or another I/O
6.100 + * error occurs.
6.101 + * @see java.io.FilterInputStream#in
6.102 + * @see java.io.InputStream#read(byte[], int, int)
6.103 + */
6.104 + public final int read(byte b[]) throws IOException {
6.105 + return in.read(b, 0, b.length);
6.106 + }
6.107 +
6.108 + /**
6.109 + * Reads up to <code>len</code> bytes of data from the contained
6.110 + * input stream into an array of bytes. An attempt is made to read
6.111 + * as many as <code>len</code> bytes, but a smaller number may be read,
6.112 + * possibly zero. The number of bytes actually read is returned as an
6.113 + * integer.
6.114 + *
6.115 + * <p> This method blocks until input data is available, end of file is
6.116 + * detected, or an exception is thrown.
6.117 + *
6.118 + * <p> If <code>len</code> is zero, then no bytes are read and
6.119 + * <code>0</code> is returned; otherwise, there is an attempt to read at
6.120 + * least one byte. If no byte is available because the stream is at end of
6.121 + * file, the value <code>-1</code> is returned; otherwise, at least one
6.122 + * byte is read and stored into <code>b</code>.
6.123 + *
6.124 + * <p> The first byte read is stored into element <code>b[off]</code>, the
6.125 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
6.126 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
6.127 + * bytes actually read; these bytes will be stored in elements
6.128 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
6.129 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
6.130 + * <code>b[off+len-1]</code> unaffected.
6.131 + *
6.132 + * <p> In every case, elements <code>b[0]</code> through
6.133 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
6.134 + * <code>b[b.length-1]</code> are unaffected.
6.135 + *
6.136 + * @param b the buffer into which the data is read.
6.137 + * @param off the start offset in the destination array <code>b</code>
6.138 + * @param len the maximum number of bytes read.
6.139 + * @return the total number of bytes read into the buffer, or
6.140 + * <code>-1</code> if there is no more data because the end
6.141 + * of the stream has been reached.
6.142 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
6.143 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
6.144 + * <code>len</code> is negative, or <code>len</code> is greater than
6.145 + * <code>b.length - off</code>
6.146 + * @exception IOException if the first byte cannot be read for any reason
6.147 + * other than end of file, the stream has been closed and the underlying
6.148 + * input stream does not support reading after close, or another I/O
6.149 + * error occurs.
6.150 + * @see java.io.FilterInputStream#in
6.151 + * @see java.io.InputStream#read(byte[], int, int)
6.152 + */
6.153 + public final int read(byte b[], int off, int len) throws IOException {
6.154 + return in.read(b, off, len);
6.155 + }
6.156 +
6.157 + /**
6.158 + * See the general contract of the <code>readFully</code>
6.159 + * method of <code>DataInput</code>.
6.160 + * <p>
6.161 + * Bytes
6.162 + * for this operation are read from the contained
6.163 + * input stream.
6.164 + *
6.165 + * @param b the buffer into which the data is read.
6.166 + * @exception EOFException if this input stream reaches the end before
6.167 + * reading all the bytes.
6.168 + * @exception IOException the stream has been closed and the contained
6.169 + * input stream does not support reading after close, or
6.170 + * another I/O error occurs.
6.171 + * @see java.io.FilterInputStream#in
6.172 + */
6.173 + public final void readFully(byte b[]) throws IOException {
6.174 + readFully(b, 0, b.length);
6.175 + }
6.176 +
6.177 + /**
6.178 + * See the general contract of the <code>readFully</code>
6.179 + * method of <code>DataInput</code>.
6.180 + * <p>
6.181 + * Bytes
6.182 + * for this operation are read from the contained
6.183 + * input stream.
6.184 + *
6.185 + * @param b the buffer into which the data is read.
6.186 + * @param off the start offset of the data.
6.187 + * @param len the number of bytes to read.
6.188 + * @exception EOFException if this input stream reaches the end before
6.189 + * reading all the bytes.
6.190 + * @exception IOException the stream has been closed and the contained
6.191 + * input stream does not support reading after close, or
6.192 + * another I/O error occurs.
6.193 + * @see java.io.FilterInputStream#in
6.194 + */
6.195 + public final void readFully(byte b[], int off, int len) throws IOException {
6.196 + if (len < 0)
6.197 + throw new IndexOutOfBoundsException();
6.198 + int n = 0;
6.199 + while (n < len) {
6.200 + int count = in.read(b, off + n, len - n);
6.201 + if (count < 0)
6.202 + throw new EOFException();
6.203 + n += count;
6.204 + }
6.205 + }
6.206 +
6.207 + /**
6.208 + * See the general contract of the <code>skipBytes</code>
6.209 + * method of <code>DataInput</code>.
6.210 + * <p>
6.211 + * Bytes for this operation are read from the contained
6.212 + * input stream.
6.213 + *
6.214 + * @param n the number of bytes to be skipped.
6.215 + * @return the actual number of bytes skipped.
6.216 + * @exception IOException if the contained input stream does not support
6.217 + * seek, or the stream has been closed and
6.218 + * the contained input stream does not support
6.219 + * reading after close, or another I/O error occurs.
6.220 + */
6.221 + public final int skipBytes(int n) throws IOException {
6.222 + int total = 0;
6.223 + int cur = 0;
6.224 +
6.225 + while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
6.226 + total += cur;
6.227 + }
6.228 +
6.229 + return total;
6.230 + }
6.231 +
6.232 + /**
6.233 + * See the general contract of the <code>readBoolean</code>
6.234 + * method of <code>DataInput</code>.
6.235 + * <p>
6.236 + * Bytes for this operation are read from the contained
6.237 + * input stream.
6.238 + *
6.239 + * @return the <code>boolean</code> value read.
6.240 + * @exception EOFException if this input stream has reached the end.
6.241 + * @exception IOException the stream has been closed and the contained
6.242 + * input stream does not support reading after close, or
6.243 + * another I/O error occurs.
6.244 + * @see java.io.FilterInputStream#in
6.245 + */
6.246 + public final boolean readBoolean() throws IOException {
6.247 + int ch = in.read();
6.248 + if (ch < 0)
6.249 + throw new EOFException();
6.250 + return (ch != 0);
6.251 + }
6.252 +
6.253 + /**
6.254 + * See the general contract of the <code>readByte</code>
6.255 + * method of <code>DataInput</code>.
6.256 + * <p>
6.257 + * Bytes
6.258 + * for this operation are read from the contained
6.259 + * input stream.
6.260 + *
6.261 + * @return the next byte of this input stream as a signed 8-bit
6.262 + * <code>byte</code>.
6.263 + * @exception EOFException if this input stream has reached the end.
6.264 + * @exception IOException the stream has been closed and the contained
6.265 + * input stream does not support reading after close, or
6.266 + * another I/O error occurs.
6.267 + * @see java.io.FilterInputStream#in
6.268 + */
6.269 + public final byte readByte() throws IOException {
6.270 + int ch = in.read();
6.271 + if (ch < 0)
6.272 + throw new EOFException();
6.273 + return (byte)(ch);
6.274 + }
6.275 +
6.276 + /**
6.277 + * See the general contract of the <code>readUnsignedByte</code>
6.278 + * method of <code>DataInput</code>.
6.279 + * <p>
6.280 + * Bytes
6.281 + * for this operation are read from the contained
6.282 + * input stream.
6.283 + *
6.284 + * @return the next byte of this input stream, interpreted as an
6.285 + * unsigned 8-bit number.
6.286 + * @exception EOFException if this input stream has reached the end.
6.287 + * @exception IOException the stream has been closed and the contained
6.288 + * input stream does not support reading after close, or
6.289 + * another I/O error occurs.
6.290 + * @see java.io.FilterInputStream#in
6.291 + */
6.292 + public final int readUnsignedByte() throws IOException {
6.293 + int ch = in.read();
6.294 + if (ch < 0)
6.295 + throw new EOFException();
6.296 + return ch;
6.297 + }
6.298 +
6.299 + /**
6.300 + * See the general contract of the <code>readShort</code>
6.301 + * method of <code>DataInput</code>.
6.302 + * <p>
6.303 + * Bytes
6.304 + * for this operation are read from the contained
6.305 + * input stream.
6.306 + *
6.307 + * @return the next two bytes of this input stream, interpreted as a
6.308 + * signed 16-bit number.
6.309 + * @exception EOFException if this input stream reaches the end before
6.310 + * reading two bytes.
6.311 + * @exception IOException the stream has been closed and the contained
6.312 + * input stream does not support reading after close, or
6.313 + * another I/O error occurs.
6.314 + * @see java.io.FilterInputStream#in
6.315 + */
6.316 + public final short readShort() throws IOException {
6.317 + int ch1 = in.read();
6.318 + int ch2 = in.read();
6.319 + if ((ch1 | ch2) < 0)
6.320 + throw new EOFException();
6.321 + return (short)((ch1 << 8) + (ch2 << 0));
6.322 + }
6.323 +
6.324 + /**
6.325 + * See the general contract of the <code>readUnsignedShort</code>
6.326 + * method of <code>DataInput</code>.
6.327 + * <p>
6.328 + * Bytes
6.329 + * for this operation are read from the contained
6.330 + * input stream.
6.331 + *
6.332 + * @return the next two bytes of this input stream, interpreted as an
6.333 + * unsigned 16-bit integer.
6.334 + * @exception EOFException if this input stream reaches the end before
6.335 + * reading two bytes.
6.336 + * @exception IOException the stream has been closed and the contained
6.337 + * input stream does not support reading after close, or
6.338 + * another I/O error occurs.
6.339 + * @see java.io.FilterInputStream#in
6.340 + */
6.341 + public final int readUnsignedShort() throws IOException {
6.342 + int ch1 = in.read();
6.343 + int ch2 = in.read();
6.344 + if ((ch1 | ch2) < 0)
6.345 + throw new EOFException();
6.346 + return (ch1 << 8) + (ch2 << 0);
6.347 + }
6.348 +
6.349 + /**
6.350 + * See the general contract of the <code>readChar</code>
6.351 + * method of <code>DataInput</code>.
6.352 + * <p>
6.353 + * Bytes
6.354 + * for this operation are read from the contained
6.355 + * input stream.
6.356 + *
6.357 + * @return the next two bytes of this input stream, interpreted as a
6.358 + * <code>char</code>.
6.359 + * @exception EOFException if this input stream reaches the end before
6.360 + * reading two bytes.
6.361 + * @exception IOException the stream has been closed and the contained
6.362 + * input stream does not support reading after close, or
6.363 + * another I/O error occurs.
6.364 + * @see java.io.FilterInputStream#in
6.365 + */
6.366 + public final char readChar() throws IOException {
6.367 + int ch1 = in.read();
6.368 + int ch2 = in.read();
6.369 + if ((ch1 | ch2) < 0)
6.370 + throw new EOFException();
6.371 + return (char)((ch1 << 8) + (ch2 << 0));
6.372 + }
6.373 +
6.374 + /**
6.375 + * See the general contract of the <code>readInt</code>
6.376 + * method of <code>DataInput</code>.
6.377 + * <p>
6.378 + * Bytes
6.379 + * for this operation are read from the contained
6.380 + * input stream.
6.381 + *
6.382 + * @return the next four bytes of this input stream, interpreted as an
6.383 + * <code>int</code>.
6.384 + * @exception EOFException if this input stream reaches the end before
6.385 + * reading four bytes.
6.386 + * @exception IOException the stream has been closed and the contained
6.387 + * input stream does not support reading after close, or
6.388 + * another I/O error occurs.
6.389 + * @see java.io.FilterInputStream#in
6.390 + */
6.391 + public final int readInt() throws IOException {
6.392 + int ch1 = in.read();
6.393 + int ch2 = in.read();
6.394 + int ch3 = in.read();
6.395 + int ch4 = in.read();
6.396 + if ((ch1 | ch2 | ch3 | ch4) < 0)
6.397 + throw new EOFException();
6.398 + return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
6.399 + }
6.400 +
6.401 + private byte readBuffer[] = new byte[8];
6.402 +
6.403 + /**
6.404 + * See the general contract of the <code>readLong</code>
6.405 + * method of <code>DataInput</code>.
6.406 + * <p>
6.407 + * Bytes
6.408 + * for this operation are read from the contained
6.409 + * input stream.
6.410 + *
6.411 + * @return the next eight bytes of this input stream, interpreted as a
6.412 + * <code>long</code>.
6.413 + * @exception EOFException if this input stream reaches the end before
6.414 + * reading eight bytes.
6.415 + * @exception IOException the stream has been closed and the contained
6.416 + * input stream does not support reading after close, or
6.417 + * another I/O error occurs.
6.418 + * @see java.io.FilterInputStream#in
6.419 + */
6.420 + public final long readLong() throws IOException {
6.421 + readFully(readBuffer, 0, 8);
6.422 + return (((long)readBuffer[0] << 56) +
6.423 + ((long)(readBuffer[1] & 255) << 48) +
6.424 + ((long)(readBuffer[2] & 255) << 40) +
6.425 + ((long)(readBuffer[3] & 255) << 32) +
6.426 + ((long)(readBuffer[4] & 255) << 24) +
6.427 + ((readBuffer[5] & 255) << 16) +
6.428 + ((readBuffer[6] & 255) << 8) +
6.429 + ((readBuffer[7] & 255) << 0));
6.430 + }
6.431 +
6.432 + /**
6.433 + * See the general contract of the <code>readFloat</code>
6.434 + * method of <code>DataInput</code>.
6.435 + * <p>
6.436 + * Bytes
6.437 + * for this operation are read from the contained
6.438 + * input stream.
6.439 + *
6.440 + * @return the next four bytes of this input stream, interpreted as a
6.441 + * <code>float</code>.
6.442 + * @exception EOFException if this input stream reaches the end before
6.443 + * reading four bytes.
6.444 + * @exception IOException the stream has been closed and the contained
6.445 + * input stream does not support reading after close, or
6.446 + * another I/O error occurs.
6.447 + * @see java.io.DataInputStream#readInt()
6.448 + * @see java.lang.Float#intBitsToFloat(int)
6.449 + */
6.450 + public final float readFloat() throws IOException {
6.451 + return Float.intBitsToFloat(readInt());
6.452 + }
6.453 +
6.454 + /**
6.455 + * See the general contract of the <code>readDouble</code>
6.456 + * method of <code>DataInput</code>.
6.457 + * <p>
6.458 + * Bytes
6.459 + * for this operation are read from the contained
6.460 + * input stream.
6.461 + *
6.462 + * @return the next eight bytes of this input stream, interpreted as a
6.463 + * <code>double</code>.
6.464 + * @exception EOFException if this input stream reaches the end before
6.465 + * reading eight bytes.
6.466 + * @exception IOException the stream has been closed and the contained
6.467 + * input stream does not support reading after close, or
6.468 + * another I/O error occurs.
6.469 + * @see java.io.DataInputStream#readLong()
6.470 + * @see java.lang.Double#longBitsToDouble(long)
6.471 + */
6.472 + public final double readDouble() throws IOException {
6.473 + int hi = readInt();
6.474 + int low = readInt();
6.475 + return toDouble(hi, low);
6.476 + }
6.477 +
6.478 + @JavaScriptBody(args={ "hi", "low" },
6.479 + body=
6.480 + "if (low == 0) {\n"
6.481 + + " if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
6.482 + + " if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
6.483 + + "}\n"
6.484 + + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
6.485 + + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
6.486 + + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
6.487 + + "var e = (hi >> 20) & 0x7ff;\n"
6.488 + + "var to32 = low >> 0;\n"
6.489 + + "if (e === 0) {\n"
6.490 + + " if (to32 & 0x80000000) {\n"
6.491 + + " hi = hi << 1 + 1; low = low << 1;\n"
6.492 + + " } else {\n"
6.493 + + " hi = hi << 1; low = low << 1;\n"
6.494 + + " }\n"
6.495 + + "} else {\n"
6.496 + + " hi = (hi & 0xfffff) | 0x100000;\n"
6.497 + + "}\n"
6.498 + + "to32 = low >> 0;\n"
6.499 + + "var m = Math.pow(2.0, 32) * hi + to32;\n"
6.500 + + "var r = s * m * Math.pow(2.0, e - 1075);\n"
6.501 + + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
6.502 + + "return r;\n"
6.503 + )
6.504 + private static double toDouble(int hi, int low) {
6.505 + long both = hi;
6.506 + both = (both << 32) & low;
6.507 + return Double.doubleToLongBits(both);
6.508 + }
6.509 +
6.510 + private char lineBuffer[];
6.511 +
6.512 + /**
6.513 + * See the general contract of the <code>readLine</code>
6.514 + * method of <code>DataInput</code>.
6.515 + * <p>
6.516 + * Bytes
6.517 + * for this operation are read from the contained
6.518 + * input stream.
6.519 + *
6.520 + * @deprecated This method does not properly convert bytes to characters.
6.521 + * As of JDK 1.1, the preferred way to read lines of text is via the
6.522 + * <code>BufferedReader.readLine()</code> method. Programs that use the
6.523 + * <code>DataInputStream</code> class to read lines can be converted to use
6.524 + * the <code>BufferedReader</code> class by replacing code of the form:
6.525 + * <blockquote><pre>
6.526 + * DataInputStream d = new DataInputStream(in);
6.527 + * </pre></blockquote>
6.528 + * with:
6.529 + * <blockquote><pre>
6.530 + * BufferedReader d
6.531 + * = new BufferedReader(new InputStreamReader(in));
6.532 + * </pre></blockquote>
6.533 + *
6.534 + * @return the next line of text from this input stream.
6.535 + * @exception IOException if an I/O error occurs.
6.536 + * @see java.io.BufferedReader#readLine()
6.537 + * @see java.io.FilterInputStream#in
6.538 + */
6.539 + @Deprecated
6.540 + public final String readLine() throws IOException {
6.541 + char buf[] = lineBuffer;
6.542 +
6.543 + if (buf == null) {
6.544 + buf = lineBuffer = new char[128];
6.545 + }
6.546 +
6.547 + int room = buf.length;
6.548 + int offset = 0;
6.549 + int c;
6.550 +
6.551 +loop: while (true) {
6.552 + switch (c = in.read()) {
6.553 + case -1:
6.554 + case '\n':
6.555 + break loop;
6.556 +
6.557 + case '\r':
6.558 + int c2 = in.read();
6.559 + if ((c2 != '\n') && (c2 != -1)) {
6.560 + if (!(in instanceof PushbackInputStream)) {
6.561 + this.in = new PushbackInputStream(in);
6.562 + }
6.563 + ((PushbackInputStream)in).unread(c2);
6.564 + }
6.565 + break loop;
6.566 +
6.567 + default:
6.568 + if (--room < 0) {
6.569 + buf = new char[offset + 128];
6.570 + room = buf.length - offset - 1;
6.571 + arraycopy(lineBuffer, 0, buf, 0, offset);
6.572 + lineBuffer = buf;
6.573 + }
6.574 + buf[offset++] = (char) c;
6.575 + break;
6.576 + }
6.577 + }
6.578 + if ((c == -1) && (offset == 0)) {
6.579 + return null;
6.580 + }
6.581 + return String.copyValueOf(buf, 0, offset);
6.582 + }
6.583 +
6.584 + /**
6.585 + * See the general contract of the <code>readUTF</code>
6.586 + * method of <code>DataInput</code>.
6.587 + * <p>
6.588 + * Bytes
6.589 + * for this operation are read from the contained
6.590 + * input stream.
6.591 + *
6.592 + * @return a Unicode string.
6.593 + * @exception EOFException if this input stream reaches the end before
6.594 + * reading all the bytes.
6.595 + * @exception IOException the stream has been closed and the contained
6.596 + * input stream does not support reading after close, or
6.597 + * another I/O error occurs.
6.598 + * @exception UTFDataFormatException if the bytes do not represent a valid
6.599 + * modified UTF-8 encoding of a string.
6.600 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
6.601 + */
6.602 + public final String readUTF() throws IOException {
6.603 + return readUTF(this);
6.604 + }
6.605 +
6.606 + /**
6.607 + * Reads from the
6.608 + * stream <code>in</code> a representation
6.609 + * of a Unicode character string encoded in
6.610 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
6.611 + * this string of characters is then returned as a <code>String</code>.
6.612 + * The details of the modified UTF-8 representation
6.613 + * are exactly the same as for the <code>readUTF</code>
6.614 + * method of <code>DataInput</code>.
6.615 + *
6.616 + * @param in a data input stream.
6.617 + * @return a Unicode string.
6.618 + * @exception EOFException if the input stream reaches the end
6.619 + * before all the bytes.
6.620 + * @exception IOException the stream has been closed and the contained
6.621 + * input stream does not support reading after close, or
6.622 + * another I/O error occurs.
6.623 + * @exception UTFDataFormatException if the bytes do not represent a
6.624 + * valid modified UTF-8 encoding of a Unicode string.
6.625 + * @see java.io.DataInputStream#readUnsignedShort()
6.626 + */
6.627 + public final static String readUTF(DataInput in) throws IOException {
6.628 + int utflen = in.readUnsignedShort();
6.629 + byte[] bytearr = null;
6.630 + char[] chararr = null;
6.631 + if (in instanceof DataInputStream) {
6.632 + DataInputStream dis = (DataInputStream)in;
6.633 + if (dis.bytearr.length < utflen){
6.634 + dis.bytearr = new byte[utflen*2];
6.635 + dis.chararr = new char[utflen*2];
6.636 + }
6.637 + chararr = dis.chararr;
6.638 + bytearr = dis.bytearr;
6.639 + } else {
6.640 + bytearr = new byte[utflen];
6.641 + chararr = new char[utflen];
6.642 + }
6.643 +
6.644 + int c, char2, char3;
6.645 + int count = 0;
6.646 + int chararr_count=0;
6.647 +
6.648 + in.readFully(bytearr, 0, utflen);
6.649 +
6.650 + while (count < utflen) {
6.651 + c = (int) bytearr[count] & 0xff;
6.652 + if (c > 127) break;
6.653 + count++;
6.654 + chararr[chararr_count++]=(char)c;
6.655 + }
6.656 +
6.657 + while (count < utflen) {
6.658 + c = (int) bytearr[count] & 0xff;
6.659 + switch (c >> 4) {
6.660 + case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
6.661 + /* 0xxxxxxx*/
6.662 + count++;
6.663 + chararr[chararr_count++]=(char)c;
6.664 + break;
6.665 + case 12: case 13:
6.666 + /* 110x xxxx 10xx xxxx*/
6.667 + count += 2;
6.668 + if (count > utflen)
6.669 + throw new UTFDataFormatException(
6.670 + "malformed input: partial character at end");
6.671 + char2 = (int) bytearr[count-1];
6.672 + if ((char2 & 0xC0) != 0x80)
6.673 + throw new UTFDataFormatException(
6.674 + "malformed input around byte " + count);
6.675 + chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
6.676 + (char2 & 0x3F));
6.677 + break;
6.678 + case 14:
6.679 + /* 1110 xxxx 10xx xxxx 10xx xxxx */
6.680 + count += 3;
6.681 + if (count > utflen)
6.682 + throw new UTFDataFormatException(
6.683 + "malformed input: partial character at end");
6.684 + char2 = (int) bytearr[count-2];
6.685 + char3 = (int) bytearr[count-1];
6.686 + if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
6.687 + throw new UTFDataFormatException(
6.688 + "malformed input around byte " + (count-1));
6.689 + chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
6.690 + ((char2 & 0x3F) << 6) |
6.691 + ((char3 & 0x3F) << 0));
6.692 + break;
6.693 + default:
6.694 + /* 10xx xxxx, 1111 xxxx */
6.695 + throw new UTFDataFormatException(
6.696 + "malformed input around byte " + count);
6.697 + }
6.698 + }
6.699 + // The number of chars produced may be less than utflen
6.700 + return new String(chararr, 0, chararr_count);
6.701 + }
6.702 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
6.703 + while (count-- > 0) {
6.704 + dst[dstBegin++] = value[srcBegin++];
6.705 + }
6.706 + }
6.707 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/emul/mini/src/main/java/java/io/EOFException.java Wed Jan 23 20:39:23 2013 +0100
7.3 @@ -0,0 +1,65 @@
7.4 +/*
7.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.io;
7.30 +
7.31 +/**
7.32 + * Signals that an end of file or end of stream has been reached
7.33 + * unexpectedly during input.
7.34 + * <p>
7.35 + * This exception is mainly used by data input streams to signal end of
7.36 + * stream. Note that many other input operations return a special value on
7.37 + * end of stream rather than throwing an exception.
7.38 + * <p>
7.39 + *
7.40 + * @author Frank Yellin
7.41 + * @see java.io.DataInputStream
7.42 + * @see java.io.IOException
7.43 + * @since JDK1.0
7.44 + */
7.45 +public
7.46 +class EOFException extends IOException {
7.47 + private static final long serialVersionUID = 6433858223774886977L;
7.48 +
7.49 + /**
7.50 + * Constructs an <code>EOFException</code> with <code>null</code>
7.51 + * as its error detail message.
7.52 + */
7.53 + public EOFException() {
7.54 + super();
7.55 + }
7.56 +
7.57 + /**
7.58 + * Constructs an <code>EOFException</code> with the specified detail
7.59 + * message. The string <code>s</code> may later be retrieved by the
7.60 + * <code>{@link java.lang.Throwable#getMessage}</code> method of class
7.61 + * <code>java.lang.Throwable</code>.
7.62 + *
7.63 + * @param s the detail message.
7.64 + */
7.65 + public EOFException(String s) {
7.66 + super(s);
7.67 + }
7.68 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/emul/mini/src/main/java/java/io/FilterInputStream.java Wed Jan 23 20:39:23 2013 +0100
8.3 @@ -0,0 +1,245 @@
8.4 +/*
8.5 + * Copyright (c) 1994, 2010, 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 +
8.29 +package java.io;
8.30 +
8.31 +/**
8.32 + * A <code>FilterInputStream</code> contains
8.33 + * some other input stream, which it uses as
8.34 + * its basic source of data, possibly transforming
8.35 + * the data along the way or providing additional
8.36 + * functionality. The class <code>FilterInputStream</code>
8.37 + * itself simply overrides all methods of
8.38 + * <code>InputStream</code> with versions that
8.39 + * pass all requests to the contained input
8.40 + * stream. Subclasses of <code>FilterInputStream</code>
8.41 + * may further override some of these methods
8.42 + * and may also provide additional methods
8.43 + * and fields.
8.44 + *
8.45 + * @author Jonathan Payne
8.46 + * @since JDK1.0
8.47 + */
8.48 +public
8.49 +class FilterInputStream extends InputStream {
8.50 + /**
8.51 + * The input stream to be filtered.
8.52 + */
8.53 + protected volatile InputStream in;
8.54 +
8.55 + /**
8.56 + * Creates a <code>FilterInputStream</code>
8.57 + * by assigning the argument <code>in</code>
8.58 + * to the field <code>this.in</code> so as
8.59 + * to remember it for later use.
8.60 + *
8.61 + * @param in the underlying input stream, or <code>null</code> if
8.62 + * this instance is to be created without an underlying stream.
8.63 + */
8.64 + protected FilterInputStream(InputStream in) {
8.65 + this.in = in;
8.66 + }
8.67 +
8.68 + /**
8.69 + * Reads the next byte of data from this input stream. The value
8.70 + * byte is returned as an <code>int</code> in the range
8.71 + * <code>0</code> to <code>255</code>. If no byte is available
8.72 + * because the end of the stream has been reached, the value
8.73 + * <code>-1</code> is returned. This method blocks until input data
8.74 + * is available, the end of the stream is detected, or an exception
8.75 + * is thrown.
8.76 + * <p>
8.77 + * This method
8.78 + * simply performs <code>in.read()</code> and returns the result.
8.79 + *
8.80 + * @return the next byte of data, or <code>-1</code> if the end of the
8.81 + * stream is reached.
8.82 + * @exception IOException if an I/O error occurs.
8.83 + * @see java.io.FilterInputStream#in
8.84 + */
8.85 + public int read() throws IOException {
8.86 + return in.read();
8.87 + }
8.88 +
8.89 + /**
8.90 + * Reads up to <code>byte.length</code> bytes of data from this
8.91 + * input stream into an array of bytes. This method blocks until some
8.92 + * input is available.
8.93 + * <p>
8.94 + * This method simply performs the call
8.95 + * <code>read(b, 0, b.length)</code> and returns
8.96 + * the result. It is important that it does
8.97 + * <i>not</i> do <code>in.read(b)</code> instead;
8.98 + * certain subclasses of <code>FilterInputStream</code>
8.99 + * depend on the implementation strategy actually
8.100 + * used.
8.101 + *
8.102 + * @param b the buffer into which the data is read.
8.103 + * @return the total number of bytes read into the buffer, or
8.104 + * <code>-1</code> if there is no more data because the end of
8.105 + * the stream has been reached.
8.106 + * @exception IOException if an I/O error occurs.
8.107 + * @see java.io.FilterInputStream#read(byte[], int, int)
8.108 + */
8.109 + public int read(byte b[]) throws IOException {
8.110 + return read(b, 0, b.length);
8.111 + }
8.112 +
8.113 + /**
8.114 + * Reads up to <code>len</code> bytes of data from this input stream
8.115 + * into an array of bytes. If <code>len</code> is not zero, the method
8.116 + * blocks until some input is available; otherwise, no
8.117 + * bytes are read and <code>0</code> is returned.
8.118 + * <p>
8.119 + * This method simply performs <code>in.read(b, off, len)</code>
8.120 + * and returns the result.
8.121 + *
8.122 + * @param b the buffer into which the data is read.
8.123 + * @param off the start offset in the destination array <code>b</code>
8.124 + * @param len the maximum number of bytes read.
8.125 + * @return the total number of bytes read into the buffer, or
8.126 + * <code>-1</code> if there is no more data because the end of
8.127 + * the stream has been reached.
8.128 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
8.129 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
8.130 + * <code>len</code> is negative, or <code>len</code> is greater than
8.131 + * <code>b.length - off</code>
8.132 + * @exception IOException if an I/O error occurs.
8.133 + * @see java.io.FilterInputStream#in
8.134 + */
8.135 + public int read(byte b[], int off, int len) throws IOException {
8.136 + return in.read(b, off, len);
8.137 + }
8.138 +
8.139 + /**
8.140 + * Skips over and discards <code>n</code> bytes of data from the
8.141 + * input stream. The <code>skip</code> method may, for a variety of
8.142 + * reasons, end up skipping over some smaller number of bytes,
8.143 + * possibly <code>0</code>. The actual number of bytes skipped is
8.144 + * returned.
8.145 + * <p>
8.146 + * This method simply performs <code>in.skip(n)</code>.
8.147 + *
8.148 + * @param n the number of bytes to be skipped.
8.149 + * @return the actual number of bytes skipped.
8.150 + * @exception IOException if the stream does not support seek,
8.151 + * or if some other I/O error occurs.
8.152 + */
8.153 + public long skip(long n) throws IOException {
8.154 + return in.skip(n);
8.155 + }
8.156 +
8.157 + /**
8.158 + * Returns an estimate of the number of bytes that can be read (or
8.159 + * skipped over) from this input stream without blocking by the next
8.160 + * caller of a method for this input stream. The next caller might be
8.161 + * the same thread or another thread. A single read or skip of this
8.162 + * many bytes will not block, but may read or skip fewer bytes.
8.163 + * <p>
8.164 + * This method returns the result of {@link #in in}.available().
8.165 + *
8.166 + * @return an estimate of the number of bytes that can be read (or skipped
8.167 + * over) from this input stream without blocking.
8.168 + * @exception IOException if an I/O error occurs.
8.169 + */
8.170 + public int available() throws IOException {
8.171 + return in.available();
8.172 + }
8.173 +
8.174 + /**
8.175 + * Closes this input stream and releases any system resources
8.176 + * associated with the stream.
8.177 + * This
8.178 + * method simply performs <code>in.close()</code>.
8.179 + *
8.180 + * @exception IOException if an I/O error occurs.
8.181 + * @see java.io.FilterInputStream#in
8.182 + */
8.183 + public void close() throws IOException {
8.184 + in.close();
8.185 + }
8.186 +
8.187 + /**
8.188 + * Marks the current position in this input stream. A subsequent
8.189 + * call to the <code>reset</code> method repositions this stream at
8.190 + * the last marked position so that subsequent reads re-read the same bytes.
8.191 + * <p>
8.192 + * The <code>readlimit</code> argument tells this input stream to
8.193 + * allow that many bytes to be read before the mark position gets
8.194 + * invalidated.
8.195 + * <p>
8.196 + * This method simply performs <code>in.mark(readlimit)</code>.
8.197 + *
8.198 + * @param readlimit the maximum limit of bytes that can be read before
8.199 + * the mark position becomes invalid.
8.200 + * @see java.io.FilterInputStream#in
8.201 + * @see java.io.FilterInputStream#reset()
8.202 + */
8.203 + public synchronized void mark(int readlimit) {
8.204 + in.mark(readlimit);
8.205 + }
8.206 +
8.207 + /**
8.208 + * Repositions this stream to the position at the time the
8.209 + * <code>mark</code> method was last called on this input stream.
8.210 + * <p>
8.211 + * This method
8.212 + * simply performs <code>in.reset()</code>.
8.213 + * <p>
8.214 + * Stream marks are intended to be used in
8.215 + * situations where you need to read ahead a little to see what's in
8.216 + * the stream. Often this is most easily done by invoking some
8.217 + * general parser. If the stream is of the type handled by the
8.218 + * parse, it just chugs along happily. If the stream is not of
8.219 + * that type, the parser should toss an exception when it fails.
8.220 + * If this happens within readlimit bytes, it allows the outer
8.221 + * code to reset the stream and try another parser.
8.222 + *
8.223 + * @exception IOException if the stream has not been marked or if the
8.224 + * mark has been invalidated.
8.225 + * @see java.io.FilterInputStream#in
8.226 + * @see java.io.FilterInputStream#mark(int)
8.227 + */
8.228 + public synchronized void reset() throws IOException {
8.229 + in.reset();
8.230 + }
8.231 +
8.232 + /**
8.233 + * Tests if this input stream supports the <code>mark</code>
8.234 + * and <code>reset</code> methods.
8.235 + * This method
8.236 + * simply performs <code>in.markSupported()</code>.
8.237 + *
8.238 + * @return <code>true</code> if this stream type supports the
8.239 + * <code>mark</code> and <code>reset</code> method;
8.240 + * <code>false</code> otherwise.
8.241 + * @see java.io.FilterInputStream#in
8.242 + * @see java.io.InputStream#mark(int)
8.243 + * @see java.io.InputStream#reset()
8.244 + */
8.245 + public boolean markSupported() {
8.246 + return in.markSupported();
8.247 + }
8.248 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/emul/mini/src/main/java/java/io/IOException.java Wed Jan 23 20:39:23 2013 +0100
9.3 @@ -0,0 +1,101 @@
9.4 +/*
9.5 + * Copyright (c) 1994, 2006, 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.io;
9.30 +
9.31 +/**
9.32 + * Signals that an I/O exception of some sort has occurred. This
9.33 + * class is the general class of exceptions produced by failed or
9.34 + * interrupted I/O operations.
9.35 + *
9.36 + * @author unascribed
9.37 + * @see java.io.InputStream
9.38 + * @see java.io.OutputStream
9.39 + * @since JDK1.0
9.40 + */
9.41 +public
9.42 +class IOException extends Exception {
9.43 + static final long serialVersionUID = 7818375828146090155L;
9.44 +
9.45 + /**
9.46 + * Constructs an {@code IOException} with {@code null}
9.47 + * as its error detail message.
9.48 + */
9.49 + public IOException() {
9.50 + super();
9.51 + }
9.52 +
9.53 + /**
9.54 + * Constructs an {@code IOException} with the specified detail message.
9.55 + *
9.56 + * @param message
9.57 + * The detail message (which is saved for later retrieval
9.58 + * by the {@link #getMessage()} method)
9.59 + */
9.60 + public IOException(String message) {
9.61 + super(message);
9.62 + }
9.63 +
9.64 + /**
9.65 + * Constructs an {@code IOException} with the specified detail message
9.66 + * and cause.
9.67 + *
9.68 + * <p> Note that the detail message associated with {@code cause} is
9.69 + * <i>not</i> automatically incorporated into this exception's detail
9.70 + * message.
9.71 + *
9.72 + * @param message
9.73 + * The detail message (which is saved for later retrieval
9.74 + * by the {@link #getMessage()} method)
9.75 + *
9.76 + * @param cause
9.77 + * The cause (which is saved for later retrieval by the
9.78 + * {@link #getCause()} method). (A null value is permitted,
9.79 + * and indicates that the cause is nonexistent or unknown.)
9.80 + *
9.81 + * @since 1.6
9.82 + */
9.83 + public IOException(String message, Throwable cause) {
9.84 + super(message, cause);
9.85 + }
9.86 +
9.87 + /**
9.88 + * Constructs an {@code IOException} with the specified cause and a
9.89 + * detail message of {@code (cause==null ? null : cause.toString())}
9.90 + * (which typically contains the class and detail message of {@code cause}).
9.91 + * This constructor is useful for IO exceptions that are little more
9.92 + * than wrappers for other throwables.
9.93 + *
9.94 + * @param cause
9.95 + * The cause (which is saved for later retrieval by the
9.96 + * {@link #getCause()} method). (A null value is permitted,
9.97 + * and indicates that the cause is nonexistent or unknown.)
9.98 + *
9.99 + * @since 1.6
9.100 + */
9.101 + public IOException(Throwable cause) {
9.102 + super(cause);
9.103 + }
9.104 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/emul/mini/src/main/java/java/io/InputStream.java Wed Jan 23 20:39:23 2013 +0100
10.3 @@ -0,0 +1,370 @@
10.4 +/*
10.5 + * Copyright (c) 1994, 2006, 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.io;
10.30 +
10.31 +/**
10.32 + * This abstract class is the superclass of all classes representing
10.33 + * an input stream of bytes.
10.34 + *
10.35 + * <p> Applications that need to define a subclass of <code>InputStream</code>
10.36 + * must always provide a method that returns the next byte of input.
10.37 + *
10.38 + * @author Arthur van Hoff
10.39 + * @see java.io.BufferedInputStream
10.40 + * @see java.io.ByteArrayInputStream
10.41 + * @see java.io.DataInputStream
10.42 + * @see java.io.FilterInputStream
10.43 + * @see java.io.InputStream#read()
10.44 + * @see java.io.OutputStream
10.45 + * @see java.io.PushbackInputStream
10.46 + * @since JDK1.0
10.47 + */
10.48 +public abstract class InputStream implements Closeable {
10.49 +
10.50 + // SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
10.51 + private static final int SKIP_BUFFER_SIZE = 2048;
10.52 + // skipBuffer is initialized in skip(long), if needed.
10.53 + private static byte[] skipBuffer;
10.54 +
10.55 + /**
10.56 + * Reads the next byte of data from the input stream. The value byte is
10.57 + * returned as an <code>int</code> in the range <code>0</code> to
10.58 + * <code>255</code>. If no byte is available because the end of the stream
10.59 + * has been reached, the value <code>-1</code> is returned. This method
10.60 + * blocks until input data is available, the end of the stream is detected,
10.61 + * or an exception is thrown.
10.62 + *
10.63 + * <p> A subclass must provide an implementation of this method.
10.64 + *
10.65 + * @return the next byte of data, or <code>-1</code> if the end of the
10.66 + * stream is reached.
10.67 + * @exception IOException if an I/O error occurs.
10.68 + */
10.69 + public abstract int read() throws IOException;
10.70 +
10.71 + /**
10.72 + * Reads some number of bytes from the input stream and stores them into
10.73 + * the buffer array <code>b</code>. The number of bytes actually read is
10.74 + * returned as an integer. This method blocks until input data is
10.75 + * available, end of file is detected, or an exception is thrown.
10.76 + *
10.77 + * <p> If the length of <code>b</code> is zero, then no bytes are read and
10.78 + * <code>0</code> is returned; otherwise, there is an attempt to read at
10.79 + * least one byte. If no byte is available because the stream is at the
10.80 + * end of the file, the value <code>-1</code> is returned; otherwise, at
10.81 + * least one byte is read and stored into <code>b</code>.
10.82 + *
10.83 + * <p> The first byte read is stored into element <code>b[0]</code>, the
10.84 + * next one into <code>b[1]</code>, and so on. The number of bytes read is,
10.85 + * at most, equal to the length of <code>b</code>. Let <i>k</i> be the
10.86 + * number of bytes actually read; these bytes will be stored in elements
10.87 + * <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
10.88 + * leaving elements <code>b[</code><i>k</i><code>]</code> through
10.89 + * <code>b[b.length-1]</code> unaffected.
10.90 + *
10.91 + * <p> The <code>read(b)</code> method for class <code>InputStream</code>
10.92 + * has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
10.93 + *
10.94 + * @param b the buffer into which the data is read.
10.95 + * @return the total number of bytes read into the buffer, or
10.96 + * <code>-1</code> if there is no more data because the end of
10.97 + * the stream has been reached.
10.98 + * @exception IOException If the first byte cannot be read for any reason
10.99 + * other than the end of the file, if the input stream has been closed, or
10.100 + * if some other I/O error occurs.
10.101 + * @exception NullPointerException if <code>b</code> is <code>null</code>.
10.102 + * @see java.io.InputStream#read(byte[], int, int)
10.103 + */
10.104 + public int read(byte b[]) throws IOException {
10.105 + return read(b, 0, b.length);
10.106 + }
10.107 +
10.108 + /**
10.109 + * Reads up to <code>len</code> bytes of data from the input stream into
10.110 + * an array of bytes. An attempt is made to read as many as
10.111 + * <code>len</code> bytes, but a smaller number may be read.
10.112 + * The number of bytes actually read is returned as an integer.
10.113 + *
10.114 + * <p> This method blocks until input data is available, end of file is
10.115 + * detected, or an exception is thrown.
10.116 + *
10.117 + * <p> If <code>len</code> is zero, then no bytes are read and
10.118 + * <code>0</code> is returned; otherwise, there is an attempt to read at
10.119 + * least one byte. If no byte is available because the stream is at end of
10.120 + * file, the value <code>-1</code> is returned; otherwise, at least one
10.121 + * byte is read and stored into <code>b</code>.
10.122 + *
10.123 + * <p> The first byte read is stored into element <code>b[off]</code>, the
10.124 + * next one into <code>b[off+1]</code>, and so on. The number of bytes read
10.125 + * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
10.126 + * bytes actually read; these bytes will be stored in elements
10.127 + * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
10.128 + * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
10.129 + * <code>b[off+len-1]</code> unaffected.
10.130 + *
10.131 + * <p> In every case, elements <code>b[0]</code> through
10.132 + * <code>b[off]</code> and elements <code>b[off+len]</code> through
10.133 + * <code>b[b.length-1]</code> are unaffected.
10.134 + *
10.135 + * <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
10.136 + * for class <code>InputStream</code> simply calls the method
10.137 + * <code>read()</code> repeatedly. If the first such call results in an
10.138 + * <code>IOException</code>, that exception is returned from the call to
10.139 + * the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
10.140 + * any subsequent call to <code>read()</code> results in a
10.141 + * <code>IOException</code>, the exception is caught and treated as if it
10.142 + * were end of file; the bytes read up to that point are stored into
10.143 + * <code>b</code> and the number of bytes read before the exception
10.144 + * occurred is returned. The default implementation of this method blocks
10.145 + * until the requested amount of input data <code>len</code> has been read,
10.146 + * end of file is detected, or an exception is thrown. Subclasses are encouraged
10.147 + * to provide a more efficient implementation of this method.
10.148 + *
10.149 + * @param b the buffer into which the data is read.
10.150 + * @param off the start offset in array <code>b</code>
10.151 + * at which the data is written.
10.152 + * @param len the maximum number of bytes to read.
10.153 + * @return the total number of bytes read into the buffer, or
10.154 + * <code>-1</code> if there is no more data because the end of
10.155 + * the stream has been reached.
10.156 + * @exception IOException If the first byte cannot be read for any reason
10.157 + * other than end of file, or if the input stream has been closed, or if
10.158 + * some other I/O error occurs.
10.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
10.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
10.161 + * <code>len</code> is negative, or <code>len</code> is greater than
10.162 + * <code>b.length - off</code>
10.163 + * @see java.io.InputStream#read()
10.164 + */
10.165 + public int read(byte b[], int off, int len) throws IOException {
10.166 + if (b == null) {
10.167 + throw new NullPointerException();
10.168 + } else if (off < 0 || len < 0 || len > b.length - off) {
10.169 + throw new IndexOutOfBoundsException();
10.170 + } else if (len == 0) {
10.171 + return 0;
10.172 + }
10.173 +
10.174 + int c = read();
10.175 + if (c == -1) {
10.176 + return -1;
10.177 + }
10.178 + b[off] = (byte)c;
10.179 +
10.180 + int i = 1;
10.181 + try {
10.182 + for (; i < len ; i++) {
10.183 + c = read();
10.184 + if (c == -1) {
10.185 + break;
10.186 + }
10.187 + b[off + i] = (byte)c;
10.188 + }
10.189 + } catch (IOException ee) {
10.190 + }
10.191 + return i;
10.192 + }
10.193 +
10.194 + /**
10.195 + * Skips over and discards <code>n</code> bytes of data from this input
10.196 + * stream. The <code>skip</code> method may, for a variety of reasons, end
10.197 + * up skipping over some smaller number of bytes, possibly <code>0</code>.
10.198 + * This may result from any of a number of conditions; reaching end of file
10.199 + * before <code>n</code> bytes have been skipped is only one possibility.
10.200 + * The actual number of bytes skipped is returned. If <code>n</code> is
10.201 + * negative, no bytes are skipped.
10.202 + *
10.203 + * <p> The <code>skip</code> method of this class creates a
10.204 + * byte array and then repeatedly reads into it until <code>n</code> bytes
10.205 + * have been read or the end of the stream has been reached. Subclasses are
10.206 + * encouraged to provide a more efficient implementation of this method.
10.207 + * For instance, the implementation may depend on the ability to seek.
10.208 + *
10.209 + * @param n the number of bytes to be skipped.
10.210 + * @return the actual number of bytes skipped.
10.211 + * @exception IOException if the stream does not support seek,
10.212 + * or if some other I/O error occurs.
10.213 + */
10.214 + public long skip(long n) throws IOException {
10.215 +
10.216 + long remaining = n;
10.217 + int nr;
10.218 + if (skipBuffer == null)
10.219 + skipBuffer = new byte[SKIP_BUFFER_SIZE];
10.220 +
10.221 + byte[] localSkipBuffer = skipBuffer;
10.222 +
10.223 + if (n <= 0) {
10.224 + return 0;
10.225 + }
10.226 +
10.227 + while (remaining > 0) {
10.228 + nr = read(localSkipBuffer, 0,
10.229 + (int) Math.min(SKIP_BUFFER_SIZE, remaining));
10.230 + if (nr < 0) {
10.231 + break;
10.232 + }
10.233 + remaining -= nr;
10.234 + }
10.235 +
10.236 + return n - remaining;
10.237 + }
10.238 +
10.239 + /**
10.240 + * Returns an estimate of the number of bytes that can be read (or
10.241 + * skipped over) from this input stream without blocking by the next
10.242 + * invocation of a method for this input stream. The next invocation
10.243 + * might be the same thread or another thread. A single read or skip of this
10.244 + * many bytes will not block, but may read or skip fewer bytes.
10.245 + *
10.246 + * <p> Note that while some implementations of {@code InputStream} will return
10.247 + * the total number of bytes in the stream, many will not. It is
10.248 + * never correct to use the return value of this method to allocate
10.249 + * a buffer intended to hold all data in this stream.
10.250 + *
10.251 + * <p> A subclass' implementation of this method may choose to throw an
10.252 + * {@link IOException} if this input stream has been closed by
10.253 + * invoking the {@link #close()} method.
10.254 + *
10.255 + * <p> The {@code available} method for class {@code InputStream} always
10.256 + * returns {@code 0}.
10.257 + *
10.258 + * <p> This method should be overridden by subclasses.
10.259 + *
10.260 + * @return an estimate of the number of bytes that can be read (or skipped
10.261 + * over) from this input stream without blocking or {@code 0} when
10.262 + * it reaches the end of the input stream.
10.263 + * @exception IOException if an I/O error occurs.
10.264 + */
10.265 + public int available() throws IOException {
10.266 + return 0;
10.267 + }
10.268 +
10.269 + /**
10.270 + * Closes this input stream and releases any system resources associated
10.271 + * with the stream.
10.272 + *
10.273 + * <p> The <code>close</code> method of <code>InputStream</code> does
10.274 + * nothing.
10.275 + *
10.276 + * @exception IOException if an I/O error occurs.
10.277 + */
10.278 + public void close() throws IOException {}
10.279 +
10.280 + /**
10.281 + * Marks the current position in this input stream. A subsequent call to
10.282 + * the <code>reset</code> method repositions this stream at the last marked
10.283 + * position so that subsequent reads re-read the same bytes.
10.284 + *
10.285 + * <p> The <code>readlimit</code> arguments tells this input stream to
10.286 + * allow that many bytes to be read before the mark position gets
10.287 + * invalidated.
10.288 + *
10.289 + * <p> The general contract of <code>mark</code> is that, if the method
10.290 + * <code>markSupported</code> returns <code>true</code>, the stream somehow
10.291 + * remembers all the bytes read after the call to <code>mark</code> and
10.292 + * stands ready to supply those same bytes again if and whenever the method
10.293 + * <code>reset</code> is called. However, the stream is not required to
10.294 + * remember any data at all if more than <code>readlimit</code> bytes are
10.295 + * read from the stream before <code>reset</code> is called.
10.296 + *
10.297 + * <p> Marking a closed stream should not have any effect on the stream.
10.298 + *
10.299 + * <p> The <code>mark</code> method of <code>InputStream</code> does
10.300 + * nothing.
10.301 + *
10.302 + * @param readlimit the maximum limit of bytes that can be read before
10.303 + * the mark position becomes invalid.
10.304 + * @see java.io.InputStream#reset()
10.305 + */
10.306 + public synchronized void mark(int readlimit) {}
10.307 +
10.308 + /**
10.309 + * Repositions this stream to the position at the time the
10.310 + * <code>mark</code> method was last called on this input stream.
10.311 + *
10.312 + * <p> The general contract of <code>reset</code> is:
10.313 + *
10.314 + * <p><ul>
10.315 + *
10.316 + * <li> If the method <code>markSupported</code> returns
10.317 + * <code>true</code>, then:
10.318 + *
10.319 + * <ul><li> If the method <code>mark</code> has not been called since
10.320 + * the stream was created, or the number of bytes read from the stream
10.321 + * since <code>mark</code> was last called is larger than the argument
10.322 + * to <code>mark</code> at that last call, then an
10.323 + * <code>IOException</code> might be thrown.
10.324 + *
10.325 + * <li> If such an <code>IOException</code> is not thrown, then the
10.326 + * stream is reset to a state such that all the bytes read since the
10.327 + * most recent call to <code>mark</code> (or since the start of the
10.328 + * file, if <code>mark</code> has not been called) will be resupplied
10.329 + * to subsequent callers of the <code>read</code> method, followed by
10.330 + * any bytes that otherwise would have been the next input data as of
10.331 + * the time of the call to <code>reset</code>. </ul>
10.332 + *
10.333 + * <li> If the method <code>markSupported</code> returns
10.334 + * <code>false</code>, then:
10.335 + *
10.336 + * <ul><li> The call to <code>reset</code> may throw an
10.337 + * <code>IOException</code>.
10.338 + *
10.339 + * <li> If an <code>IOException</code> is not thrown, then the stream
10.340 + * is reset to a fixed state that depends on the particular type of the
10.341 + * input stream and how it was created. The bytes that will be supplied
10.342 + * to subsequent callers of the <code>read</code> method depend on the
10.343 + * particular type of the input stream. </ul></ul>
10.344 + *
10.345 + * <p>The method <code>reset</code> for class <code>InputStream</code>
10.346 + * does nothing except throw an <code>IOException</code>.
10.347 + *
10.348 + * @exception IOException if this stream has not been marked or if the
10.349 + * mark has been invalidated.
10.350 + * @see java.io.InputStream#mark(int)
10.351 + * @see java.io.IOException
10.352 + */
10.353 + public synchronized void reset() throws IOException {
10.354 + throw new IOException("mark/reset not supported");
10.355 + }
10.356 +
10.357 + /**
10.358 + * Tests if this input stream supports the <code>mark</code> and
10.359 + * <code>reset</code> methods. Whether or not <code>mark</code> and
10.360 + * <code>reset</code> are supported is an invariant property of a
10.361 + * particular input stream instance. The <code>markSupported</code> method
10.362 + * of <code>InputStream</code> returns <code>false</code>.
10.363 + *
10.364 + * @return <code>true</code> if this stream instance supports the mark
10.365 + * and reset methods; <code>false</code> otherwise.
10.366 + * @see java.io.InputStream#mark(int)
10.367 + * @see java.io.InputStream#reset()
10.368 + */
10.369 + public boolean markSupported() {
10.370 + return false;
10.371 + }
10.372 +
10.373 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/emul/mini/src/main/java/java/io/PushbackInputStream.java Wed Jan 23 20:39:23 2013 +0100
11.3 @@ -0,0 +1,388 @@
11.4 +/*
11.5 + * Copyright (c) 1994, 2011, 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.io;
11.30 +
11.31 +/**
11.32 + * A <code>PushbackInputStream</code> adds
11.33 + * functionality to another input stream, namely
11.34 + * the ability to "push back" or "unread"
11.35 + * one byte. This is useful in situations where
11.36 + * it is convenient for a fragment of code
11.37 + * to read an indefinite number of data bytes
11.38 + * that are delimited by a particular byte
11.39 + * value; after reading the terminating byte,
11.40 + * the code fragment can "unread" it, so that
11.41 + * the next read operation on the input stream
11.42 + * will reread the byte that was pushed back.
11.43 + * For example, bytes representing the characters
11.44 + * constituting an identifier might be terminated
11.45 + * by a byte representing an operator character;
11.46 + * a method whose job is to read just an identifier
11.47 + * can read until it sees the operator and
11.48 + * then push the operator back to be re-read.
11.49 + *
11.50 + * @author David Connelly
11.51 + * @author Jonathan Payne
11.52 + * @since JDK1.0
11.53 + */
11.54 +public
11.55 +class PushbackInputStream extends FilterInputStream {
11.56 + /**
11.57 + * The pushback buffer.
11.58 + * @since JDK1.1
11.59 + */
11.60 + protected byte[] buf;
11.61 +
11.62 + /**
11.63 + * The position within the pushback buffer from which the next byte will
11.64 + * be read. When the buffer is empty, <code>pos</code> is equal to
11.65 + * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
11.66 + * equal to zero.
11.67 + *
11.68 + * @since JDK1.1
11.69 + */
11.70 + protected int pos;
11.71 +
11.72 + /**
11.73 + * Check to make sure that this stream has not been closed
11.74 + */
11.75 + private void ensureOpen() throws IOException {
11.76 + if (in == null)
11.77 + throw new IOException("Stream closed");
11.78 + }
11.79 +
11.80 + /**
11.81 + * Creates a <code>PushbackInputStream</code>
11.82 + * with a pushback buffer of the specified <code>size</code>,
11.83 + * and saves its argument, the input stream
11.84 + * <code>in</code>, for later use. Initially,
11.85 + * there is no pushed-back byte (the field
11.86 + * <code>pushBack</code> is initialized to
11.87 + * <code>-1</code>).
11.88 + *
11.89 + * @param in the input stream from which bytes will be read.
11.90 + * @param size the size of the pushback buffer.
11.91 + * @exception IllegalArgumentException if size is <= 0
11.92 + * @since JDK1.1
11.93 + */
11.94 + public PushbackInputStream(InputStream in, int size) {
11.95 + super(in);
11.96 + if (size <= 0) {
11.97 + throw new IllegalArgumentException("size <= 0");
11.98 + }
11.99 + this.buf = new byte[size];
11.100 + this.pos = size;
11.101 + }
11.102 +
11.103 + /**
11.104 + * Creates a <code>PushbackInputStream</code>
11.105 + * and saves its argument, the input stream
11.106 + * <code>in</code>, for later use. Initially,
11.107 + * there is no pushed-back byte (the field
11.108 + * <code>pushBack</code> is initialized to
11.109 + * <code>-1</code>).
11.110 + *
11.111 + * @param in the input stream from which bytes will be read.
11.112 + */
11.113 + public PushbackInputStream(InputStream in) {
11.114 + this(in, 1);
11.115 + }
11.116 +
11.117 + /**
11.118 + * Reads the next byte of data from this input stream. The value
11.119 + * byte is returned as an <code>int</code> in the range
11.120 + * <code>0</code> to <code>255</code>. If no byte is available
11.121 + * because the end of the stream has been reached, the value
11.122 + * <code>-1</code> is returned. This method blocks until input data
11.123 + * is available, the end of the stream is detected, or an exception
11.124 + * is thrown.
11.125 + *
11.126 + * <p> This method returns the most recently pushed-back byte, if there is
11.127 + * one, and otherwise calls the <code>read</code> method of its underlying
11.128 + * input stream and returns whatever value that method returns.
11.129 + *
11.130 + * @return the next byte of data, or <code>-1</code> if the end of the
11.131 + * stream has been reached.
11.132 + * @exception IOException if this input stream has been closed by
11.133 + * invoking its {@link #close()} method,
11.134 + * or an I/O error occurs.
11.135 + * @see java.io.InputStream#read()
11.136 + */
11.137 + public int read() throws IOException {
11.138 + ensureOpen();
11.139 + if (pos < buf.length) {
11.140 + return buf[pos++] & 0xff;
11.141 + }
11.142 + return super.read();
11.143 + }
11.144 +
11.145 + /**
11.146 + * Reads up to <code>len</code> bytes of data from this input stream into
11.147 + * an array of bytes. This method first reads any pushed-back bytes; after
11.148 + * that, if fewer than <code>len</code> bytes have been read then it
11.149 + * reads from the underlying input stream. If <code>len</code> is not zero, the method
11.150 + * blocks until at least 1 byte of input is available; otherwise, no
11.151 + * bytes are read and <code>0</code> is returned.
11.152 + *
11.153 + * @param b the buffer into which the data is read.
11.154 + * @param off the start offset in the destination array <code>b</code>
11.155 + * @param len the maximum number of bytes read.
11.156 + * @return the total number of bytes read into the buffer, or
11.157 + * <code>-1</code> if there is no more data because the end of
11.158 + * the stream has been reached.
11.159 + * @exception NullPointerException If <code>b</code> is <code>null</code>.
11.160 + * @exception IndexOutOfBoundsException If <code>off</code> is negative,
11.161 + * <code>len</code> is negative, or <code>len</code> is greater than
11.162 + * <code>b.length - off</code>
11.163 + * @exception IOException if this input stream has been closed by
11.164 + * invoking its {@link #close()} method,
11.165 + * or an I/O error occurs.
11.166 + * @see java.io.InputStream#read(byte[], int, int)
11.167 + */
11.168 + public int read(byte[] b, int off, int len) throws IOException {
11.169 + ensureOpen();
11.170 + if (b == null) {
11.171 + throw new NullPointerException();
11.172 + } else if (off < 0 || len < 0 || len > b.length - off) {
11.173 + throw new IndexOutOfBoundsException();
11.174 + } else if (len == 0) {
11.175 + return 0;
11.176 + }
11.177 +
11.178 + int avail = buf.length - pos;
11.179 + if (avail > 0) {
11.180 + if (len < avail) {
11.181 + avail = len;
11.182 + }
11.183 + arraycopy(buf, pos, b, off, avail);
11.184 + pos += avail;
11.185 + off += avail;
11.186 + len -= avail;
11.187 + }
11.188 + if (len > 0) {
11.189 + len = super.read(b, off, len);
11.190 + if (len == -1) {
11.191 + return avail == 0 ? -1 : avail;
11.192 + }
11.193 + return avail + len;
11.194 + }
11.195 + return avail;
11.196 + }
11.197 +
11.198 + /**
11.199 + * Pushes back a byte by copying it to the front of the pushback buffer.
11.200 + * After this method returns, the next byte to be read will have the value
11.201 + * <code>(byte)b</code>.
11.202 + *
11.203 + * @param b the <code>int</code> value whose low-order
11.204 + * byte is to be pushed back.
11.205 + * @exception IOException If there is not enough room in the pushback
11.206 + * buffer for the byte, or this input stream has been closed by
11.207 + * invoking its {@link #close()} method.
11.208 + */
11.209 + public void unread(int b) throws IOException {
11.210 + ensureOpen();
11.211 + if (pos == 0) {
11.212 + throw new IOException("Push back buffer is full");
11.213 + }
11.214 + buf[--pos] = (byte)b;
11.215 + }
11.216 +
11.217 + /**
11.218 + * Pushes back a portion of an array of bytes by copying it to the front
11.219 + * of the pushback buffer. After this method returns, the next byte to be
11.220 + * read will have the value <code>b[off]</code>, the byte after that will
11.221 + * have the value <code>b[off+1]</code>, and so forth.
11.222 + *
11.223 + * @param b the byte array to push back.
11.224 + * @param off the start offset of the data.
11.225 + * @param len the number of bytes to push back.
11.226 + * @exception IOException If there is not enough room in the pushback
11.227 + * buffer for the specified number of bytes,
11.228 + * or this input stream has been closed by
11.229 + * invoking its {@link #close()} method.
11.230 + * @since JDK1.1
11.231 + */
11.232 + public void unread(byte[] b, int off, int len) throws IOException {
11.233 + ensureOpen();
11.234 + if (len > pos) {
11.235 + throw new IOException("Push back buffer is full");
11.236 + }
11.237 + pos -= len;
11.238 + arraycopy(b, off, buf, pos, len);
11.239 + }
11.240 +
11.241 + /**
11.242 + * Pushes back an array of bytes by copying it to the front of the
11.243 + * pushback buffer. After this method returns, the next byte to be read
11.244 + * will have the value <code>b[0]</code>, the byte after that will have the
11.245 + * value <code>b[1]</code>, and so forth.
11.246 + *
11.247 + * @param b the byte array to push back
11.248 + * @exception IOException If there is not enough room in the pushback
11.249 + * buffer for the specified number of bytes,
11.250 + * or this input stream has been closed by
11.251 + * invoking its {@link #close()} method.
11.252 + * @since JDK1.1
11.253 + */
11.254 + public void unread(byte[] b) throws IOException {
11.255 + unread(b, 0, b.length);
11.256 + }
11.257 +
11.258 + /**
11.259 + * Returns an estimate of the number of bytes that can be read (or
11.260 + * skipped over) from this input stream without blocking by the next
11.261 + * invocation of a method for this input stream. The next invocation might be
11.262 + * the same thread or another thread. A single read or skip of this
11.263 + * many bytes will not block, but may read or skip fewer bytes.
11.264 + *
11.265 + * <p> The method returns the sum of the number of bytes that have been
11.266 + * pushed back and the value returned by {@link
11.267 + * java.io.FilterInputStream#available available}.
11.268 + *
11.269 + * @return the number of bytes that can be read (or skipped over) from
11.270 + * the input stream without blocking.
11.271 + * @exception IOException if this input stream has been closed by
11.272 + * invoking its {@link #close()} method,
11.273 + * or an I/O error occurs.
11.274 + * @see java.io.FilterInputStream#in
11.275 + * @see java.io.InputStream#available()
11.276 + */
11.277 + public int available() throws IOException {
11.278 + ensureOpen();
11.279 + int n = buf.length - pos;
11.280 + int avail = super.available();
11.281 + return n > (Integer.MAX_VALUE - avail)
11.282 + ? Integer.MAX_VALUE
11.283 + : n + avail;
11.284 + }
11.285 +
11.286 + /**
11.287 + * Skips over and discards <code>n</code> bytes of data from this
11.288 + * input stream. The <code>skip</code> method may, for a variety of
11.289 + * reasons, end up skipping over some smaller number of bytes,
11.290 + * possibly zero. If <code>n</code> is negative, no bytes are skipped.
11.291 + *
11.292 + * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
11.293 + * first skips over the bytes in the pushback buffer, if any. It then
11.294 + * calls the <code>skip</code> method of the underlying input stream if
11.295 + * more bytes need to be skipped. The actual number of bytes skipped
11.296 + * is returned.
11.297 + *
11.298 + * @param n {@inheritDoc}
11.299 + * @return {@inheritDoc}
11.300 + * @exception IOException if the stream does not support seek,
11.301 + * or the stream has been closed by
11.302 + * invoking its {@link #close()} method,
11.303 + * or an I/O error occurs.
11.304 + * @see java.io.FilterInputStream#in
11.305 + * @see java.io.InputStream#skip(long n)
11.306 + * @since 1.2
11.307 + */
11.308 + public long skip(long n) throws IOException {
11.309 + ensureOpen();
11.310 + if (n <= 0) {
11.311 + return 0;
11.312 + }
11.313 +
11.314 + long pskip = buf.length - pos;
11.315 + if (pskip > 0) {
11.316 + if (n < pskip) {
11.317 + pskip = n;
11.318 + }
11.319 + pos += pskip;
11.320 + n -= pskip;
11.321 + }
11.322 + if (n > 0) {
11.323 + pskip += super.skip(n);
11.324 + }
11.325 + return pskip;
11.326 + }
11.327 +
11.328 + /**
11.329 + * Tests if this input stream supports the <code>mark</code> and
11.330 + * <code>reset</code> methods, which it does not.
11.331 + *
11.332 + * @return <code>false</code>, since this class does not support the
11.333 + * <code>mark</code> and <code>reset</code> methods.
11.334 + * @see java.io.InputStream#mark(int)
11.335 + * @see java.io.InputStream#reset()
11.336 + */
11.337 + public boolean markSupported() {
11.338 + return false;
11.339 + }
11.340 +
11.341 + /**
11.342 + * Marks the current position in this input stream.
11.343 + *
11.344 + * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
11.345 + * does nothing.
11.346 + *
11.347 + * @param readlimit the maximum limit of bytes that can be read before
11.348 + * the mark position becomes invalid.
11.349 + * @see java.io.InputStream#reset()
11.350 + */
11.351 + public synchronized void mark(int readlimit) {
11.352 + }
11.353 +
11.354 + /**
11.355 + * Repositions this stream to the position at the time the
11.356 + * <code>mark</code> method was last called on this input stream.
11.357 + *
11.358 + * <p> The method <code>reset</code> for class
11.359 + * <code>PushbackInputStream</code> does nothing except throw an
11.360 + * <code>IOException</code>.
11.361 + *
11.362 + * @exception IOException if this method is invoked.
11.363 + * @see java.io.InputStream#mark(int)
11.364 + * @see java.io.IOException
11.365 + */
11.366 + public synchronized void reset() throws IOException {
11.367 + throw new IOException("mark/reset not supported");
11.368 + }
11.369 +
11.370 + /**
11.371 + * Closes this input stream and releases any system resources
11.372 + * associated with the stream.
11.373 + * Once the stream has been closed, further read(), unread(),
11.374 + * available(), reset(), or skip() invocations will throw an IOException.
11.375 + * Closing a previously closed stream has no effect.
11.376 + *
11.377 + * @exception IOException if an I/O error occurs.
11.378 + */
11.379 + public synchronized void close() throws IOException {
11.380 + if (in == null)
11.381 + return;
11.382 + in.close();
11.383 + in = null;
11.384 + buf = null;
11.385 + }
11.386 + static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) {
11.387 + while (count-- > 0) {
11.388 + dst[dstBegin++] = value[srcBegin++];
11.389 + }
11.390 + }
11.391 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/emul/mini/src/main/java/java/io/Serializable.java Wed Jan 23 20:39:23 2013 +0100
12.3 @@ -0,0 +1,170 @@
12.4 +/*
12.5 + * Copyright (c) 1996, 2005, 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.io;
12.30 +
12.31 +/**
12.32 + * Serializability of a class is enabled by the class implementing the
12.33 + * java.io.Serializable interface. Classes that do not implement this
12.34 + * interface will not have any of their state serialized or
12.35 + * deserialized. All subtypes of a serializable class are themselves
12.36 + * serializable. The serialization interface has no methods or fields
12.37 + * and serves only to identify the semantics of being serializable. <p>
12.38 + *
12.39 + * To allow subtypes of non-serializable classes to be serialized, the
12.40 + * subtype may assume responsibility for saving and restoring the
12.41 + * state of the supertype's public, protected, and (if accessible)
12.42 + * package fields. The subtype may assume this responsibility only if
12.43 + * the class it extends has an accessible no-arg constructor to
12.44 + * initialize the class's state. It is an error to declare a class
12.45 + * Serializable if this is not the case. The error will be detected at
12.46 + * runtime. <p>
12.47 + *
12.48 + * During deserialization, the fields of non-serializable classes will
12.49 + * be initialized using the public or protected no-arg constructor of
12.50 + * the class. A no-arg constructor must be accessible to the subclass
12.51 + * that is serializable. The fields of serializable subclasses will
12.52 + * be restored from the stream. <p>
12.53 + *
12.54 + * When traversing a graph, an object may be encountered that does not
12.55 + * support the Serializable interface. In this case the
12.56 + * NotSerializableException will be thrown and will identify the class
12.57 + * of the non-serializable object. <p>
12.58 + *
12.59 + * Classes that require special handling during the serialization and
12.60 + * deserialization process must implement special methods with these exact
12.61 + * signatures: <p>
12.62 + *
12.63 + * <PRE>
12.64 + * private void writeObject(java.io.ObjectOutputStream out)
12.65 + * throws IOException
12.66 + * private void readObject(java.io.ObjectInputStream in)
12.67 + * throws IOException, ClassNotFoundException;
12.68 + * private void readObjectNoData()
12.69 + * throws ObjectStreamException;
12.70 + * </PRE>
12.71 + *
12.72 + * <p>The writeObject method is responsible for writing the state of the
12.73 + * object for its particular class so that the corresponding
12.74 + * readObject method can restore it. The default mechanism for saving
12.75 + * the Object's fields can be invoked by calling
12.76 + * out.defaultWriteObject. The method does not need to concern
12.77 + * itself with the state belonging to its superclasses or subclasses.
12.78 + * State is saved by writing the individual fields to the
12.79 + * ObjectOutputStream using the writeObject method or by using the
12.80 + * methods for primitive data types supported by DataOutput.
12.81 + *
12.82 + * <p>The readObject method is responsible for reading from the stream and
12.83 + * restoring the classes fields. It may call in.defaultReadObject to invoke
12.84 + * the default mechanism for restoring the object's non-static and
12.85 + * non-transient fields. The defaultReadObject method uses information in
12.86 + * the stream to assign the fields of the object saved in the stream with the
12.87 + * correspondingly named fields in the current object. This handles the case
12.88 + * when the class has evolved to add new fields. The method does not need to
12.89 + * concern itself with the state belonging to its superclasses or subclasses.
12.90 + * State is saved by writing the individual fields to the
12.91 + * ObjectOutputStream using the writeObject method or by using the
12.92 + * methods for primitive data types supported by DataOutput.
12.93 + *
12.94 + * <p>The readObjectNoData method is responsible for initializing the state of
12.95 + * the object for its particular class in the event that the serialization
12.96 + * stream does not list the given class as a superclass of the object being
12.97 + * deserialized. This may occur in cases where the receiving party uses a
12.98 + * different version of the deserialized instance's class than the sending
12.99 + * party, and the receiver's version extends classes that are not extended by
12.100 + * the sender's version. This may also occur if the serialization stream has
12.101 + * been tampered; hence, readObjectNoData is useful for initializing
12.102 + * deserialized objects properly despite a "hostile" or incomplete source
12.103 + * stream.
12.104 + *
12.105 + * <p>Serializable classes that need to designate an alternative object to be
12.106 + * used when writing an object to the stream should implement this
12.107 + * special method with the exact signature: <p>
12.108 + *
12.109 + * <PRE>
12.110 + * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
12.111 + * </PRE><p>
12.112 + *
12.113 + * This writeReplace method is invoked by serialization if the method
12.114 + * exists and it would be accessible from a method defined within the
12.115 + * class of the object being serialized. Thus, the method can have private,
12.116 + * protected and package-private access. Subclass access to this method
12.117 + * follows java accessibility rules. <p>
12.118 + *
12.119 + * Classes that need to designate a replacement when an instance of it
12.120 + * is read from the stream should implement this special method with the
12.121 + * exact signature.<p>
12.122 + *
12.123 + * <PRE>
12.124 + * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
12.125 + * </PRE><p>
12.126 + *
12.127 + * This readResolve method follows the same invocation rules and
12.128 + * accessibility rules as writeReplace.<p>
12.129 + *
12.130 + * The serialization runtime associates with each serializable class a version
12.131 + * number, called a serialVersionUID, which is used during deserialization to
12.132 + * verify that the sender and receiver of a serialized object have loaded
12.133 + * classes for that object that are compatible with respect to serialization.
12.134 + * If the receiver has loaded a class for the object that has a different
12.135 + * serialVersionUID than that of the corresponding sender's class, then
12.136 + * deserialization will result in an {@link InvalidClassException}. A
12.137 + * serializable class can declare its own serialVersionUID explicitly by
12.138 + * declaring a field named <code>"serialVersionUID"</code> that must be static,
12.139 + * final, and of type <code>long</code>:<p>
12.140 + *
12.141 + * <PRE>
12.142 + * ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
12.143 + * </PRE>
12.144 + *
12.145 + * If a serializable class does not explicitly declare a serialVersionUID, then
12.146 + * the serialization runtime will calculate a default serialVersionUID value
12.147 + * for that class based on various aspects of the class, as described in the
12.148 + * Java(TM) Object Serialization Specification. However, it is <em>strongly
12.149 + * recommended</em> that all serializable classes explicitly declare
12.150 + * serialVersionUID values, since the default serialVersionUID computation is
12.151 + * highly sensitive to class details that may vary depending on compiler
12.152 + * implementations, and can thus result in unexpected
12.153 + * <code>InvalidClassException</code>s during deserialization. Therefore, to
12.154 + * guarantee a consistent serialVersionUID value across different java compiler
12.155 + * implementations, a serializable class must declare an explicit
12.156 + * serialVersionUID value. It is also strongly advised that explicit
12.157 + * serialVersionUID declarations use the <code>private</code> modifier where
12.158 + * possible, since such declarations apply only to the immediately declaring
12.159 + * class--serialVersionUID fields are not useful as inherited members. Array
12.160 + * classes cannot declare an explicit serialVersionUID, so they always have
12.161 + * the default computed value, but the requirement for matching
12.162 + * serialVersionUID values is waived for array classes.
12.163 + *
12.164 + * @author unascribed
12.165 + * @see java.io.ObjectOutputStream
12.166 + * @see java.io.ObjectInputStream
12.167 + * @see java.io.ObjectOutput
12.168 + * @see java.io.ObjectInput
12.169 + * @see java.io.Externalizable
12.170 + * @since JDK1.1
12.171 + */
12.172 +public interface Serializable {
12.173 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/emul/mini/src/main/java/java/io/UTFDataFormatException.java Wed Jan 23 20:39:23 2013 +0100
13.3 @@ -0,0 +1,69 @@
13.4 +/*
13.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13.7 + *
13.8 + * This code is free software; you can redistribute it and/or modify it
13.9 + * under the terms of the GNU General Public License version 2 only, as
13.10 + * published by the Free Software Foundation. Oracle designates this
13.11 + * particular file as subject to the "Classpath" exception as provided
13.12 + * by Oracle in the LICENSE file that accompanied this code.
13.13 + *
13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.17 + * version 2 for more details (a copy is included in the LICENSE file that
13.18 + * accompanied this code).
13.19 + *
13.20 + * You should have received a copy of the GNU General Public License version
13.21 + * 2 along with this work; if not, write to the Free Software Foundation,
13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13.23 + *
13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13.25 + * or visit www.oracle.com if you need additional information or have any
13.26 + * questions.
13.27 + */
13.28 +
13.29 +package java.io;
13.30 +
13.31 +/**
13.32 + * Signals that a malformed string in
13.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
13.34 + * format has been read in a data
13.35 + * input stream or by any class that implements the data input
13.36 + * interface.
13.37 + * See the
13.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
13.39 + * class description for the format in
13.40 + * which modified UTF-8 strings are read and written.
13.41 + *
13.42 + * @author Frank Yellin
13.43 + * @see java.io.DataInput
13.44 + * @see java.io.DataInputStream#readUTF(java.io.DataInput)
13.45 + * @see java.io.IOException
13.46 + * @since JDK1.0
13.47 + */
13.48 +public
13.49 +class UTFDataFormatException extends IOException {
13.50 + private static final long serialVersionUID = 420743449228280612L;
13.51 +
13.52 + /**
13.53 + * Constructs a <code>UTFDataFormatException</code> with
13.54 + * <code>null</code> as its error detail message.
13.55 + */
13.56 + public UTFDataFormatException() {
13.57 + super();
13.58 + }
13.59 +
13.60 + /**
13.61 + * Constructs a <code>UTFDataFormatException</code> with the
13.62 + * specified detail message. The string <code>s</code> can be
13.63 + * retrieved later by the
13.64 + * <code>{@link java.lang.Throwable#getMessage}</code>
13.65 + * method of class <code>java.lang.Throwable</code>.
13.66 + *
13.67 + * @param s the detail message.
13.68 + */
13.69 + public UTFDataFormatException(String s) {
13.70 + super(s);
13.71 + }
13.72 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/emul/mini/src/main/java/java/io/UnsupportedEncodingException.java Wed Jan 23 20:39:23 2013 +0100
14.3 @@ -0,0 +1,52 @@
14.4 +/*
14.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14.7 + *
14.8 + * This code is free software; you can redistribute it and/or modify it
14.9 + * under the terms of the GNU General Public License version 2 only, as
14.10 + * published by the Free Software Foundation. Oracle designates this
14.11 + * particular file as subject to the "Classpath" exception as provided
14.12 + * by Oracle in the LICENSE file that accompanied this code.
14.13 + *
14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14.17 + * version 2 for more details (a copy is included in the LICENSE file that
14.18 + * accompanied this code).
14.19 + *
14.20 + * You should have received a copy of the GNU General Public License version
14.21 + * 2 along with this work; if not, write to the Free Software Foundation,
14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14.23 + *
14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14.25 + * or visit www.oracle.com if you need additional information or have any
14.26 + * questions.
14.27 + */
14.28 +package java.io;
14.29 +
14.30 +/**
14.31 + * The Character Encoding is not supported.
14.32 + *
14.33 + * @author Asmus Freytag
14.34 + * @since JDK1.1
14.35 + */
14.36 +public class UnsupportedEncodingException
14.37 + extends IOException
14.38 +{
14.39 + private static final long serialVersionUID = -4274276298326136670L;
14.40 +
14.41 + /**
14.42 + * Constructs an UnsupportedEncodingException without a detail message.
14.43 + */
14.44 + public UnsupportedEncodingException() {
14.45 + super();
14.46 + }
14.47 +
14.48 + /**
14.49 + * Constructs an UnsupportedEncodingException with a detail message.
14.50 + * @param s Describes the reason for the exception.
14.51 + */
14.52 + public UnsupportedEncodingException(String s) {
14.53 + super(s);
14.54 + }
14.55 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/emul/mini/src/main/java/java/lang/AbstractStringBuilder.java Wed Jan 23 20:39:23 2013 +0100
15.3 @@ -0,0 +1,1424 @@
15.4 +/*
15.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15.7 + *
15.8 + * This code is free software; you can redistribute it and/or modify it
15.9 + * under the terms of the GNU General Public License version 2 only, as
15.10 + * published by the Free Software Foundation. Oracle designates this
15.11 + * particular file as subject to the "Classpath" exception as provided
15.12 + * by Oracle in the LICENSE file that accompanied this code.
15.13 + *
15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15.17 + * version 2 for more details (a copy is included in the LICENSE file that
15.18 + * accompanied this code).
15.19 + *
15.20 + * You should have received a copy of the GNU General Public License version
15.21 + * 2 along with this work; if not, write to the Free Software Foundation,
15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15.23 + *
15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15.25 + * or visit www.oracle.com if you need additional information or have any
15.26 + * questions.
15.27 + */
15.28 +
15.29 +package java.lang;
15.30 +
15.31 +/**
15.32 + * A mutable sequence of characters.
15.33 + * <p>
15.34 + * Implements a modifiable string. At any point in time it contains some
15.35 + * particular sequence of characters, but the length and content of the
15.36 + * sequence can be changed through certain method calls.
15.37 + *
15.38 + * @author Michael McCloskey
15.39 + * @author Martin Buchholz
15.40 + * @author Ulf Zibis
15.41 + * @since 1.5
15.42 + */
15.43 +abstract class AbstractStringBuilder implements Appendable, CharSequence {
15.44 + /**
15.45 + * The value is used for character storage.
15.46 + */
15.47 + char[] value;
15.48 +
15.49 + /**
15.50 + * The count is the number of characters used.
15.51 + */
15.52 + int count;
15.53 +
15.54 + /**
15.55 + * This no-arg constructor is necessary for serialization of subclasses.
15.56 + */
15.57 + AbstractStringBuilder() {
15.58 + }
15.59 +
15.60 + /**
15.61 + * Creates an AbstractStringBuilder of the specified capacity.
15.62 + */
15.63 + AbstractStringBuilder(int capacity) {
15.64 + value = new char[capacity];
15.65 + }
15.66 +
15.67 + /**
15.68 + * Returns the length (character count).
15.69 + *
15.70 + * @return the length of the sequence of characters currently
15.71 + * represented by this object
15.72 + */
15.73 + public int length() {
15.74 + return count;
15.75 + }
15.76 +
15.77 + /**
15.78 + * Returns the current capacity. The capacity is the amount of storage
15.79 + * available for newly inserted characters, beyond which an allocation
15.80 + * will occur.
15.81 + *
15.82 + * @return the current capacity
15.83 + */
15.84 + public int capacity() {
15.85 + return value.length;
15.86 + }
15.87 +
15.88 + /**
15.89 + * Ensures that the capacity is at least equal to the specified minimum.
15.90 + * If the current capacity is less than the argument, then a new internal
15.91 + * array is allocated with greater capacity. The new capacity is the
15.92 + * larger of:
15.93 + * <ul>
15.94 + * <li>The <code>minimumCapacity</code> argument.
15.95 + * <li>Twice the old capacity, plus <code>2</code>.
15.96 + * </ul>
15.97 + * If the <code>minimumCapacity</code> argument is nonpositive, this
15.98 + * method takes no action and simply returns.
15.99 + *
15.100 + * @param minimumCapacity the minimum desired capacity.
15.101 + */
15.102 + public void ensureCapacity(int minimumCapacity) {
15.103 + if (minimumCapacity > 0)
15.104 + ensureCapacityInternal(minimumCapacity);
15.105 + }
15.106 +
15.107 + /**
15.108 + * This method has the same contract as ensureCapacity, but is
15.109 + * never synchronized.
15.110 + */
15.111 + private void ensureCapacityInternal(int minimumCapacity) {
15.112 + // overflow-conscious code
15.113 + if (minimumCapacity - value.length > 0)
15.114 + expandCapacity(minimumCapacity);
15.115 + }
15.116 +
15.117 + /**
15.118 + * This implements the expansion semantics of ensureCapacity with no
15.119 + * size check or synchronization.
15.120 + */
15.121 + void expandCapacity(int minimumCapacity) {
15.122 + int newCapacity = value.length * 2 + 2;
15.123 + if (newCapacity - minimumCapacity < 0)
15.124 + newCapacity = minimumCapacity;
15.125 + if (newCapacity < 0) {
15.126 + if (minimumCapacity < 0) // overflow
15.127 + throw new OutOfMemoryError();
15.128 + newCapacity = Integer.MAX_VALUE;
15.129 + }
15.130 + value = copyOf(value, newCapacity);
15.131 + }
15.132 +
15.133 + /**
15.134 + * Attempts to reduce storage used for the character sequence.
15.135 + * If the buffer is larger than necessary to hold its current sequence of
15.136 + * characters, then it may be resized to become more space efficient.
15.137 + * Calling this method may, but is not required to, affect the value
15.138 + * returned by a subsequent call to the {@link #capacity()} method.
15.139 + */
15.140 + public void trimToSize() {
15.141 + if (count < value.length) {
15.142 + value = copyOf(value, count);
15.143 + }
15.144 + }
15.145 +
15.146 + /**
15.147 + * Sets the length of the character sequence.
15.148 + * The sequence is changed to a new character sequence
15.149 + * whose length is specified by the argument. For every nonnegative
15.150 + * index <i>k</i> less than <code>newLength</code>, the character at
15.151 + * index <i>k</i> in the new character sequence is the same as the
15.152 + * character at index <i>k</i> in the old sequence if <i>k</i> is less
15.153 + * than the length of the old character sequence; otherwise, it is the
15.154 + * null character <code>'\u0000'</code>.
15.155 + *
15.156 + * In other words, if the <code>newLength</code> argument is less than
15.157 + * the current length, the length is changed to the specified length.
15.158 + * <p>
15.159 + * If the <code>newLength</code> argument is greater than or equal
15.160 + * to the current length, sufficient null characters
15.161 + * (<code>'\u0000'</code>) are appended so that
15.162 + * length becomes the <code>newLength</code> argument.
15.163 + * <p>
15.164 + * The <code>newLength</code> argument must be greater than or equal
15.165 + * to <code>0</code>.
15.166 + *
15.167 + * @param newLength the new length
15.168 + * @throws IndexOutOfBoundsException if the
15.169 + * <code>newLength</code> argument is negative.
15.170 + */
15.171 + public void setLength(int newLength) {
15.172 + if (newLength < 0)
15.173 + throw new StringIndexOutOfBoundsException(newLength);
15.174 + ensureCapacityInternal(newLength);
15.175 +
15.176 + if (count < newLength) {
15.177 + for (; count < newLength; count++)
15.178 + value[count] = '\0';
15.179 + } else {
15.180 + count = newLength;
15.181 + }
15.182 + }
15.183 +
15.184 + /**
15.185 + * Returns the <code>char</code> value in this sequence at the specified index.
15.186 + * The first <code>char</code> value is at index <code>0</code>, the next at index
15.187 + * <code>1</code>, and so on, as in array indexing.
15.188 + * <p>
15.189 + * The index argument must be greater than or equal to
15.190 + * <code>0</code>, and less than the length of this sequence.
15.191 + *
15.192 + * <p>If the <code>char</code> value specified by the index is a
15.193 + * <a href="Character.html#unicode">surrogate</a>, the surrogate
15.194 + * value is returned.
15.195 + *
15.196 + * @param index the index of the desired <code>char</code> value.
15.197 + * @return the <code>char</code> value at the specified index.
15.198 + * @throws IndexOutOfBoundsException if <code>index</code> is
15.199 + * negative or greater than or equal to <code>length()</code>.
15.200 + */
15.201 + public char charAt(int index) {
15.202 + if ((index < 0) || (index >= count))
15.203 + throw new StringIndexOutOfBoundsException(index);
15.204 + return value[index];
15.205 + }
15.206 +
15.207 + /**
15.208 + * Returns the character (Unicode code point) at the specified
15.209 + * index. The index refers to <code>char</code> values
15.210 + * (Unicode code units) and ranges from <code>0</code> to
15.211 + * {@link #length()}<code> - 1</code>.
15.212 + *
15.213 + * <p> If the <code>char</code> value specified at the given index
15.214 + * is in the high-surrogate range, the following index is less
15.215 + * than the length of this sequence, and the
15.216 + * <code>char</code> value at the following index is in the
15.217 + * low-surrogate range, then the supplementary code point
15.218 + * corresponding to this surrogate pair is returned. Otherwise,
15.219 + * the <code>char</code> value at the given index is returned.
15.220 + *
15.221 + * @param index the index to the <code>char</code> values
15.222 + * @return the code point value of the character at the
15.223 + * <code>index</code>
15.224 + * @exception IndexOutOfBoundsException if the <code>index</code>
15.225 + * argument is negative or not less than the length of this
15.226 + * sequence.
15.227 + */
15.228 + public int codePointAt(int index) {
15.229 + if ((index < 0) || (index >= count)) {
15.230 + throw new StringIndexOutOfBoundsException(index);
15.231 + }
15.232 + return Character.codePointAt(value, index);
15.233 + }
15.234 +
15.235 + /**
15.236 + * Returns the character (Unicode code point) before the specified
15.237 + * index. The index refers to <code>char</code> values
15.238 + * (Unicode code units) and ranges from <code>1</code> to {@link
15.239 + * #length()}.
15.240 + *
15.241 + * <p> If the <code>char</code> value at <code>(index - 1)</code>
15.242 + * is in the low-surrogate range, <code>(index - 2)</code> is not
15.243 + * negative, and the <code>char</code> value at <code>(index -
15.244 + * 2)</code> is in the high-surrogate range, then the
15.245 + * supplementary code point value of the surrogate pair is
15.246 + * returned. If the <code>char</code> value at <code>index -
15.247 + * 1</code> is an unpaired low-surrogate or a high-surrogate, the
15.248 + * surrogate value is returned.
15.249 + *
15.250 + * @param index the index following the code point that should be returned
15.251 + * @return the Unicode code point value before the given index.
15.252 + * @exception IndexOutOfBoundsException if the <code>index</code>
15.253 + * argument is less than 1 or greater than the length
15.254 + * of this sequence.
15.255 + */
15.256 + public int codePointBefore(int index) {
15.257 + int i = index - 1;
15.258 + if ((i < 0) || (i >= count)) {
15.259 + throw new StringIndexOutOfBoundsException(index);
15.260 + }
15.261 + return Character.codePointBefore(value, index);
15.262 + }
15.263 +
15.264 + /**
15.265 + * Returns the number of Unicode code points in the specified text
15.266 + * range of this sequence. The text range begins at the specified
15.267 + * <code>beginIndex</code> and extends to the <code>char</code> at
15.268 + * index <code>endIndex - 1</code>. Thus the length (in
15.269 + * <code>char</code>s) of the text range is
15.270 + * <code>endIndex-beginIndex</code>. Unpaired surrogates within
15.271 + * this sequence count as one code point each.
15.272 + *
15.273 + * @param beginIndex the index to the first <code>char</code> of
15.274 + * the text range.
15.275 + * @param endIndex the index after the last <code>char</code> of
15.276 + * the text range.
15.277 + * @return the number of Unicode code points in the specified text
15.278 + * range
15.279 + * @exception IndexOutOfBoundsException if the
15.280 + * <code>beginIndex</code> is negative, or <code>endIndex</code>
15.281 + * is larger than the length of this sequence, or
15.282 + * <code>beginIndex</code> is larger than <code>endIndex</code>.
15.283 + */
15.284 + public int codePointCount(int beginIndex, int endIndex) {
15.285 + if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
15.286 + throw new IndexOutOfBoundsException();
15.287 + }
15.288 + return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
15.289 + }
15.290 +
15.291 + /**
15.292 + * Returns the index within this sequence that is offset from the
15.293 + * given <code>index</code> by <code>codePointOffset</code> code
15.294 + * points. Unpaired surrogates within the text range given by
15.295 + * <code>index</code> and <code>codePointOffset</code> count as
15.296 + * one code point each.
15.297 + *
15.298 + * @param index the index to be offset
15.299 + * @param codePointOffset the offset in code points
15.300 + * @return the index within this sequence
15.301 + * @exception IndexOutOfBoundsException if <code>index</code>
15.302 + * is negative or larger then the length of this sequence,
15.303 + * or if <code>codePointOffset</code> is positive and the subsequence
15.304 + * starting with <code>index</code> has fewer than
15.305 + * <code>codePointOffset</code> code points,
15.306 + * or if <code>codePointOffset</code> is negative and the subsequence
15.307 + * before <code>index</code> has fewer than the absolute value of
15.308 + * <code>codePointOffset</code> code points.
15.309 + */
15.310 + public int offsetByCodePoints(int index, int codePointOffset) {
15.311 + if (index < 0 || index > count) {
15.312 + throw new IndexOutOfBoundsException();
15.313 + }
15.314 + return Character.offsetByCodePointsImpl(value, 0, count,
15.315 + index, codePointOffset);
15.316 + }
15.317 +
15.318 + /**
15.319 + * Characters are copied from this sequence into the
15.320 + * destination character array <code>dst</code>. The first character to
15.321 + * be copied is at index <code>srcBegin</code>; the last character to
15.322 + * be copied is at index <code>srcEnd-1</code>. The total number of
15.323 + * characters to be copied is <code>srcEnd-srcBegin</code>. The
15.324 + * characters are copied into the subarray of <code>dst</code> starting
15.325 + * at index <code>dstBegin</code> and ending at index:
15.326 + * <p><blockquote><pre>
15.327 + * dstbegin + (srcEnd-srcBegin) - 1
15.328 + * </pre></blockquote>
15.329 + *
15.330 + * @param srcBegin start copying at this offset.
15.331 + * @param srcEnd stop copying at this offset.
15.332 + * @param dst the array to copy the data into.
15.333 + * @param dstBegin offset into <code>dst</code>.
15.334 + * @throws NullPointerException if <code>dst</code> is
15.335 + * <code>null</code>.
15.336 + * @throws IndexOutOfBoundsException if any of the following is true:
15.337 + * <ul>
15.338 + * <li><code>srcBegin</code> is negative
15.339 + * <li><code>dstBegin</code> is negative
15.340 + * <li>the <code>srcBegin</code> argument is greater than
15.341 + * the <code>srcEnd</code> argument.
15.342 + * <li><code>srcEnd</code> is greater than
15.343 + * <code>this.length()</code>.
15.344 + * <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
15.345 + * <code>dst.length</code>
15.346 + * </ul>
15.347 + */
15.348 + public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
15.349 + {
15.350 + if (srcBegin < 0)
15.351 + throw new StringIndexOutOfBoundsException(srcBegin);
15.352 + if ((srcEnd < 0) || (srcEnd > count))
15.353 + throw new StringIndexOutOfBoundsException(srcEnd);
15.354 + if (srcBegin > srcEnd)
15.355 + throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
15.356 + arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
15.357 + }
15.358 +
15.359 + /**
15.360 + * The character at the specified index is set to <code>ch</code>. This
15.361 + * sequence is altered to represent a new character sequence that is
15.362 + * identical to the old character sequence, except that it contains the
15.363 + * character <code>ch</code> at position <code>index</code>.
15.364 + * <p>
15.365 + * The index argument must be greater than or equal to
15.366 + * <code>0</code>, and less than the length of this sequence.
15.367 + *
15.368 + * @param index the index of the character to modify.
15.369 + * @param ch the new character.
15.370 + * @throws IndexOutOfBoundsException if <code>index</code> is
15.371 + * negative or greater than or equal to <code>length()</code>.
15.372 + */
15.373 + public void setCharAt(int index, char ch) {
15.374 + if ((index < 0) || (index >= count))
15.375 + throw new StringIndexOutOfBoundsException(index);
15.376 + value[index] = ch;
15.377 + }
15.378 +
15.379 + /**
15.380 + * Appends the string representation of the {@code Object} argument.
15.381 + * <p>
15.382 + * The overall effect is exactly as if the argument were converted
15.383 + * to a string by the method {@link String#valueOf(Object)},
15.384 + * and the characters of that string were then
15.385 + * {@link #append(String) appended} to this character sequence.
15.386 + *
15.387 + * @param obj an {@code Object}.
15.388 + * @return a reference to this object.
15.389 + */
15.390 + public AbstractStringBuilder append(Object obj) {
15.391 + return append(String.valueOf(obj));
15.392 + }
15.393 +
15.394 + /**
15.395 + * Appends the specified string to this character sequence.
15.396 + * <p>
15.397 + * The characters of the {@code String} argument are appended, in
15.398 + * order, increasing the length of this sequence by the length of the
15.399 + * argument. If {@code str} is {@code null}, then the four
15.400 + * characters {@code "null"} are appended.
15.401 + * <p>
15.402 + * Let <i>n</i> be the length of this character sequence just prior to
15.403 + * execution of the {@code append} method. Then the character at
15.404 + * index <i>k</i> in the new character sequence is equal to the character
15.405 + * at index <i>k</i> in the old character sequence, if <i>k</i> is less
15.406 + * than <i>n</i>; otherwise, it is equal to the character at index
15.407 + * <i>k-n</i> in the argument {@code str}.
15.408 + *
15.409 + * @param str a string.
15.410 + * @return a reference to this object.
15.411 + */
15.412 + public AbstractStringBuilder append(String str) {
15.413 + if (str == null) str = "null";
15.414 + int len = str.length();
15.415 + ensureCapacityInternal(count + len);
15.416 + str.getChars(0, len, value, count);
15.417 + count += len;
15.418 + return this;
15.419 + }
15.420 +
15.421 + // Documentation in subclasses because of synchro difference
15.422 + public AbstractStringBuilder append(StringBuffer sb) {
15.423 + if (sb == null)
15.424 + return append("null");
15.425 + int len = sb.length();
15.426 + ensureCapacityInternal(count + len);
15.427 + sb.getChars(0, len, value, count);
15.428 + count += len;
15.429 + return this;
15.430 + }
15.431 +
15.432 + // Documentation in subclasses because of synchro difference
15.433 + public AbstractStringBuilder append(CharSequence s) {
15.434 + if (s == null)
15.435 + s = "null";
15.436 + if (s instanceof String)
15.437 + return this.append((String)s);
15.438 + if (s instanceof StringBuffer)
15.439 + return this.append((StringBuffer)s);
15.440 + return this.append(s, 0, s.length());
15.441 + }
15.442 +
15.443 + /**
15.444 + * Appends a subsequence of the specified {@code CharSequence} to this
15.445 + * sequence.
15.446 + * <p>
15.447 + * Characters of the argument {@code s}, starting at
15.448 + * index {@code start}, are appended, in order, to the contents of
15.449 + * this sequence up to the (exclusive) index {@code end}. The length
15.450 + * of this sequence is increased by the value of {@code end - start}.
15.451 + * <p>
15.452 + * Let <i>n</i> be the length of this character sequence just prior to
15.453 + * execution of the {@code append} method. Then the character at
15.454 + * index <i>k</i> in this character sequence becomes equal to the
15.455 + * character at index <i>k</i> in this sequence, if <i>k</i> is less than
15.456 + * <i>n</i>; otherwise, it is equal to the character at index
15.457 + * <i>k+start-n</i> in the argument {@code s}.
15.458 + * <p>
15.459 + * If {@code s} is {@code null}, then this method appends
15.460 + * characters as if the s parameter was a sequence containing the four
15.461 + * characters {@code "null"}.
15.462 + *
15.463 + * @param s the sequence to append.
15.464 + * @param start the starting index of the subsequence to be appended.
15.465 + * @param end the end index of the subsequence to be appended.
15.466 + * @return a reference to this object.
15.467 + * @throws IndexOutOfBoundsException if
15.468 + * {@code start} is negative, or
15.469 + * {@code start} is greater than {@code end} or
15.470 + * {@code end} is greater than {@code s.length()}
15.471 + */
15.472 + public AbstractStringBuilder append(CharSequence s, int start, int end) {
15.473 + if (s == null)
15.474 + s = "null";
15.475 + if ((start < 0) || (start > end) || (end > s.length()))
15.476 + throw new IndexOutOfBoundsException(
15.477 + "start " + start + ", end " + end + ", s.length() "
15.478 + + s.length());
15.479 + int len = end - start;
15.480 + ensureCapacityInternal(count + len);
15.481 + for (int i = start, j = count; i < end; i++, j++)
15.482 + value[j] = s.charAt(i);
15.483 + count += len;
15.484 + return this;
15.485 + }
15.486 +
15.487 + /**
15.488 + * Appends the string representation of the {@code char} array
15.489 + * argument to this sequence.
15.490 + * <p>
15.491 + * The characters of the array argument are appended, in order, to
15.492 + * the contents of this sequence. The length of this sequence
15.493 + * increases by the length of the argument.
15.494 + * <p>
15.495 + * The overall effect is exactly as if the argument were converted
15.496 + * to a string by the method {@link String#valueOf(char[])},
15.497 + * and the characters of that string were then
15.498 + * {@link #append(String) appended} to this character sequence.
15.499 + *
15.500 + * @param str the characters to be appended.
15.501 + * @return a reference to this object.
15.502 + */
15.503 + public AbstractStringBuilder append(char[] str) {
15.504 + int len = str.length;
15.505 + ensureCapacityInternal(count + len);
15.506 + arraycopy(str, 0, value, count, len);
15.507 + count += len;
15.508 + return this;
15.509 + }
15.510 +
15.511 + /**
15.512 + * Appends the string representation of a subarray of the
15.513 + * {@code char} array argument to this sequence.
15.514 + * <p>
15.515 + * Characters of the {@code char} array {@code str}, starting at
15.516 + * index {@code offset}, are appended, in order, to the contents
15.517 + * of this sequence. The length of this sequence increases
15.518 + * by the value of {@code len}.
15.519 + * <p>
15.520 + * The overall effect is exactly as if the arguments were converted
15.521 + * to a string by the method {@link String#valueOf(char[],int,int)},
15.522 + * and the characters of that string were then
15.523 + * {@link #append(String) appended} to this character sequence.
15.524 + *
15.525 + * @param str the characters to be appended.
15.526 + * @param offset the index of the first {@code char} to append.
15.527 + * @param len the number of {@code char}s to append.
15.528 + * @return a reference to this object.
15.529 + * @throws IndexOutOfBoundsException
15.530 + * if {@code offset < 0} or {@code len < 0}
15.531 + * or {@code offset+len > str.length}
15.532 + */
15.533 + public AbstractStringBuilder append(char str[], int offset, int len) {
15.534 + if (len > 0) // let arraycopy report AIOOBE for len < 0
15.535 + ensureCapacityInternal(count + len);
15.536 + arraycopy(str, offset, value, count, len);
15.537 + count += len;
15.538 + return this;
15.539 + }
15.540 +
15.541 + /**
15.542 + * Appends the string representation of the {@code boolean}
15.543 + * argument to the sequence.
15.544 + * <p>
15.545 + * The overall effect is exactly as if the argument were converted
15.546 + * to a string by the method {@link String#valueOf(boolean)},
15.547 + * and the characters of that string were then
15.548 + * {@link #append(String) appended} to this character sequence.
15.549 + *
15.550 + * @param b a {@code boolean}.
15.551 + * @return a reference to this object.
15.552 + */
15.553 + public AbstractStringBuilder append(boolean b) {
15.554 + if (b) {
15.555 + ensureCapacityInternal(count + 4);
15.556 + value[count++] = 't';
15.557 + value[count++] = 'r';
15.558 + value[count++] = 'u';
15.559 + value[count++] = 'e';
15.560 + } else {
15.561 + ensureCapacityInternal(count + 5);
15.562 + value[count++] = 'f';
15.563 + value[count++] = 'a';
15.564 + value[count++] = 'l';
15.565 + value[count++] = 's';
15.566 + value[count++] = 'e';
15.567 + }
15.568 + return this;
15.569 + }
15.570 +
15.571 + /**
15.572 + * Appends the string representation of the {@code char}
15.573 + * argument to this sequence.
15.574 + * <p>
15.575 + * The argument is appended to the contents of this sequence.
15.576 + * The length of this sequence increases by {@code 1}.
15.577 + * <p>
15.578 + * The overall effect is exactly as if the argument were converted
15.579 + * to a string by the method {@link String#valueOf(char)},
15.580 + * and the character in that string were then
15.581 + * {@link #append(String) appended} to this character sequence.
15.582 + *
15.583 + * @param c a {@code char}.
15.584 + * @return a reference to this object.
15.585 + */
15.586 + public AbstractStringBuilder append(char c) {
15.587 + ensureCapacityInternal(count + 1);
15.588 + value[count++] = c;
15.589 + return this;
15.590 + }
15.591 +
15.592 + /**
15.593 + * Appends the string representation of the {@code int}
15.594 + * argument to this sequence.
15.595 + * <p>
15.596 + * The overall effect is exactly as if the argument were converted
15.597 + * to a string by the method {@link String#valueOf(int)},
15.598 + * and the characters of that string were then
15.599 + * {@link #append(String) appended} to this character sequence.
15.600 + *
15.601 + * @param i an {@code int}.
15.602 + * @return a reference to this object.
15.603 + */
15.604 + public AbstractStringBuilder append(int i) {
15.605 + return append(Integer.toString(i));
15.606 + }
15.607 +
15.608 + /**
15.609 + * Appends the string representation of the {@code long}
15.610 + * argument to this sequence.
15.611 + * <p>
15.612 + * The overall effect is exactly as if the argument were converted
15.613 + * to a string by the method {@link String#valueOf(long)},
15.614 + * and the characters of that string were then
15.615 + * {@link #append(String) appended} to this character sequence.
15.616 + *
15.617 + * @param l a {@code long}.
15.618 + * @return a reference to this object.
15.619 + */
15.620 + public AbstractStringBuilder append(long l) {
15.621 + if (l == Long.MIN_VALUE) {
15.622 + append("-9223372036854775808");
15.623 + return this;
15.624 + }
15.625 + int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
15.626 + : Long.stringSize(l);
15.627 + int spaceNeeded = count + appendedLength;
15.628 + ensureCapacityInternal(spaceNeeded);
15.629 + Long.getChars(l, spaceNeeded, value);
15.630 + count = spaceNeeded;
15.631 + return this;
15.632 + }
15.633 +
15.634 + /**
15.635 + * Appends the string representation of the {@code float}
15.636 + * argument to this sequence.
15.637 + * <p>
15.638 + * The overall effect is exactly as if the argument were converted
15.639 + * to a string by the method {@link String#valueOf(float)},
15.640 + * and the characters of that string were then
15.641 + * {@link #append(String) appended} to this character sequence.
15.642 + *
15.643 + * @param f a {@code float}.
15.644 + * @return a reference to this object.
15.645 + */
15.646 + public AbstractStringBuilder append(float f) {
15.647 + return append(Float.toString(f));
15.648 + }
15.649 +
15.650 + /**
15.651 + * Appends the string representation of the {@code double}
15.652 + * argument to this sequence.
15.653 + * <p>
15.654 + * The overall effect is exactly as if the argument were converted
15.655 + * to a string by the method {@link String#valueOf(double)},
15.656 + * and the characters of that string were then
15.657 + * {@link #append(String) appended} to this character sequence.
15.658 + *
15.659 + * @param d a {@code double}.
15.660 + * @return a reference to this object.
15.661 + */
15.662 + public AbstractStringBuilder append(double d) {
15.663 + return append(Double.toString(d));
15.664 + }
15.665 +
15.666 + /**
15.667 + * Removes the characters in a substring of this sequence.
15.668 + * The substring begins at the specified {@code start} and extends to
15.669 + * the character at index {@code end - 1} or to the end of the
15.670 + * sequence if no such character exists. If
15.671 + * {@code start} is equal to {@code end}, no changes are made.
15.672 + *
15.673 + * @param start The beginning index, inclusive.
15.674 + * @param end The ending index, exclusive.
15.675 + * @return This object.
15.676 + * @throws StringIndexOutOfBoundsException if {@code start}
15.677 + * is negative, greater than {@code length()}, or
15.678 + * greater than {@code end}.
15.679 + */
15.680 + public AbstractStringBuilder delete(int start, int end) {
15.681 + if (start < 0)
15.682 + throw new StringIndexOutOfBoundsException(start);
15.683 + if (end > count)
15.684 + end = count;
15.685 + if (start > end)
15.686 + throw new StringIndexOutOfBoundsException();
15.687 + int len = end - start;
15.688 + if (len > 0) {
15.689 + arraycopy(value, start+len, value, start, count-end);
15.690 + count -= len;
15.691 + }
15.692 + return this;
15.693 + }
15.694 +
15.695 + /**
15.696 + * Appends the string representation of the {@code codePoint}
15.697 + * argument to this sequence.
15.698 + *
15.699 + * <p> The argument is appended to the contents of this sequence.
15.700 + * The length of this sequence increases by
15.701 + * {@link Character#charCount(int) Character.charCount(codePoint)}.
15.702 + *
15.703 + * <p> The overall effect is exactly as if the argument were
15.704 + * converted to a {@code char} array by the method
15.705 + * {@link Character#toChars(int)} and the character in that array
15.706 + * were then {@link #append(char[]) appended} to this character
15.707 + * sequence.
15.708 + *
15.709 + * @param codePoint a Unicode code point
15.710 + * @return a reference to this object.
15.711 + * @exception IllegalArgumentException if the specified
15.712 + * {@code codePoint} isn't a valid Unicode code point
15.713 + */
15.714 + public AbstractStringBuilder appendCodePoint(int codePoint) {
15.715 + final int count = this.count;
15.716 +
15.717 + if (Character.isBmpCodePoint(codePoint)) {
15.718 + ensureCapacityInternal(count + 1);
15.719 + value[count] = (char) codePoint;
15.720 + this.count = count + 1;
15.721 + } else if (Character.isValidCodePoint(codePoint)) {
15.722 + ensureCapacityInternal(count + 2);
15.723 + Character.toSurrogates(codePoint, value, count);
15.724 + this.count = count + 2;
15.725 + } else {
15.726 + throw new IllegalArgumentException();
15.727 + }
15.728 + return this;
15.729 + }
15.730 +
15.731 + /**
15.732 + * Removes the <code>char</code> at the specified position in this
15.733 + * sequence. This sequence is shortened by one <code>char</code>.
15.734 + *
15.735 + * <p>Note: If the character at the given index is a supplementary
15.736 + * character, this method does not remove the entire character. If
15.737 + * correct handling of supplementary characters is required,
15.738 + * determine the number of <code>char</code>s to remove by calling
15.739 + * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
15.740 + * where <code>thisSequence</code> is this sequence.
15.741 + *
15.742 + * @param index Index of <code>char</code> to remove
15.743 + * @return This object.
15.744 + * @throws StringIndexOutOfBoundsException if the <code>index</code>
15.745 + * is negative or greater than or equal to
15.746 + * <code>length()</code>.
15.747 + */
15.748 + public AbstractStringBuilder deleteCharAt(int index) {
15.749 + if ((index < 0) || (index >= count))
15.750 + throw new StringIndexOutOfBoundsException(index);
15.751 + arraycopy(value, index+1, value, index, count-index-1);
15.752 + count--;
15.753 + return this;
15.754 + }
15.755 +
15.756 + /**
15.757 + * Replaces the characters in a substring of this sequence
15.758 + * with characters in the specified <code>String</code>. The substring
15.759 + * begins at the specified <code>start</code> and extends to the character
15.760 + * at index <code>end - 1</code> or to the end of the
15.761 + * sequence if no such character exists. First the
15.762 + * characters in the substring are removed and then the specified
15.763 + * <code>String</code> is inserted at <code>start</code>. (This
15.764 + * sequence will be lengthened to accommodate the
15.765 + * specified String if necessary.)
15.766 + *
15.767 + * @param start The beginning index, inclusive.
15.768 + * @param end The ending index, exclusive.
15.769 + * @param str String that will replace previous contents.
15.770 + * @return This object.
15.771 + * @throws StringIndexOutOfBoundsException if <code>start</code>
15.772 + * is negative, greater than <code>length()</code>, or
15.773 + * greater than <code>end</code>.
15.774 + */
15.775 + public AbstractStringBuilder replace(int start, int end, String str) {
15.776 + if (start < 0)
15.777 + throw new StringIndexOutOfBoundsException(start);
15.778 + if (start > count)
15.779 + throw new StringIndexOutOfBoundsException("start > length()");
15.780 + if (start > end)
15.781 + throw new StringIndexOutOfBoundsException("start > end");
15.782 +
15.783 + if (end > count)
15.784 + end = count;
15.785 + int len = str.length();
15.786 + int newCount = count + len - (end - start);
15.787 + ensureCapacityInternal(newCount);
15.788 +
15.789 + arraycopy(value, end, value, start + len, count - end);
15.790 + str.getChars(value, start);
15.791 + count = newCount;
15.792 + return this;
15.793 + }
15.794 +
15.795 + /**
15.796 + * Returns a new <code>String</code> that contains a subsequence of
15.797 + * characters currently contained in this character sequence. The
15.798 + * substring begins at the specified index and extends to the end of
15.799 + * this sequence.
15.800 + *
15.801 + * @param start The beginning index, inclusive.
15.802 + * @return The new string.
15.803 + * @throws StringIndexOutOfBoundsException if <code>start</code> is
15.804 + * less than zero, or greater than the length of this object.
15.805 + */
15.806 + public String substring(int start) {
15.807 + return substring(start, count);
15.808 + }
15.809 +
15.810 + /**
15.811 + * Returns a new character sequence that is a subsequence of this sequence.
15.812 + *
15.813 + * <p> An invocation of this method of the form
15.814 + *
15.815 + * <blockquote><pre>
15.816 + * sb.subSequence(begin, end)</pre></blockquote>
15.817 + *
15.818 + * behaves in exactly the same way as the invocation
15.819 + *
15.820 + * <blockquote><pre>
15.821 + * sb.substring(begin, end)</pre></blockquote>
15.822 + *
15.823 + * This method is provided so that this class can
15.824 + * implement the {@link CharSequence} interface. </p>
15.825 + *
15.826 + * @param start the start index, inclusive.
15.827 + * @param end the end index, exclusive.
15.828 + * @return the specified subsequence.
15.829 + *
15.830 + * @throws IndexOutOfBoundsException
15.831 + * if <tt>start</tt> or <tt>end</tt> are negative,
15.832 + * if <tt>end</tt> is greater than <tt>length()</tt>,
15.833 + * or if <tt>start</tt> is greater than <tt>end</tt>
15.834 + * @spec JSR-51
15.835 + */
15.836 + public CharSequence subSequence(int start, int end) {
15.837 + return substring(start, end);
15.838 + }
15.839 +
15.840 + /**
15.841 + * Returns a new <code>String</code> that contains a subsequence of
15.842 + * characters currently contained in this sequence. The
15.843 + * substring begins at the specified <code>start</code> and
15.844 + * extends to the character at index <code>end - 1</code>.
15.845 + *
15.846 + * @param start The beginning index, inclusive.
15.847 + * @param end The ending index, exclusive.
15.848 + * @return The new string.
15.849 + * @throws StringIndexOutOfBoundsException if <code>start</code>
15.850 + * or <code>end</code> are negative or greater than
15.851 + * <code>length()</code>, or <code>start</code> is
15.852 + * greater than <code>end</code>.
15.853 + */
15.854 + public String substring(int start, int end) {
15.855 + if (start < 0)
15.856 + throw new StringIndexOutOfBoundsException(start);
15.857 + if (end > count)
15.858 + throw new StringIndexOutOfBoundsException(end);
15.859 + if (start > end)
15.860 + throw new StringIndexOutOfBoundsException(end - start);
15.861 + return new String(value, start, end - start);
15.862 + }
15.863 +
15.864 + /**
15.865 + * Inserts the string representation of a subarray of the {@code str}
15.866 + * array argument into this sequence. The subarray begins at the
15.867 + * specified {@code offset} and extends {@code len} {@code char}s.
15.868 + * The characters of the subarray are inserted into this sequence at
15.869 + * the position indicated by {@code index}. The length of this
15.870 + * sequence increases by {@code len} {@code char}s.
15.871 + *
15.872 + * @param index position at which to insert subarray.
15.873 + * @param str A {@code char} array.
15.874 + * @param offset the index of the first {@code char} in subarray to
15.875 + * be inserted.
15.876 + * @param len the number of {@code char}s in the subarray to
15.877 + * be inserted.
15.878 + * @return This object
15.879 + * @throws StringIndexOutOfBoundsException if {@code index}
15.880 + * is negative or greater than {@code length()}, or
15.881 + * {@code offset} or {@code len} are negative, or
15.882 + * {@code (offset+len)} is greater than
15.883 + * {@code str.length}.
15.884 + */
15.885 + public AbstractStringBuilder insert(int index, char[] str, int offset,
15.886 + int len)
15.887 + {
15.888 + if ((index < 0) || (index > length()))
15.889 + throw new StringIndexOutOfBoundsException(index);
15.890 + if ((offset < 0) || (len < 0) || (offset > str.length - len))
15.891 + throw new StringIndexOutOfBoundsException(
15.892 + "offset " + offset + ", len " + len + ", str.length "
15.893 + + str.length);
15.894 + ensureCapacityInternal(count + len);
15.895 + arraycopy(value, index, value, index + len, count - index);
15.896 + arraycopy(str, offset, value, index, len);
15.897 + count += len;
15.898 + return this;
15.899 + }
15.900 +
15.901 + /**
15.902 + * Inserts the string representation of the {@code Object}
15.903 + * argument into this character sequence.
15.904 + * <p>
15.905 + * The overall effect is exactly as if the second argument were
15.906 + * converted to a string by the method {@link String#valueOf(Object)},
15.907 + * and the characters of that string were then
15.908 + * {@link #insert(int,String) inserted} into this character
15.909 + * sequence at the indicated offset.
15.910 + * <p>
15.911 + * The {@code offset} argument must be greater than or equal to
15.912 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.913 + * of this sequence.
15.914 + *
15.915 + * @param offset the offset.
15.916 + * @param obj an {@code Object}.
15.917 + * @return a reference to this object.
15.918 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.919 + */
15.920 + public AbstractStringBuilder insert(int offset, Object obj) {
15.921 + return insert(offset, String.valueOf(obj));
15.922 + }
15.923 +
15.924 + /**
15.925 + * Inserts the string into this character sequence.
15.926 + * <p>
15.927 + * The characters of the {@code String} argument are inserted, in
15.928 + * order, into this sequence at the indicated offset, moving up any
15.929 + * characters originally above that position and increasing the length
15.930 + * of this sequence by the length of the argument. If
15.931 + * {@code str} is {@code null}, then the four characters
15.932 + * {@code "null"} are inserted into this sequence.
15.933 + * <p>
15.934 + * The character at index <i>k</i> in the new character sequence is
15.935 + * equal to:
15.936 + * <ul>
15.937 + * <li>the character at index <i>k</i> in the old character sequence, if
15.938 + * <i>k</i> is less than {@code offset}
15.939 + * <li>the character at index <i>k</i>{@code -offset} in the
15.940 + * argument {@code str}, if <i>k</i> is not less than
15.941 + * {@code offset} but is less than {@code offset+str.length()}
15.942 + * <li>the character at index <i>k</i>{@code -str.length()} in the
15.943 + * old character sequence, if <i>k</i> is not less than
15.944 + * {@code offset+str.length()}
15.945 + * </ul><p>
15.946 + * The {@code offset} argument must be greater than or equal to
15.947 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.948 + * of this sequence.
15.949 + *
15.950 + * @param offset the offset.
15.951 + * @param str a string.
15.952 + * @return a reference to this object.
15.953 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.954 + */
15.955 + public AbstractStringBuilder insert(int offset, String str) {
15.956 + if ((offset < 0) || (offset > length()))
15.957 + throw new StringIndexOutOfBoundsException(offset);
15.958 + if (str == null)
15.959 + str = "null";
15.960 + int len = str.length();
15.961 + ensureCapacityInternal(count + len);
15.962 + arraycopy(value, offset, value, offset + len, count - offset);
15.963 + str.getChars(value, offset);
15.964 + count += len;
15.965 + return this;
15.966 + }
15.967 +
15.968 + /**
15.969 + * Inserts the string representation of the {@code char} array
15.970 + * argument into this sequence.
15.971 + * <p>
15.972 + * The characters of the array argument are inserted into the
15.973 + * contents of this sequence at the position indicated by
15.974 + * {@code offset}. The length of this sequence increases by
15.975 + * the length of the argument.
15.976 + * <p>
15.977 + * The overall effect is exactly as if the second argument were
15.978 + * converted to a string by the method {@link String#valueOf(char[])},
15.979 + * and the characters of that string were then
15.980 + * {@link #insert(int,String) inserted} into this character
15.981 + * sequence at the indicated offset.
15.982 + * <p>
15.983 + * The {@code offset} argument must be greater than or equal to
15.984 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.985 + * of this sequence.
15.986 + *
15.987 + * @param offset the offset.
15.988 + * @param str a character array.
15.989 + * @return a reference to this object.
15.990 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.991 + */
15.992 + public AbstractStringBuilder insert(int offset, char[] str) {
15.993 + if ((offset < 0) || (offset > length()))
15.994 + throw new StringIndexOutOfBoundsException(offset);
15.995 + int len = str.length;
15.996 + ensureCapacityInternal(count + len);
15.997 + arraycopy(value, offset, value, offset + len, count - offset);
15.998 + arraycopy(str, 0, value, offset, len);
15.999 + count += len;
15.1000 + return this;
15.1001 + }
15.1002 +
15.1003 + /**
15.1004 + * Inserts the specified {@code CharSequence} into this sequence.
15.1005 + * <p>
15.1006 + * The characters of the {@code CharSequence} argument are inserted,
15.1007 + * in order, into this sequence at the indicated offset, moving up
15.1008 + * any characters originally above that position and increasing the length
15.1009 + * of this sequence by the length of the argument s.
15.1010 + * <p>
15.1011 + * The result of this method is exactly the same as if it were an
15.1012 + * invocation of this object's
15.1013 + * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
15.1014 + * method.
15.1015 + *
15.1016 + * <p>If {@code s} is {@code null}, then the four characters
15.1017 + * {@code "null"} are inserted into this sequence.
15.1018 + *
15.1019 + * @param dstOffset the offset.
15.1020 + * @param s the sequence to be inserted
15.1021 + * @return a reference to this object.
15.1022 + * @throws IndexOutOfBoundsException if the offset is invalid.
15.1023 + */
15.1024 + public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
15.1025 + if (s == null)
15.1026 + s = "null";
15.1027 + if (s instanceof String)
15.1028 + return this.insert(dstOffset, (String)s);
15.1029 + return this.insert(dstOffset, s, 0, s.length());
15.1030 + }
15.1031 +
15.1032 + /**
15.1033 + * Inserts a subsequence of the specified {@code CharSequence} into
15.1034 + * this sequence.
15.1035 + * <p>
15.1036 + * The subsequence of the argument {@code s} specified by
15.1037 + * {@code start} and {@code end} are inserted,
15.1038 + * in order, into this sequence at the specified destination offset, moving
15.1039 + * up any characters originally above that position. The length of this
15.1040 + * sequence is increased by {@code end - start}.
15.1041 + * <p>
15.1042 + * The character at index <i>k</i> in this sequence becomes equal to:
15.1043 + * <ul>
15.1044 + * <li>the character at index <i>k</i> in this sequence, if
15.1045 + * <i>k</i> is less than {@code dstOffset}
15.1046 + * <li>the character at index <i>k</i>{@code +start-dstOffset} in
15.1047 + * the argument {@code s}, if <i>k</i> is greater than or equal to
15.1048 + * {@code dstOffset} but is less than {@code dstOffset+end-start}
15.1049 + * <li>the character at index <i>k</i>{@code -(end-start)} in this
15.1050 + * sequence, if <i>k</i> is greater than or equal to
15.1051 + * {@code dstOffset+end-start}
15.1052 + * </ul><p>
15.1053 + * The {@code dstOffset} argument must be greater than or equal to
15.1054 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1055 + * of this sequence.
15.1056 + * <p>The start argument must be nonnegative, and not greater than
15.1057 + * {@code end}.
15.1058 + * <p>The end argument must be greater than or equal to
15.1059 + * {@code start}, and less than or equal to the length of s.
15.1060 + *
15.1061 + * <p>If {@code s} is {@code null}, then this method inserts
15.1062 + * characters as if the s parameter was a sequence containing the four
15.1063 + * characters {@code "null"}.
15.1064 + *
15.1065 + * @param dstOffset the offset in this sequence.
15.1066 + * @param s the sequence to be inserted.
15.1067 + * @param start the starting index of the subsequence to be inserted.
15.1068 + * @param end the end index of the subsequence to be inserted.
15.1069 + * @return a reference to this object.
15.1070 + * @throws IndexOutOfBoundsException if {@code dstOffset}
15.1071 + * is negative or greater than {@code this.length()}, or
15.1072 + * {@code start} or {@code end} are negative, or
15.1073 + * {@code start} is greater than {@code end} or
15.1074 + * {@code end} is greater than {@code s.length()}
15.1075 + */
15.1076 + public AbstractStringBuilder insert(int dstOffset, CharSequence s,
15.1077 + int start, int end) {
15.1078 + if (s == null)
15.1079 + s = "null";
15.1080 + if ((dstOffset < 0) || (dstOffset > this.length()))
15.1081 + throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
15.1082 + if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
15.1083 + throw new IndexOutOfBoundsException(
15.1084 + "start " + start + ", end " + end + ", s.length() "
15.1085 + + s.length());
15.1086 + int len = end - start;
15.1087 + ensureCapacityInternal(count + len);
15.1088 + arraycopy(value, dstOffset, value, dstOffset + len,
15.1089 + count - dstOffset);
15.1090 + for (int i=start; i<end; i++)
15.1091 + value[dstOffset++] = s.charAt(i);
15.1092 + count += len;
15.1093 + return this;
15.1094 + }
15.1095 +
15.1096 + /**
15.1097 + * Inserts the string representation of the {@code boolean}
15.1098 + * argument into this sequence.
15.1099 + * <p>
15.1100 + * The overall effect is exactly as if the second argument were
15.1101 + * converted to a string by the method {@link String#valueOf(boolean)},
15.1102 + * and the characters of that string were then
15.1103 + * {@link #insert(int,String) inserted} into this character
15.1104 + * sequence at the indicated offset.
15.1105 + * <p>
15.1106 + * The {@code offset} argument must be greater than or equal to
15.1107 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1108 + * of this sequence.
15.1109 + *
15.1110 + * @param offset the offset.
15.1111 + * @param b a {@code boolean}.
15.1112 + * @return a reference to this object.
15.1113 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1114 + */
15.1115 + public AbstractStringBuilder insert(int offset, boolean b) {
15.1116 + return insert(offset, String.valueOf(b));
15.1117 + }
15.1118 +
15.1119 + /**
15.1120 + * Inserts the string representation of the {@code char}
15.1121 + * argument into this sequence.
15.1122 + * <p>
15.1123 + * The overall effect is exactly as if the second argument were
15.1124 + * converted to a string by the method {@link String#valueOf(char)},
15.1125 + * and the character in that string were then
15.1126 + * {@link #insert(int,String) inserted} into this character
15.1127 + * sequence at the indicated offset.
15.1128 + * <p>
15.1129 + * The {@code offset} argument must be greater than or equal to
15.1130 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1131 + * of this sequence.
15.1132 + *
15.1133 + * @param offset the offset.
15.1134 + * @param c a {@code char}.
15.1135 + * @return a reference to this object.
15.1136 + * @throws IndexOutOfBoundsException if the offset is invalid.
15.1137 + */
15.1138 + public AbstractStringBuilder insert(int offset, char c) {
15.1139 + ensureCapacityInternal(count + 1);
15.1140 + arraycopy(value, offset, value, offset + 1, count - offset);
15.1141 + value[offset] = c;
15.1142 + count += 1;
15.1143 + return this;
15.1144 + }
15.1145 +
15.1146 + /**
15.1147 + * Inserts the string representation of the second {@code int}
15.1148 + * argument into this sequence.
15.1149 + * <p>
15.1150 + * The overall effect is exactly as if the second argument were
15.1151 + * converted to a string by the method {@link String#valueOf(int)},
15.1152 + * and the characters of that string were then
15.1153 + * {@link #insert(int,String) inserted} into this character
15.1154 + * sequence at the indicated offset.
15.1155 + * <p>
15.1156 + * The {@code offset} argument must be greater than or equal to
15.1157 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1158 + * of this sequence.
15.1159 + *
15.1160 + * @param offset the offset.
15.1161 + * @param i an {@code int}.
15.1162 + * @return a reference to this object.
15.1163 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1164 + */
15.1165 + public AbstractStringBuilder insert(int offset, int i) {
15.1166 + return insert(offset, String.valueOf(i));
15.1167 + }
15.1168 +
15.1169 + /**
15.1170 + * Inserts the string representation of the {@code long}
15.1171 + * argument into this sequence.
15.1172 + * <p>
15.1173 + * The overall effect is exactly as if the second argument were
15.1174 + * converted to a string by the method {@link String#valueOf(long)},
15.1175 + * and the characters of that string were then
15.1176 + * {@link #insert(int,String) inserted} into this character
15.1177 + * sequence at the indicated offset.
15.1178 + * <p>
15.1179 + * The {@code offset} argument must be greater than or equal to
15.1180 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1181 + * of this sequence.
15.1182 + *
15.1183 + * @param offset the offset.
15.1184 + * @param l a {@code long}.
15.1185 + * @return a reference to this object.
15.1186 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1187 + */
15.1188 + public AbstractStringBuilder insert(int offset, long l) {
15.1189 + return insert(offset, String.valueOf(l));
15.1190 + }
15.1191 +
15.1192 + /**
15.1193 + * Inserts the string representation of the {@code float}
15.1194 + * argument into this sequence.
15.1195 + * <p>
15.1196 + * The overall effect is exactly as if the second argument were
15.1197 + * converted to a string by the method {@link String#valueOf(float)},
15.1198 + * and the characters of that string were then
15.1199 + * {@link #insert(int,String) inserted} into this character
15.1200 + * sequence at the indicated offset.
15.1201 + * <p>
15.1202 + * The {@code offset} argument must be greater than or equal to
15.1203 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1204 + * of this sequence.
15.1205 + *
15.1206 + * @param offset the offset.
15.1207 + * @param f a {@code float}.
15.1208 + * @return a reference to this object.
15.1209 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1210 + */
15.1211 + public AbstractStringBuilder insert(int offset, float f) {
15.1212 + return insert(offset, String.valueOf(f));
15.1213 + }
15.1214 +
15.1215 + /**
15.1216 + * Inserts the string representation of the {@code double}
15.1217 + * argument into this sequence.
15.1218 + * <p>
15.1219 + * The overall effect is exactly as if the second argument were
15.1220 + * converted to a string by the method {@link String#valueOf(double)},
15.1221 + * and the characters of that string were then
15.1222 + * {@link #insert(int,String) inserted} into this character
15.1223 + * sequence at the indicated offset.
15.1224 + * <p>
15.1225 + * The {@code offset} argument must be greater than or equal to
15.1226 + * {@code 0}, and less than or equal to the {@linkplain #length() length}
15.1227 + * of this sequence.
15.1228 + *
15.1229 + * @param offset the offset.
15.1230 + * @param d a {@code double}.
15.1231 + * @return a reference to this object.
15.1232 + * @throws StringIndexOutOfBoundsException if the offset is invalid.
15.1233 + */
15.1234 + public AbstractStringBuilder insert(int offset, double d) {
15.1235 + return insert(offset, String.valueOf(d));
15.1236 + }
15.1237 +
15.1238 + /**
15.1239 + * Returns the index within this string of the first occurrence of the
15.1240 + * specified substring. The integer returned is the smallest value
15.1241 + * <i>k</i> such that:
15.1242 + * <blockquote><pre>
15.1243 + * this.toString().startsWith(str, <i>k</i>)
15.1244 + * </pre></blockquote>
15.1245 + * is <code>true</code>.
15.1246 + *
15.1247 + * @param str any string.
15.1248 + * @return if the string argument occurs as a substring within this
15.1249 + * object, then the index of the first character of the first
15.1250 + * such substring is returned; if it does not occur as a
15.1251 + * substring, <code>-1</code> is returned.
15.1252 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1253 + * <code>null</code>.
15.1254 + */
15.1255 + public int indexOf(String str) {
15.1256 + return indexOf(str, 0);
15.1257 + }
15.1258 +
15.1259 + /**
15.1260 + * Returns the index within this string of the first occurrence of the
15.1261 + * specified substring, starting at the specified index. The integer
15.1262 + * returned is the smallest value <tt>k</tt> for which:
15.1263 + * <blockquote><pre>
15.1264 + * k >= Math.min(fromIndex, str.length()) &&
15.1265 + * this.toString().startsWith(str, k)
15.1266 + * </pre></blockquote>
15.1267 + * If no such value of <i>k</i> exists, then -1 is returned.
15.1268 + *
15.1269 + * @param str the substring for which to search.
15.1270 + * @param fromIndex the index from which to start the search.
15.1271 + * @return the index within this string of the first occurrence of the
15.1272 + * specified substring, starting at the specified index.
15.1273 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1274 + * <code>null</code>.
15.1275 + */
15.1276 + public int indexOf(String str, int fromIndex) {
15.1277 + return toString().indexOf(str, fromIndex);
15.1278 + }
15.1279 +
15.1280 + /**
15.1281 + * Returns the index within this string of the rightmost occurrence
15.1282 + * of the specified substring. The rightmost empty string "" is
15.1283 + * considered to occur at the index value <code>this.length()</code>.
15.1284 + * The returned index is the largest value <i>k</i> such that
15.1285 + * <blockquote><pre>
15.1286 + * this.toString().startsWith(str, k)
15.1287 + * </pre></blockquote>
15.1288 + * is true.
15.1289 + *
15.1290 + * @param str the substring to search for.
15.1291 + * @return if the string argument occurs one or more times as a substring
15.1292 + * within this object, then the index of the first character of
15.1293 + * the last such substring is returned. If it does not occur as
15.1294 + * a substring, <code>-1</code> is returned.
15.1295 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1296 + * <code>null</code>.
15.1297 + */
15.1298 + public int lastIndexOf(String str) {
15.1299 + return lastIndexOf(str, count);
15.1300 + }
15.1301 +
15.1302 + /**
15.1303 + * Returns the index within this string of the last occurrence of the
15.1304 + * specified substring. The integer returned is the largest value <i>k</i>
15.1305 + * such that:
15.1306 + * <blockquote><pre>
15.1307 + * k <= Math.min(fromIndex, str.length()) &&
15.1308 + * this.toString().startsWith(str, k)
15.1309 + * </pre></blockquote>
15.1310 + * If no such value of <i>k</i> exists, then -1 is returned.
15.1311 + *
15.1312 + * @param str the substring to search for.
15.1313 + * @param fromIndex the index to start the search from.
15.1314 + * @return the index within this sequence of the last occurrence of the
15.1315 + * specified substring.
15.1316 + * @throws java.lang.NullPointerException if <code>str</code> is
15.1317 + * <code>null</code>.
15.1318 + */
15.1319 + public int lastIndexOf(String str, int fromIndex) {
15.1320 + return String.lastIndexOf(value, 0, count,
15.1321 + str.toCharArray(), 0, str.length(), fromIndex);
15.1322 + }
15.1323 +
15.1324 + /**
15.1325 + * Causes this character sequence to be replaced by the reverse of
15.1326 + * the sequence. If there are any surrogate pairs included in the
15.1327 + * sequence, these are treated as single characters for the
15.1328 + * reverse operation. Thus, the order of the high-low surrogates
15.1329 + * is never reversed.
15.1330 + *
15.1331 + * Let <i>n</i> be the character length of this character sequence
15.1332 + * (not the length in <code>char</code> values) just prior to
15.1333 + * execution of the <code>reverse</code> method. Then the
15.1334 + * character at index <i>k</i> in the new character sequence is
15.1335 + * equal to the character at index <i>n-k-1</i> in the old
15.1336 + * character sequence.
15.1337 + *
15.1338 + * <p>Note that the reverse operation may result in producing
15.1339 + * surrogate pairs that were unpaired low-surrogates and
15.1340 + * high-surrogates before the operation. For example, reversing
15.1341 + * "\uDC00\uD800" produces "\uD800\uDC00" which is
15.1342 + * a valid surrogate pair.
15.1343 + *
15.1344 + * @return a reference to this object.
15.1345 + */
15.1346 + public AbstractStringBuilder reverse() {
15.1347 + boolean hasSurrogate = false;
15.1348 + int n = count - 1;
15.1349 + for (int j = (n-1) >> 1; j >= 0; --j) {
15.1350 + char temp = value[j];
15.1351 + char temp2 = value[n - j];
15.1352 + if (!hasSurrogate) {
15.1353 + hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
15.1354 + || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
15.1355 + }
15.1356 + value[j] = temp2;
15.1357 + value[n - j] = temp;
15.1358 + }
15.1359 + if (hasSurrogate) {
15.1360 + // Reverse back all valid surrogate pairs
15.1361 + for (int i = 0; i < count - 1; i++) {
15.1362 + char c2 = value[i];
15.1363 + if (Character.isLowSurrogate(c2)) {
15.1364 + char c1 = value[i + 1];
15.1365 + if (Character.isHighSurrogate(c1)) {
15.1366 + value[i++] = c1;
15.1367 + value[i] = c2;
15.1368 + }
15.1369 + }
15.1370 + }
15.1371 + }
15.1372 + return this;
15.1373 + }
15.1374 +
15.1375 + /**
15.1376 + * Returns a string representing the data in this sequence.
15.1377 + * A new <code>String</code> object is allocated and initialized to
15.1378 + * contain the character sequence currently represented by this
15.1379 + * object. This <code>String</code> is then returned. Subsequent
15.1380 + * changes to this sequence do not affect the contents of the
15.1381 + * <code>String</code>.
15.1382 + *
15.1383 + * @return a string representation of this sequence of characters.
15.1384 + */
15.1385 + public abstract String toString();
15.1386 +
15.1387 + /**
15.1388 + * Needed by <tt>String</tt> for the contentEquals method.
15.1389 + */
15.1390 + final char[] getValue() {
15.1391 + return value;
15.1392 + }
15.1393 +
15.1394 + static char[] copyOfRange(char[] original, int from, int to) {
15.1395 + int newLength = to - from;
15.1396 + if (newLength < 0) {
15.1397 + throw new IllegalArgumentException(from + " > " + to);
15.1398 + }
15.1399 + char[] copy = new char[newLength];
15.1400 + arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
15.1401 + return copy;
15.1402 + }
15.1403 +
15.1404 + static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
15.1405 + if (srcBegin < dstBegin) {
15.1406 + while (count-- > 0) {
15.1407 + dst[dstBegin + count] = value[srcBegin + count];
15.1408 + }
15.1409 + } else {
15.1410 + while (count-- > 0) {
15.1411 + dst[dstBegin++] = value[srcBegin++];
15.1412 + }
15.1413 + }
15.1414 + }
15.1415 +
15.1416 + // access system property
15.1417 + static String getProperty(String nm) {
15.1418 + return null;
15.1419 + }
15.1420 +
15.1421 + static char[] copyOf(char[] original, int newLength) {
15.1422 + char[] copy = new char[newLength];
15.1423 + arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
15.1424 + return copy;
15.1425 + }
15.1426 +
15.1427 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/emul/mini/src/main/java/java/lang/Appendable.java Wed Jan 23 20:39:23 2013 +0100
16.3 @@ -0,0 +1,121 @@
16.4 +/*
16.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16.7 + *
16.8 + * This code is free software; you can redistribute it and/or modify it
16.9 + * under the terms of the GNU General Public License version 2 only, as
16.10 + * published by the Free Software Foundation. Oracle designates this
16.11 + * particular file as subject to the "Classpath" exception as provided
16.12 + * by Oracle in the LICENSE file that accompanied this code.
16.13 + *
16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16.17 + * version 2 for more details (a copy is included in the LICENSE file that
16.18 + * accompanied this code).
16.19 + *
16.20 + * You should have received a copy of the GNU General Public License version
16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16.23 + *
16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16.25 + * or visit www.oracle.com if you need additional information or have any
16.26 + * questions.
16.27 + */
16.28 +
16.29 +package java.lang;
16.30 +
16.31 +import java.io.IOException;
16.32 +
16.33 +/**
16.34 + * An object to which <tt>char</tt> sequences and values can be appended. The
16.35 + * <tt>Appendable</tt> interface must be implemented by any class whose
16.36 + * instances are intended to receive formatted output from a {@link
16.37 + * java.util.Formatter}.
16.38 + *
16.39 + * <p> The characters to be appended should be valid Unicode characters as
16.40 + * described in <a href="Character.html#unicode">Unicode Character
16.41 + * Representation</a>. Note that supplementary characters may be composed of
16.42 + * multiple 16-bit <tt>char</tt> values.
16.43 + *
16.44 + * <p> Appendables are not necessarily safe for multithreaded access. Thread
16.45 + * safety is the responsibility of classes that extend and implement this
16.46 + * interface.
16.47 + *
16.48 + * <p> Since this interface may be implemented by existing classes
16.49 + * with different styles of error handling there is no guarantee that
16.50 + * errors will be propagated to the invoker.
16.51 + *
16.52 + * @since 1.5
16.53 + */
16.54 +public interface Appendable {
16.55 +
16.56 + /**
16.57 + * Appends the specified character sequence to this <tt>Appendable</tt>.
16.58 + *
16.59 + * <p> Depending on which class implements the character sequence
16.60 + * <tt>csq</tt>, the entire sequence may not be appended. For
16.61 + * instance, if <tt>csq</tt> is a {@link java.nio.CharBuffer} then
16.62 + * the subsequence to append is defined by the buffer's position and limit.
16.63 + *
16.64 + * @param csq
16.65 + * The character sequence to append. If <tt>csq</tt> is
16.66 + * <tt>null</tt>, then the four characters <tt>"null"</tt> are
16.67 + * appended to this Appendable.
16.68 + *
16.69 + * @return A reference to this <tt>Appendable</tt>
16.70 + *
16.71 + * @throws IOException
16.72 + * If an I/O error occurs
16.73 + */
16.74 + Appendable append(CharSequence csq) throws IOException;
16.75 +
16.76 + /**
16.77 + * Appends a subsequence of the specified character sequence to this
16.78 + * <tt>Appendable</tt>.
16.79 + *
16.80 + * <p> An invocation of this method of the form <tt>out.append(csq, start,
16.81 + * end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
16.82 + * exactly the same way as the invocation
16.83 + *
16.84 + * <pre>
16.85 + * out.append(csq.subSequence(start, end)) </pre>
16.86 + *
16.87 + * @param csq
16.88 + * The character sequence from which a subsequence will be
16.89 + * appended. If <tt>csq</tt> is <tt>null</tt>, then characters
16.90 + * will be appended as if <tt>csq</tt> contained the four
16.91 + * characters <tt>"null"</tt>.
16.92 + *
16.93 + * @param start
16.94 + * The index of the first character in the subsequence
16.95 + *
16.96 + * @param end
16.97 + * The index of the character following the last character in the
16.98 + * subsequence
16.99 + *
16.100 + * @return A reference to this <tt>Appendable</tt>
16.101 + *
16.102 + * @throws IndexOutOfBoundsException
16.103 + * If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
16.104 + * is greater than <tt>end</tt>, or <tt>end</tt> is greater than
16.105 + * <tt>csq.length()</tt>
16.106 + *
16.107 + * @throws IOException
16.108 + * If an I/O error occurs
16.109 + */
16.110 + Appendable append(CharSequence csq, int start, int end) throws IOException;
16.111 +
16.112 + /**
16.113 + * Appends the specified character to this <tt>Appendable</tt>.
16.114 + *
16.115 + * @param c
16.116 + * The character to append
16.117 + *
16.118 + * @return A reference to this <tt>Appendable</tt>
16.119 + *
16.120 + * @throws IOException
16.121 + * If an I/O error occurs
16.122 + */
16.123 + Appendable append(char c) throws IOException;
16.124 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/emul/mini/src/main/java/java/lang/ArrayIndexOutOfBoundsException.java Wed Jan 23 20:39:23 2013 +0100
17.3 @@ -0,0 +1,67 @@
17.4 +/*
17.5 + * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
17.7 + *
17.8 + * This code is free software; you can redistribute it and/or modify it
17.9 + * under the terms of the GNU General Public License version 2 only, as
17.10 + * published by the Free Software Foundation. Oracle designates this
17.11 + * particular file as subject to the "Classpath" exception as provided
17.12 + * by Oracle in the LICENSE file that accompanied this code.
17.13 + *
17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17.17 + * version 2 for more details (a copy is included in the LICENSE file that
17.18 + * accompanied this code).
17.19 + *
17.20 + * You should have received a copy of the GNU General Public License version
17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17.23 + *
17.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
17.25 + * or visit www.oracle.com if you need additional information or have any
17.26 + * questions.
17.27 + */
17.28 +
17.29 +package java.lang;
17.30 +
17.31 +/**
17.32 + * Thrown to indicate that an array has been accessed with an
17.33 + * illegal index. The index is either negative or greater than or
17.34 + * equal to the size of the array.
17.35 + *
17.36 + * @author unascribed
17.37 + * @since JDK1.0
17.38 + */
17.39 +public
17.40 +class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
17.41 + private static final long serialVersionUID = -5116101128118950844L;
17.42 +
17.43 + /**
17.44 + * Constructs an <code>ArrayIndexOutOfBoundsException</code> with no
17.45 + * detail message.
17.46 + */
17.47 + public ArrayIndexOutOfBoundsException() {
17.48 + super();
17.49 + }
17.50 +
17.51 + /**
17.52 + * Constructs a new <code>ArrayIndexOutOfBoundsException</code>
17.53 + * class with an argument indicating the illegal index.
17.54 + *
17.55 + * @param index the illegal index.
17.56 + */
17.57 + public ArrayIndexOutOfBoundsException(int index) {
17.58 + super("Array index out of range: " + index);
17.59 + }
17.60 +
17.61 + /**
17.62 + * Constructs an <code>ArrayIndexOutOfBoundsException</code> class
17.63 + * with the specified detail message.
17.64 + *
17.65 + * @param s the detail message.
17.66 + */
17.67 + public ArrayIndexOutOfBoundsException(String s) {
17.68 + super(s);
17.69 + }
17.70 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
18.2 +++ b/emul/mini/src/main/java/java/lang/AssertionError.java Wed Jan 23 20:39:23 2013 +0100
18.3 @@ -0,0 +1,167 @@
18.4 +/*
18.5 + * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
18.7 + *
18.8 + * This code is free software; you can redistribute it and/or modify it
18.9 + * under the terms of the GNU General Public License version 2 only, as
18.10 + * published by the Free Software Foundation. Oracle designates this
18.11 + * particular file as subject to the "Classpath" exception as provided
18.12 + * by Oracle in the LICENSE file that accompanied this code.
18.13 + *
18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18.17 + * version 2 for more details (a copy is included in the LICENSE file that
18.18 + * accompanied this code).
18.19 + *
18.20 + * You should have received a copy of the GNU General Public License version
18.21 + * 2 along with this work; if not, write to the Free Software Foundation,
18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18.23 + *
18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
18.25 + * or visit www.oracle.com if you need additional information or have any
18.26 + * questions.
18.27 + */
18.28 +
18.29 +package java.lang;
18.30 +
18.31 +/**
18.32 + * Thrown to indicate that an assertion has failed.
18.33 + *
18.34 + * <p>The seven one-argument public constructors provided by this
18.35 + * class ensure that the assertion error returned by the invocation:
18.36 + * <pre>
18.37 + * new AssertionError(<i>expression</i>)
18.38 + * </pre>
18.39 + * has as its detail message the <i>string conversion</i> of
18.40 + * <i>expression</i> (as defined in section 15.18.1.1 of
18.41 + * <cite>The Java™ Language Specification</cite>),
18.42 + * regardless of the type of <i>expression</i>.
18.43 + *
18.44 + * @since 1.4
18.45 + */
18.46 +public class AssertionError extends Error {
18.47 + private static final long serialVersionUID = -5013299493970297370L;
18.48 +
18.49 + /**
18.50 + * Constructs an AssertionError with no detail message.
18.51 + */
18.52 + public AssertionError() {
18.53 + }
18.54 +
18.55 + /**
18.56 + * This internal constructor does no processing on its string argument,
18.57 + * even if it is a null reference. The public constructors will
18.58 + * never call this constructor with a null argument.
18.59 + */
18.60 + private AssertionError(String detailMessage) {
18.61 + super(detailMessage);
18.62 + }
18.63 +
18.64 + /**
18.65 + * Constructs an AssertionError with its detail message derived
18.66 + * from the specified object, which is converted to a string as
18.67 + * defined in section 15.18.1.1 of
18.68 + * <cite>The Java™ Language Specification</cite>.
18.69 + *<p>
18.70 + * If the specified object is an instance of {@code Throwable}, it
18.71 + * becomes the <i>cause</i> of the newly constructed assertion error.
18.72 + *
18.73 + * @param detailMessage value to be used in constructing detail message
18.74 + * @see Throwable#getCause()
18.75 + */
18.76 + public AssertionError(Object detailMessage) {
18.77 + this("" + detailMessage);
18.78 + if (detailMessage instanceof Throwable)
18.79 + initCause((Throwable) detailMessage);
18.80 + }
18.81 +
18.82 + /**
18.83 + * Constructs an AssertionError with its detail message derived
18.84 + * from the specified <code>boolean</code>, which is converted to
18.85 + * a string as defined in section 15.18.1.1 of
18.86 + * <cite>The Java™ Language Specification</cite>.
18.87 + *
18.88 + * @param detailMessage value to be used in constructing detail message
18.89 + */
18.90 + public AssertionError(boolean detailMessage) {
18.91 + this("" + detailMessage);
18.92 + }
18.93 +
18.94 + /**
18.95 + * Constructs an AssertionError with its detail message derived
18.96 + * from the specified <code>char</code>, which is converted to a
18.97 + * string as defined in section 15.18.1.1 of
18.98 + * <cite>The Java™ Language Specification</cite>.
18.99 + *
18.100 + * @param detailMessage value to be used in constructing detail message
18.101 + */
18.102 + public AssertionError(char detailMessage) {
18.103 + this("" + detailMessage);
18.104 + }
18.105 +
18.106 + /**
18.107 + * Constructs an AssertionError with its detail message derived
18.108 + * from the specified <code>int</code>, which is converted to a
18.109 + * string as defined in section 15.18.1.1 of
18.110 + * <cite>The Java™ Language Specification</cite>.
18.111 + *
18.112 + * @param detailMessage value to be used in constructing detail message
18.113 + */
18.114 + public AssertionError(int detailMessage) {
18.115 + this("" + detailMessage);
18.116 + }
18.117 +
18.118 + /**
18.119 + * Constructs an AssertionError with its detail message derived
18.120 + * from the specified <code>long</code>, which is converted to a
18.121 + * string as defined in section 15.18.1.1 of
18.122 + * <cite>The Java™ Language Specification</cite>.
18.123 + *
18.124 + * @param detailMessage value to be used in constructing detail message
18.125 + */
18.126 + public AssertionError(long detailMessage) {
18.127 + this("" + detailMessage);
18.128 + }
18.129 +
18.130 + /**
18.131 + * Constructs an AssertionError with its detail message derived
18.132 + * from the specified <code>float</code>, which is converted to a
18.133 + * string as defined in section 15.18.1.1 of
18.134 + * <cite>The Java™ Language Specification</cite>.
18.135 + *
18.136 + * @param detailMessage value to be used in constructing detail message
18.137 + */
18.138 + public AssertionError(float detailMessage) {
18.139 + this("" + detailMessage);
18.140 + }
18.141 +
18.142 + /**
18.143 + * Constructs an AssertionError with its detail message derived
18.144 + * from the specified <code>double</code>, which is converted to a
18.145 + * string as defined in section 15.18.1.1 of
18.146 + * <cite>The Java™ Language Specification</cite>.
18.147 + *
18.148 + * @param detailMessage value to be used in constructing detail message
18.149 + */
18.150 + public AssertionError(double detailMessage) {
18.151 + this("" + detailMessage);
18.152 + }
18.153 +
18.154 + /**
18.155 + * Constructs a new {@code AssertionError} with the specified
18.156 + * detail message and cause.
18.157 + *
18.158 + * <p>Note that the detail message associated with
18.159 + * {@code cause} is <i>not</i> automatically incorporated in
18.160 + * this error's detail message.
18.161 + *
18.162 + * @param message the detail message, may be {@code null}
18.163 + * @param cause the cause, may be {@code null}
18.164 + *
18.165 + * @since 1.7
18.166 + */
18.167 + public AssertionError(String message, Throwable cause) {
18.168 + super(message, cause);
18.169 + }
18.170 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
19.2 +++ b/emul/mini/src/main/java/java/lang/AutoCloseable.java Wed Jan 23 20:39:23 2013 +0100
19.3 @@ -0,0 +1,72 @@
19.4 +/*
19.5 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
19.7 + *
19.8 + * This code is free software; you can redistribute it and/or modify it
19.9 + * under the terms of the GNU General Public License version 2 only, as
19.10 + * published by the Free Software Foundation. Oracle designates this
19.11 + * particular file as subject to the "Classpath" exception as provided
19.12 + * by Oracle in the LICENSE file that accompanied this code.
19.13 + *
19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19.17 + * version 2 for more details (a copy is included in the LICENSE file that
19.18 + * accompanied this code).
19.19 + *
19.20 + * You should have received a copy of the GNU General Public License version
19.21 + * 2 along with this work; if not, write to the Free Software Foundation,
19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19.23 + *
19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19.25 + * or visit www.oracle.com if you need additional information or have any
19.26 + * questions.
19.27 + */
19.28 +
19.29 +package java.lang;
19.30 +
19.31 +/**
19.32 + * A resource that must be closed when it is no longer needed.
19.33 + *
19.34 + * @author Josh Bloch
19.35 + * @since 1.7
19.36 + */
19.37 +public interface AutoCloseable {
19.38 + /**
19.39 + * Closes this resource, relinquishing any underlying resources.
19.40 + * This method is invoked automatically on objects managed by the
19.41 + * {@code try}-with-resources statement.
19.42 + *
19.43 + * <p>While this interface method is declared to throw {@code
19.44 + * Exception}, implementers are <em>strongly</em> encouraged to
19.45 + * declare concrete implementations of the {@code close} method to
19.46 + * throw more specific exceptions, or to throw no exception at all
19.47 + * if the close operation cannot fail.
19.48 + *
19.49 + * <p><em>Implementers of this interface are also strongly advised
19.50 + * to not have the {@code close} method throw {@link
19.51 + * InterruptedException}.</em>
19.52 + *
19.53 + * This exception interacts with a thread's interrupted status,
19.54 + * and runtime misbehavior is likely to occur if an {@code
19.55 + * InterruptedException} is {@linkplain Throwable#addSuppressed
19.56 + * suppressed}.
19.57 + *
19.58 + * More generally, if it would cause problems for an
19.59 + * exception to be suppressed, the {@code AutoCloseable.close}
19.60 + * method should not throw it.
19.61 + *
19.62 + * <p>Note that unlike the {@link java.io.Closeable#close close}
19.63 + * method of {@link java.io.Closeable}, this {@code close} method
19.64 + * is <em>not</em> required to be idempotent. In other words,
19.65 + * calling this {@code close} method more than once may have some
19.66 + * visible side effect, unlike {@code Closeable.close} which is
19.67 + * required to have no effect if called more than once.
19.68 + *
19.69 + * However, implementers of this interface are strongly encouraged
19.70 + * to make their {@code close} methods idempotent.
19.71 + *
19.72 + * @throws Exception if this resource cannot be closed
19.73 + */
19.74 + void close() throws Exception;
19.75 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
20.2 +++ b/emul/mini/src/main/java/java/lang/Boolean.java Wed Jan 23 20:39:23 2013 +0100
20.3 @@ -0,0 +1,282 @@
20.4 +/*
20.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
20.7 + *
20.8 + * This code is free software; you can redistribute it and/or modify it
20.9 + * under the terms of the GNU General Public License version 2 only, as
20.10 + * published by the Free Software Foundation. Oracle designates this
20.11 + * particular file as subject to the "Classpath" exception as provided
20.12 + * by Oracle in the LICENSE file that accompanied this code.
20.13 + *
20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20.17 + * version 2 for more details (a copy is included in the LICENSE file that
20.18 + * accompanied this code).
20.19 + *
20.20 + * You should have received a copy of the GNU General Public License version
20.21 + * 2 along with this work; if not, write to the Free Software Foundation,
20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20.23 + *
20.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20.25 + * or visit www.oracle.com if you need additional information or have any
20.26 + * questions.
20.27 + */
20.28 +
20.29 +package java.lang;
20.30 +
20.31 +/**
20.32 + * The Boolean class wraps a value of the primitive type
20.33 + * {@code boolean} in an object. An object of type
20.34 + * {@code Boolean} contains a single field whose type is
20.35 + * {@code boolean}.
20.36 + * <p>
20.37 + * In addition, this class provides many methods for
20.38 + * converting a {@code boolean} to a {@code String} and a
20.39 + * {@code String} to a {@code boolean}, as well as other
20.40 + * constants and methods useful when dealing with a
20.41 + * {@code boolean}.
20.42 + *
20.43 + * @author Arthur van Hoff
20.44 + * @since JDK1.0
20.45 + */
20.46 +public final class Boolean implements java.io.Serializable,
20.47 + Comparable<Boolean>
20.48 +{
20.49 + /**
20.50 + * The {@code Boolean} object corresponding to the primitive
20.51 + * value {@code true}.
20.52 + */
20.53 + public static final Boolean TRUE = new Boolean(true);
20.54 +
20.55 + /**
20.56 + * The {@code Boolean} object corresponding to the primitive
20.57 + * value {@code false}.
20.58 + */
20.59 + public static final Boolean FALSE = new Boolean(false);
20.60 +
20.61 + /**
20.62 + * The Class object representing the primitive type boolean.
20.63 + *
20.64 + * @since JDK1.1
20.65 + */
20.66 + public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean");
20.67 +
20.68 + /**
20.69 + * The value of the Boolean.
20.70 + *
20.71 + * @serial
20.72 + */
20.73 + private final boolean value;
20.74 +
20.75 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
20.76 + private static final long serialVersionUID = -3665804199014368530L;
20.77 +
20.78 + /**
20.79 + * Allocates a {@code Boolean} object representing the
20.80 + * {@code value} argument.
20.81 + *
20.82 + * <p><b>Note: It is rarely appropriate to use this constructor.
20.83 + * Unless a <i>new</i> instance is required, the static factory
20.84 + * {@link #valueOf(boolean)} is generally a better choice. It is
20.85 + * likely to yield significantly better space and time performance.</b>
20.86 + *
20.87 + * @param value the value of the {@code Boolean}.
20.88 + */
20.89 + public Boolean(boolean value) {
20.90 + this.value = value;
20.91 + }
20.92 +
20.93 + /**
20.94 + * Allocates a {@code Boolean} object representing the value
20.95 + * {@code true} if the string argument is not {@code null}
20.96 + * and is equal, ignoring case, to the string {@code "true"}.
20.97 + * Otherwise, allocate a {@code Boolean} object representing the
20.98 + * value {@code false}. Examples:<p>
20.99 + * {@code new Boolean("True")} produces a {@code Boolean} object
20.100 + * that represents {@code true}.<br>
20.101 + * {@code new Boolean("yes")} produces a {@code Boolean} object
20.102 + * that represents {@code false}.
20.103 + *
20.104 + * @param s the string to be converted to a {@code Boolean}.
20.105 + */
20.106 + public Boolean(String s) {
20.107 + this(toBoolean(s));
20.108 + }
20.109 +
20.110 + /**
20.111 + * Parses the string argument as a boolean. The {@code boolean}
20.112 + * returned represents the value {@code true} if the string argument
20.113 + * is not {@code null} and is equal, ignoring case, to the string
20.114 + * {@code "true"}. <p>
20.115 + * Example: {@code Boolean.parseBoolean("True")} returns {@code true}.<br>
20.116 + * Example: {@code Boolean.parseBoolean("yes")} returns {@code false}.
20.117 + *
20.118 + * @param s the {@code String} containing the boolean
20.119 + * representation to be parsed
20.120 + * @return the boolean represented by the string argument
20.121 + * @since 1.5
20.122 + */
20.123 + public static boolean parseBoolean(String s) {
20.124 + return toBoolean(s);
20.125 + }
20.126 +
20.127 + /**
20.128 + * Returns the value of this {@code Boolean} object as a boolean
20.129 + * primitive.
20.130 + *
20.131 + * @return the primitive {@code boolean} value of this object.
20.132 + */
20.133 + public boolean booleanValue() {
20.134 + return value;
20.135 + }
20.136 +
20.137 + /**
20.138 + * Returns a {@code Boolean} instance representing the specified
20.139 + * {@code boolean} value. If the specified {@code boolean} value
20.140 + * is {@code true}, this method returns {@code Boolean.TRUE};
20.141 + * if it is {@code false}, this method returns {@code Boolean.FALSE}.
20.142 + * If a new {@code Boolean} instance is not required, this method
20.143 + * should generally be used in preference to the constructor
20.144 + * {@link #Boolean(boolean)}, as this method is likely to yield
20.145 + * significantly better space and time performance.
20.146 + *
20.147 + * @param b a boolean value.
20.148 + * @return a {@code Boolean} instance representing {@code b}.
20.149 + * @since 1.4
20.150 + */
20.151 + public static Boolean valueOf(boolean b) {
20.152 + return (b ? TRUE : FALSE);
20.153 + }
20.154 +
20.155 + /**
20.156 + * Returns a {@code Boolean} with a value represented by the
20.157 + * specified string. The {@code Boolean} returned represents a
20.158 + * true value if the string argument is not {@code null}
20.159 + * and is equal, ignoring case, to the string {@code "true"}.
20.160 + *
20.161 + * @param s a string.
20.162 + * @return the {@code Boolean} value represented by the string.
20.163 + */
20.164 + public static Boolean valueOf(String s) {
20.165 + return toBoolean(s) ? TRUE : FALSE;
20.166 + }
20.167 +
20.168 + /**
20.169 + * Returns a {@code String} object representing the specified
20.170 + * boolean. If the specified boolean is {@code true}, then
20.171 + * the string {@code "true"} will be returned, otherwise the
20.172 + * string {@code "false"} will be returned.
20.173 + *
20.174 + * @param b the boolean to be converted
20.175 + * @return the string representation of the specified {@code boolean}
20.176 + * @since 1.4
20.177 + */
20.178 + public static String toString(boolean b) {
20.179 + return b ? "true" : "false";
20.180 + }
20.181 +
20.182 + /**
20.183 + * Returns a {@code String} object representing this Boolean's
20.184 + * value. If this object represents the value {@code true},
20.185 + * a string equal to {@code "true"} is returned. Otherwise, a
20.186 + * string equal to {@code "false"} is returned.
20.187 + *
20.188 + * @return a string representation of this object.
20.189 + */
20.190 + public String toString() {
20.191 + return value ? "true" : "false";
20.192 + }
20.193 +
20.194 + /**
20.195 + * Returns a hash code for this {@code Boolean} object.
20.196 + *
20.197 + * @return the integer {@code 1231} if this object represents
20.198 + * {@code true}; returns the integer {@code 1237} if this
20.199 + * object represents {@code false}.
20.200 + */
20.201 + public int hashCode() {
20.202 + return value ? 1231 : 1237;
20.203 + }
20.204 +
20.205 + /**
20.206 + * Returns {@code true} if and only if the argument is not
20.207 + * {@code null} and is a {@code Boolean} object that
20.208 + * represents the same {@code boolean} value as this object.
20.209 + *
20.210 + * @param obj the object to compare with.
20.211 + * @return {@code true} if the Boolean objects represent the
20.212 + * same value; {@code false} otherwise.
20.213 + */
20.214 + public boolean equals(Object obj) {
20.215 + if (obj instanceof Boolean) {
20.216 + return value == ((Boolean)obj).booleanValue();
20.217 + }
20.218 + return false;
20.219 + }
20.220 +
20.221 + /**
20.222 + * Returns {@code true} if and only if the system property
20.223 + * named by the argument exists and is equal to the string
20.224 + * {@code "true"}. (Beginning with version 1.0.2 of the
20.225 + * Java<small><sup>TM</sup></small> platform, the test of
20.226 + * this string is case insensitive.) A system property is accessible
20.227 + * through {@code getProperty}, a method defined by the
20.228 + * {@code System} class.
20.229 + * <p>
20.230 + * If there is no property with the specified name, or if the specified
20.231 + * name is empty or null, then {@code false} is returned.
20.232 + *
20.233 + * @param name the system property name.
20.234 + * @return the {@code boolean} value of the system property.
20.235 + * @see java.lang.System#getProperty(java.lang.String)
20.236 + * @see java.lang.System#getProperty(java.lang.String, java.lang.String)
20.237 + */
20.238 + public static boolean getBoolean(String name) {
20.239 + boolean result = false;
20.240 + try {
20.241 + result = toBoolean(AbstractStringBuilder.getProperty(name));
20.242 + } catch (IllegalArgumentException e) {
20.243 + } catch (NullPointerException e) {
20.244 + }
20.245 + return result;
20.246 + }
20.247 +
20.248 + /**
20.249 + * Compares this {@code Boolean} instance with another.
20.250 + *
20.251 + * @param b the {@code Boolean} instance to be compared
20.252 + * @return zero if this object represents the same boolean value as the
20.253 + * argument; a positive value if this object represents true
20.254 + * and the argument represents false; and a negative value if
20.255 + * this object represents false and the argument represents true
20.256 + * @throws NullPointerException if the argument is {@code null}
20.257 + * @see Comparable
20.258 + * @since 1.5
20.259 + */
20.260 + public int compareTo(Boolean b) {
20.261 + return compare(this.value, b.value);
20.262 + }
20.263 +
20.264 + /**
20.265 + * Compares two {@code boolean} values.
20.266 + * The value returned is identical to what would be returned by:
20.267 + * <pre>
20.268 + * Boolean.valueOf(x).compareTo(Boolean.valueOf(y))
20.269 + * </pre>
20.270 + *
20.271 + * @param x the first {@code boolean} to compare
20.272 + * @param y the second {@code boolean} to compare
20.273 + * @return the value {@code 0} if {@code x == y};
20.274 + * a value less than {@code 0} if {@code !x && y}; and
20.275 + * a value greater than {@code 0} if {@code x && !y}
20.276 + * @since 1.7
20.277 + */
20.278 + public static int compare(boolean x, boolean y) {
20.279 + return (x == y) ? 0 : (x ? 1 : -1);
20.280 + }
20.281 +
20.282 + private static boolean toBoolean(String name) {
20.283 + return ((name != null) && name.equalsIgnoreCase("true"));
20.284 + }
20.285 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
21.2 +++ b/emul/mini/src/main/java/java/lang/Byte.java Wed Jan 23 20:39:23 2013 +0100
21.3 @@ -0,0 +1,452 @@
21.4 +/*
21.5 + * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
21.7 + *
21.8 + * This code is free software; you can redistribute it and/or modify it
21.9 + * under the terms of the GNU General Public License version 2 only, as
21.10 + * published by the Free Software Foundation. Oracle designates this
21.11 + * particular file as subject to the "Classpath" exception as provided
21.12 + * by Oracle in the LICENSE file that accompanied this code.
21.13 + *
21.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
21.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21.17 + * version 2 for more details (a copy is included in the LICENSE file that
21.18 + * accompanied this code).
21.19 + *
21.20 + * You should have received a copy of the GNU General Public License version
21.21 + * 2 along with this work; if not, write to the Free Software Foundation,
21.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21.23 + *
21.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21.25 + * or visit www.oracle.com if you need additional information or have any
21.26 + * questions.
21.27 + */
21.28 +
21.29 +package java.lang;
21.30 +
21.31 +/**
21.32 + *
21.33 + * The {@code Byte} class wraps a value of primitive type {@code byte}
21.34 + * in an object. An object of type {@code Byte} contains a single
21.35 + * field whose type is {@code byte}.
21.36 + *
21.37 + * <p>In addition, this class provides several methods for converting
21.38 + * a {@code byte} to a {@code String} and a {@code String} to a {@code
21.39 + * byte}, as well as other constants and methods useful when dealing
21.40 + * with a {@code byte}.
21.41 + *
21.42 + * @author Nakul Saraiya
21.43 + * @author Joseph D. Darcy
21.44 + * @see java.lang.Number
21.45 + * @since JDK1.1
21.46 + */
21.47 +public final class Byte extends Number implements Comparable<Byte> {
21.48 +
21.49 + /**
21.50 + * A constant holding the minimum value a {@code byte} can
21.51 + * have, -2<sup>7</sup>.
21.52 + */
21.53 + public static final byte MIN_VALUE = -128;
21.54 +
21.55 + /**
21.56 + * A constant holding the maximum value a {@code byte} can
21.57 + * have, 2<sup>7</sup>-1.
21.58 + */
21.59 + public static final byte MAX_VALUE = 127;
21.60 +
21.61 + /**
21.62 + * The {@code Class} instance representing the primitive type
21.63 + * {@code byte}.
21.64 + */
21.65 + public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
21.66 +
21.67 + /**
21.68 + * Returns a new {@code String} object representing the
21.69 + * specified {@code byte}. The radix is assumed to be 10.
21.70 + *
21.71 + * @param b the {@code byte} to be converted
21.72 + * @return the string representation of the specified {@code byte}
21.73 + * @see java.lang.Integer#toString(int)
21.74 + */
21.75 + public static String toString(byte b) {
21.76 + return Integer.toString((int)b, 10);
21.77 + }
21.78 +
21.79 + private static class ByteCache {
21.80 + private ByteCache(){}
21.81 +
21.82 + static final Byte cache[] = new Byte[-(-128) + 127 + 1];
21.83 +
21.84 + static {
21.85 + for(int i = 0; i < cache.length; i++)
21.86 + cache[i] = new Byte((byte)(i - 128));
21.87 + }
21.88 + }
21.89 +
21.90 + /**
21.91 + * Returns a {@code Byte} instance representing the specified
21.92 + * {@code byte} value.
21.93 + * If a new {@code Byte} instance is not required, this method
21.94 + * should generally be used in preference to the constructor
21.95 + * {@link #Byte(byte)}, as this method is likely to yield
21.96 + * significantly better space and time performance since
21.97 + * all byte values are cached.
21.98 + *
21.99 + * @param b a byte value.
21.100 + * @return a {@code Byte} instance representing {@code b}.
21.101 + * @since 1.5
21.102 + */
21.103 + public static Byte valueOf(byte b) {
21.104 + final int offset = 128;
21.105 + return ByteCache.cache[(int)b + offset];
21.106 + }
21.107 +
21.108 + /**
21.109 + * Parses the string argument as a signed {@code byte} in the
21.110 + * radix specified by the second argument. The characters in the
21.111 + * string must all be digits, of the specified radix (as
21.112 + * determined by whether {@link java.lang.Character#digit(char,
21.113 + * int)} returns a nonnegative value) except that the first
21.114 + * character may be an ASCII minus sign {@code '-'}
21.115 + * (<code>'\u002D'</code>) to indicate a negative value or an
21.116 + * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to
21.117 + * indicate a positive value. The resulting {@code byte} value is
21.118 + * returned.
21.119 + *
21.120 + * <p>An exception of type {@code NumberFormatException} is
21.121 + * thrown if any of the following situations occurs:
21.122 + * <ul>
21.123 + * <li> The first argument is {@code null} or is a string of
21.124 + * length zero.
21.125 + *
21.126 + * <li> The radix is either smaller than {@link
21.127 + * java.lang.Character#MIN_RADIX} or larger than {@link
21.128 + * java.lang.Character#MAX_RADIX}.
21.129 + *
21.130 + * <li> Any character of the string is not a digit of the
21.131 + * specified radix, except that the first character may be a minus
21.132 + * sign {@code '-'} (<code>'\u002D'</code>) or plus sign
21.133 + * {@code '+'} (<code>'\u002B'</code>) provided that the
21.134 + * string is longer than length 1.
21.135 + *
21.136 + * <li> The value represented by the string is not a value of type
21.137 + * {@code byte}.
21.138 + * </ul>
21.139 + *
21.140 + * @param s the {@code String} containing the
21.141 + * {@code byte}
21.142 + * representation to be parsed
21.143 + * @param radix the radix to be used while parsing {@code s}
21.144 + * @return the {@code byte} value represented by the string
21.145 + * argument in the specified radix
21.146 + * @throws NumberFormatException If the string does
21.147 + * not contain a parsable {@code byte}.
21.148 + */
21.149 + public static byte parseByte(String s, int radix)
21.150 + throws NumberFormatException {
21.151 + int i = Integer.parseInt(s, radix);
21.152 + if (i < MIN_VALUE || i > MAX_VALUE)
21.153 + throw new NumberFormatException(
21.154 + "Value out of range. Value:\"" + s + "\" Radix:" + radix);
21.155 + return (byte)i;
21.156 + }
21.157 +
21.158 + /**
21.159 + * Parses the string argument as a signed decimal {@code
21.160 + * byte}. The characters in the string must all be decimal digits,
21.161 + * except that the first character may be an ASCII minus sign
21.162 + * {@code '-'} (<code>'\u002D'</code>) to indicate a negative
21.163 + * value or an ASCII plus sign {@code '+'}
21.164 + * (<code>'\u002B'</code>) to indicate a positive value. The
21.165 + * resulting {@code byte} value is returned, exactly as if the
21.166 + * argument and the radix 10 were given as arguments to the {@link
21.167 + * #parseByte(java.lang.String, int)} method.
21.168 + *
21.169 + * @param s a {@code String} containing the
21.170 + * {@code byte} representation to be parsed
21.171 + * @return the {@code byte} value represented by the
21.172 + * argument in decimal
21.173 + * @throws NumberFormatException if the string does not
21.174 + * contain a parsable {@code byte}.
21.175 + */
21.176 + public static byte parseByte(String s) throws NumberFormatException {
21.177 + return parseByte(s, 10);
21.178 + }
21.179 +
21.180 + /**
21.181 + * Returns a {@code Byte} object holding the value
21.182 + * extracted from the specified {@code String} when parsed
21.183 + * with the radix given by the second argument. The first argument
21.184 + * is interpreted as representing a signed {@code byte} in
21.185 + * the radix specified by the second argument, exactly as if the
21.186 + * argument were given to the {@link #parseByte(java.lang.String,
21.187 + * int)} method. The result is a {@code Byte} object that
21.188 + * represents the {@code byte} value specified by the string.
21.189 + *
21.190 + * <p> In other words, this method returns a {@code Byte} object
21.191 + * equal to the value of:
21.192 + *
21.193 + * <blockquote>
21.194 + * {@code new Byte(Byte.parseByte(s, radix))}
21.195 + * </blockquote>
21.196 + *
21.197 + * @param s the string to be parsed
21.198 + * @param radix the radix to be used in interpreting {@code s}
21.199 + * @return a {@code Byte} object holding the value
21.200 + * represented by the string argument in the
21.201 + * specified radix.
21.202 + * @throws NumberFormatException If the {@code String} does
21.203 + * not contain a parsable {@code byte}.
21.204 + */
21.205 + public static Byte valueOf(String s, int radix)
21.206 + throws NumberFormatException {
21.207 + return valueOf(parseByte(s, radix));
21.208 + }
21.209 +
21.210 + /**
21.211 + * Returns a {@code Byte} object holding the value
21.212 + * given by the specified {@code String}. The argument is
21.213 + * interpreted as representing a signed decimal {@code byte},
21.214 + * exactly as if the argument were given to the {@link
21.215 + * #parseByte(java.lang.String)} method. The result is a
21.216 + * {@code Byte} object that represents the {@code byte}
21.217 + * value specified by the string.
21.218 + *
21.219 + * <p> In other words, this method returns a {@code Byte} object
21.220 + * equal to the value of:
21.221 + *
21.222 + * <blockquote>
21.223 + * {@code new Byte(Byte.parseByte(s))}
21.224 + * </blockquote>
21.225 + *
21.226 + * @param s the string to be parsed
21.227 + * @return a {@code Byte} object holding the value
21.228 + * represented by the string argument
21.229 + * @throws NumberFormatException If the {@code String} does
21.230 + * not contain a parsable {@code byte}.
21.231 + */
21.232 + public static Byte valueOf(String s) throws NumberFormatException {
21.233 + return valueOf(s, 10);
21.234 + }
21.235 +
21.236 + /**
21.237 + * Decodes a {@code String} into a {@code Byte}.
21.238 + * Accepts decimal, hexadecimal, and octal numbers given by
21.239 + * the following grammar:
21.240 + *
21.241 + * <blockquote>
21.242 + * <dl>
21.243 + * <dt><i>DecodableString:</i>
21.244 + * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i>
21.245 + * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i>
21.246 + * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i>
21.247 + * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i>
21.248 + * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i>
21.249 + * <p>
21.250 + * <dt><i>Sign:</i>
21.251 + * <dd>{@code -}
21.252 + * <dd>{@code +}
21.253 + * </dl>
21.254 + * </blockquote>
21.255 + *
21.256 + * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i>
21.257 + * are as defined in section 3.10.1 of
21.258 + * <cite>The Java™ Language Specification</cite>,
21.259 + * except that underscores are not accepted between digits.
21.260 + *
21.261 + * <p>The sequence of characters following an optional
21.262 + * sign and/or radix specifier ("{@code 0x}", "{@code 0X}",
21.263 + * "{@code #}", or leading zero) is parsed as by the {@code
21.264 + * Byte.parseByte} method with the indicated radix (10, 16, or 8).
21.265 + * This sequence of characters must represent a positive value or
21.266 + * a {@link NumberFormatException} will be thrown. The result is
21.267 + * negated if first character of the specified {@code String} is
21.268 + * the minus sign. No whitespace characters are permitted in the
21.269 + * {@code String}.
21.270 + *
21.271 + * @param nm the {@code String} to decode.
21.272 + * @return a {@code Byte} object holding the {@code byte}
21.273 + * value represented by {@code nm}
21.274 + * @throws NumberFormatException if the {@code String} does not
21.275 + * contain a parsable {@code byte}.
21.276 + * @see java.lang.Byte#parseByte(java.lang.String, int)
21.277 + */
21.278 + public static Byte decode(String nm) throws NumberFormatException {
21.279 + int i = Integer.decode(nm);
21.280 + if (i < MIN_VALUE || i > MAX_VALUE)
21.281 + throw new NumberFormatException(
21.282 + "Value " + i + " out of range from input " + nm);
21.283 + return valueOf((byte)i);
21.284 + }
21.285 +
21.286 + /**
21.287 + * The value of the {@code Byte}.
21.288 + *
21.289 + * @serial
21.290 + */
21.291 + private final byte value;
21.292 +
21.293 + /**
21.294 + * Constructs a newly allocated {@code Byte} object that
21.295 + * represents the specified {@code byte} value.
21.296 + *
21.297 + * @param value the value to be represented by the
21.298 + * {@code Byte}.
21.299 + */
21.300 + public Byte(byte value) {
21.301 + this.value = value;
21.302 + }
21.303 +
21.304 + /**
21.305 + * Constructs a newly allocated {@code Byte} object that
21.306 + * represents the {@code byte} value indicated by the
21.307 + * {@code String} parameter. The string is converted to a
21.308 + * {@code byte} value in exactly the manner used by the
21.309 + * {@code parseByte} method for radix 10.
21.310 + *
21.311 + * @param s the {@code String} to be converted to a
21.312 + * {@code Byte}
21.313 + * @throws NumberFormatException If the {@code String}
21.314 + * does not contain a parsable {@code byte}.
21.315 + * @see java.lang.Byte#parseByte(java.lang.String, int)
21.316 + */
21.317 + public Byte(String s) throws NumberFormatException {
21.318 + this.value = parseByte(s, 10);
21.319 + }
21.320 +
21.321 + /**
21.322 + * Returns the value of this {@code Byte} as a
21.323 + * {@code byte}.
21.324 + */
21.325 + public byte byteValue() {
21.326 + return value;
21.327 + }
21.328 +
21.329 + /**
21.330 + * Returns the value of this {@code Byte} as a
21.331 + * {@code short}.
21.332 + */
21.333 + public short shortValue() {
21.334 + return (short)value;
21.335 + }
21.336 +
21.337 + /**
21.338 + * Returns the value of this {@code Byte} as an
21.339 + * {@code int}.
21.340 + */
21.341 + public int intValue() {
21.342 + return (int)value;
21.343 + }
21.344 +
21.345 + /**
21.346 + * Returns the value of this {@code Byte} as a
21.347 + * {@code long}.
21.348 + */
21.349 + public long longValue() {
21.350 + return (long)value;
21.351 + }
21.352 +
21.353 + /**
21.354 + * Returns the value of this {@code Byte} as a
21.355 + * {@code float}.
21.356 + */
21.357 + public float floatValue() {
21.358 + return (float)value;
21.359 + }
21.360 +
21.361 + /**
21.362 + * Returns the value of this {@code Byte} as a
21.363 + * {@code double}.
21.364 + */
21.365 + public double doubleValue() {
21.366 + return (double)value;
21.367 + }
21.368 +
21.369 + /**
21.370 + * Returns a {@code String} object representing this
21.371 + * {@code Byte}'s value. The value is converted to signed
21.372 + * decimal representation and returned as a string, exactly as if
21.373 + * the {@code byte} value were given as an argument to the
21.374 + * {@link java.lang.Byte#toString(byte)} method.
21.375 + *
21.376 + * @return a string representation of the value of this object in
21.377 + * base 10.
21.378 + */
21.379 + public String toString() {
21.380 + return Integer.toString((int)value);
21.381 + }
21.382 +
21.383 + /**
21.384 + * Returns a hash code for this {@code Byte}; equal to the result
21.385 + * of invoking {@code intValue()}.
21.386 + *
21.387 + * @return a hash code value for this {@code Byte}
21.388 + */
21.389 + public int hashCode() {
21.390 + return (int)value;
21.391 + }
21.392 +
21.393 + /**
21.394 + * Compares this object to the specified object. The result is
21.395 + * {@code true} if and only if the argument is not
21.396 + * {@code null} and is a {@code Byte} object that
21.397 + * contains the same {@code byte} value as this object.
21.398 + *
21.399 + * @param obj the object to compare with
21.400 + * @return {@code true} if the objects are the same;
21.401 + * {@code false} otherwise.
21.402 + */
21.403 + public boolean equals(Object obj) {
21.404 + if (obj instanceof Byte) {
21.405 + return value == ((Byte)obj).byteValue();
21.406 + }
21.407 + return false;
21.408 + }
21.409 +
21.410 + /**
21.411 + * Compares two {@code Byte} objects numerically.
21.412 + *
21.413 + * @param anotherByte the {@code Byte} to be compared.
21.414 + * @return the value {@code 0} if this {@code Byte} is
21.415 + * equal to the argument {@code Byte}; a value less than
21.416 + * {@code 0} if this {@code Byte} is numerically less
21.417 + * than the argument {@code Byte}; and a value greater than
21.418 + * {@code 0} if this {@code Byte} is numerically
21.419 + * greater than the argument {@code Byte} (signed
21.420 + * comparison).
21.421 + * @since 1.2
21.422 + */
21.423 + public int compareTo(Byte anotherByte) {
21.424 + return compare(this.value, anotherByte.value);
21.425 + }
21.426 +
21.427 + /**
21.428 + * Compares two {@code byte} values numerically.
21.429 + * The value returned is identical to what would be returned by:
21.430 + * <pre>
21.431 + * Byte.valueOf(x).compareTo(Byte.valueOf(y))
21.432 + * </pre>
21.433 + *
21.434 + * @param x the first {@code byte} to compare
21.435 + * @param y the second {@code byte} to compare
21.436 + * @return the value {@code 0} if {@code x == y};
21.437 + * a value less than {@code 0} if {@code x < y}; and
21.438 + * a value greater than {@code 0} if {@code x > y}
21.439 + * @since 1.7
21.440 + */
21.441 + public static int compare(byte x, byte y) {
21.442 + return x - y;
21.443 + }
21.444 +
21.445 + /**
21.446 + * The number of bits used to represent a {@code byte} value in two's
21.447 + * complement binary form.
21.448 + *
21.449 + * @since 1.5
21.450 + */
21.451 + public static final int SIZE = 8;
21.452 +
21.453 + /** use serialVersionUID from JDK 1.1. for interoperability */
21.454 + private static final long serialVersionUID = -7183698231559129828L;
21.455 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
22.2 +++ b/emul/mini/src/main/java/java/lang/CharSequence.java Wed Jan 23 20:39:23 2013 +0100
22.3 @@ -0,0 +1,111 @@
22.4 +/*
22.5 + * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
22.7 + *
22.8 + * This code is free software; you can redistribute it and/or modify it
22.9 + * under the terms of the GNU General Public License version 2 only, as
22.10 + * published by the Free Software Foundation. Oracle designates this
22.11 + * particular file as subject to the "Classpath" exception as provided
22.12 + * by Oracle in the LICENSE file that accompanied this code.
22.13 + *
22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22.17 + * version 2 for more details (a copy is included in the LICENSE file that
22.18 + * accompanied this code).
22.19 + *
22.20 + * You should have received a copy of the GNU General Public License version
22.21 + * 2 along with this work; if not, write to the Free Software Foundation,
22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22.23 + *
22.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22.25 + * or visit www.oracle.com if you need additional information or have any
22.26 + * questions.
22.27 + */
22.28 +
22.29 +package java.lang;
22.30 +
22.31 +
22.32 +/**
22.33 + * A <tt>CharSequence</tt> is a readable sequence of <code>char</code> values. This
22.34 + * interface provides uniform, read-only access to many different kinds of
22.35 + * <code>char</code> sequences.
22.36 + * A <code>char</code> value represents a character in the <i>Basic
22.37 + * Multilingual Plane (BMP)</i> or a surrogate. Refer to <a
22.38 + * href="Character.html#unicode">Unicode Character Representation</a> for details.
22.39 + *
22.40 + * <p> This interface does not refine the general contracts of the {@link
22.41 + * java.lang.Object#equals(java.lang.Object) equals} and {@link
22.42 + * java.lang.Object#hashCode() hashCode} methods. The result of comparing two
22.43 + * objects that implement <tt>CharSequence</tt> is therefore, in general,
22.44 + * undefined. Each object may be implemented by a different class, and there
22.45 + * is no guarantee that each class will be capable of testing its instances
22.46 + * for equality with those of the other. It is therefore inappropriate to use
22.47 + * arbitrary <tt>CharSequence</tt> instances as elements in a set or as keys in
22.48 + * a map. </p>
22.49 + *
22.50 + * @author Mike McCloskey
22.51 + * @since 1.4
22.52 + * @spec JSR-51
22.53 + */
22.54 +
22.55 +public interface CharSequence {
22.56 +
22.57 + /**
22.58 + * Returns the length of this character sequence. The length is the number
22.59 + * of 16-bit <code>char</code>s in the sequence.</p>
22.60 + *
22.61 + * @return the number of <code>char</code>s in this sequence
22.62 + */
22.63 + int length();
22.64 +
22.65 + /**
22.66 + * Returns the <code>char</code> value at the specified index. An index ranges from zero
22.67 + * to <tt>length() - 1</tt>. The first <code>char</code> value of the sequence is at
22.68 + * index zero, the next at index one, and so on, as for array
22.69 + * indexing. </p>
22.70 + *
22.71 + * <p>If the <code>char</code> value specified by the index is a
22.72 + * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
22.73 + * value is returned.
22.74 + *
22.75 + * @param index the index of the <code>char</code> value to be returned
22.76 + *
22.77 + * @return the specified <code>char</code> value
22.78 + *
22.79 + * @throws IndexOutOfBoundsException
22.80 + * if the <tt>index</tt> argument is negative or not less than
22.81 + * <tt>length()</tt>
22.82 + */
22.83 + char charAt(int index);
22.84 +
22.85 + /**
22.86 + * Returns a new <code>CharSequence</code> that is a subsequence of this sequence.
22.87 + * The subsequence starts with the <code>char</code> value at the specified index and
22.88 + * ends with the <code>char</code> value at index <tt>end - 1</tt>. The length
22.89 + * (in <code>char</code>s) of the
22.90 + * returned sequence is <tt>end - start</tt>, so if <tt>start == end</tt>
22.91 + * then an empty sequence is returned. </p>
22.92 + *
22.93 + * @param start the start index, inclusive
22.94 + * @param end the end index, exclusive
22.95 + *
22.96 + * @return the specified subsequence
22.97 + *
22.98 + * @throws IndexOutOfBoundsException
22.99 + * if <tt>start</tt> or <tt>end</tt> are negative,
22.100 + * if <tt>end</tt> is greater than <tt>length()</tt>,
22.101 + * or if <tt>start</tt> is greater than <tt>end</tt>
22.102 + */
22.103 + CharSequence subSequence(int start, int end);
22.104 +
22.105 + /**
22.106 + * Returns a string containing the characters in this sequence in the same
22.107 + * order as this sequence. The length of the string will be the length of
22.108 + * this sequence. </p>
22.109 + *
22.110 + * @return a string consisting of exactly this sequence of characters
22.111 + */
22.112 + public String toString();
22.113 +
22.114 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
23.2 +++ b/emul/mini/src/main/java/java/lang/Character.java Wed Jan 23 20:39:23 2013 +0100
23.3 @@ -0,0 +1,2382 @@
23.4 +/*
23.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
23.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23.7 + *
23.8 + * This code is free software; you can redistribute it and/or modify it
23.9 + * under the terms of the GNU General Public License version 2 only, as
23.10 + * published by the Free Software Foundation. Oracle designates this
23.11 + * particular file as subject to the "Classpath" exception as provided
23.12 + * by Oracle in the LICENSE file that accompanied this code.
23.13 + *
23.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
23.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23.17 + * version 2 for more details (a copy is included in the LICENSE file that
23.18 + * accompanied this code).
23.19 + *
23.20 + * You should have received a copy of the GNU General Public License version
23.21 + * 2 along with this work; if not, write to the Free Software Foundation,
23.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23.23 + *
23.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23.25 + * or visit www.oracle.com if you need additional information or have any
23.26 + * questions.
23.27 + */
23.28 +
23.29 +package java.lang;
23.30 +
23.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
23.32 +
23.33 +/**
23.34 + * The {@code Character} class wraps a value of the primitive
23.35 + * type {@code char} in an object. An object of type
23.36 + * {@code Character} contains a single field whose type is
23.37 + * {@code char}.
23.38 + * <p>
23.39 + * In addition, this class provides several methods for determining
23.40 + * a character's category (lowercase letter, digit, etc.) and for converting
23.41 + * characters from uppercase to lowercase and vice versa.
23.42 + * <p>
23.43 + * Character information is based on the Unicode Standard, version 6.0.0.
23.44 + * <p>
23.45 + * The methods and data of class {@code Character} are defined by
23.46 + * the information in the <i>UnicodeData</i> file that is part of the
23.47 + * Unicode Character Database maintained by the Unicode
23.48 + * Consortium. This file specifies various properties including name
23.49 + * and general category for every defined Unicode code point or
23.50 + * character range.
23.51 + * <p>
23.52 + * The file and its description are available from the Unicode Consortium at:
23.53 + * <ul>
23.54 + * <li><a href="http://www.unicode.org">http://www.unicode.org</a>
23.55 + * </ul>
23.56 + *
23.57 + * <h4><a name="unicode">Unicode Character Representations</a></h4>
23.58 + *
23.59 + * <p>The {@code char} data type (and therefore the value that a
23.60 + * {@code Character} object encapsulates) are based on the
23.61 + * original Unicode specification, which defined characters as
23.62 + * fixed-width 16-bit entities. The Unicode Standard has since been
23.63 + * changed to allow for characters whose representation requires more
23.64 + * than 16 bits. The range of legal <em>code point</em>s is now
23.65 + * U+0000 to U+10FFFF, known as <em>Unicode scalar value</em>.
23.66 + * (Refer to the <a
23.67 + * href="http://www.unicode.org/reports/tr27/#notation"><i>
23.68 + * definition</i></a> of the U+<i>n</i> notation in the Unicode
23.69 + * Standard.)
23.70 + *
23.71 + * <p><a name="BMP">The set of characters from U+0000 to U+FFFF is
23.72 + * sometimes referred to as the <em>Basic Multilingual Plane (BMP)</em>.
23.73 + * <a name="supplementary">Characters</a> whose code points are greater
23.74 + * than U+FFFF are called <em>supplementary character</em>s. The Java
23.75 + * platform uses the UTF-16 representation in {@code char} arrays and
23.76 + * in the {@code String} and {@code StringBuffer} classes. In
23.77 + * this representation, supplementary characters are represented as a pair
23.78 + * of {@code char} values, the first from the <em>high-surrogates</em>
23.79 + * range, (\uD800-\uDBFF), the second from the
23.80 + * <em>low-surrogates</em> range (\uDC00-\uDFFF).
23.81 + *
23.82 + * <p>A {@code char} value, therefore, represents Basic
23.83 + * Multilingual Plane (BMP) code points, including the surrogate
23.84 + * code points, or code units of the UTF-16 encoding. An
23.85 + * {@code int} value represents all Unicode code points,
23.86 + * including supplementary code points. The lower (least significant)
23.87 + * 21 bits of {@code int} are used to represent Unicode code
23.88 + * points and the upper (most significant) 11 bits must be zero.
23.89 + * Unless otherwise specified, the behavior with respect to
23.90 + * supplementary characters and surrogate {@code char} values is
23.91 + * as follows:
23.92 + *
23.93 + * <ul>
23.94 + * <li>The methods that only accept a {@code char} value cannot support
23.95 + * supplementary characters. They treat {@code char} values from the
23.96 + * surrogate ranges as undefined characters. For example,
23.97 + * {@code Character.isLetter('\u005CuD840')} returns {@code false}, even though
23.98 + * this specific value if followed by any low-surrogate value in a string
23.99 + * would represent a letter.
23.100 + *
23.101 + * <li>The methods that accept an {@code int} value support all
23.102 + * Unicode characters, including supplementary characters. For
23.103 + * example, {@code Character.isLetter(0x2F81A)} returns
23.104 + * {@code true} because the code point value represents a letter
23.105 + * (a CJK ideograph).
23.106 + * </ul>
23.107 + *
23.108 + * <p>In the Java SE API documentation, <em>Unicode code point</em> is
23.109 + * used for character values in the range between U+0000 and U+10FFFF,
23.110 + * and <em>Unicode code unit</em> is used for 16-bit
23.111 + * {@code char} values that are code units of the <em>UTF-16</em>
23.112 + * encoding. For more information on Unicode terminology, refer to the
23.113 + * <a href="http://www.unicode.org/glossary/">Unicode Glossary</a>.
23.114 + *
23.115 + * @author Lee Boynton
23.116 + * @author Guy Steele
23.117 + * @author Akira Tanaka
23.118 + * @author Martin Buchholz
23.119 + * @author Ulf Zibis
23.120 + * @since 1.0
23.121 + */
23.122 +public final
23.123 +class Character implements java.io.Serializable, Comparable<Character> {
23.124 + /**
23.125 + * The minimum radix available for conversion to and from strings.
23.126 + * The constant value of this field is the smallest value permitted
23.127 + * for the radix argument in radix-conversion methods such as the
23.128 + * {@code digit} method, the {@code forDigit} method, and the
23.129 + * {@code toString} method of class {@code Integer}.
23.130 + *
23.131 + * @see Character#digit(char, int)
23.132 + * @see Character#forDigit(int, int)
23.133 + * @see Integer#toString(int, int)
23.134 + * @see Integer#valueOf(String)
23.135 + */
23.136 + public static final int MIN_RADIX = 2;
23.137 +
23.138 + /**
23.139 + * The maximum radix available for conversion to and from strings.
23.140 + * The constant value of this field is the largest value permitted
23.141 + * for the radix argument in radix-conversion methods such as the
23.142 + * {@code digit} method, the {@code forDigit} method, and the
23.143 + * {@code toString} method of class {@code Integer}.
23.144 + *
23.145 + * @see Character#digit(char, int)
23.146 + * @see Character#forDigit(int, int)
23.147 + * @see Integer#toString(int, int)
23.148 + * @see Integer#valueOf(String)
23.149 + */
23.150 + public static final int MAX_RADIX = 36;
23.151 +
23.152 + /**
23.153 + * The constant value of this field is the smallest value of type
23.154 + * {@code char}, {@code '\u005Cu0000'}.
23.155 + *
23.156 + * @since 1.0.2
23.157 + */
23.158 + public static final char MIN_VALUE = '\u0000';
23.159 +
23.160 + /**
23.161 + * The constant value of this field is the largest value of type
23.162 + * {@code char}, {@code '\u005CuFFFF'}.
23.163 + *
23.164 + * @since 1.0.2
23.165 + */
23.166 + public static final char MAX_VALUE = '\uFFFF';
23.167 +
23.168 + /**
23.169 + * The {@code Class} instance representing the primitive type
23.170 + * {@code char}.
23.171 + *
23.172 + * @since 1.1
23.173 + */
23.174 + public static final Class<Character> TYPE = Class.getPrimitiveClass("char");
23.175 +
23.176 + /*
23.177 + * Normative general types
23.178 + */
23.179 +
23.180 + /*
23.181 + * General character types
23.182 + */
23.183 +
23.184 + /**
23.185 + * General category "Cn" in the Unicode specification.
23.186 + * @since 1.1
23.187 + */
23.188 + public static final byte UNASSIGNED = 0;
23.189 +
23.190 + /**
23.191 + * General category "Lu" in the Unicode specification.
23.192 + * @since 1.1
23.193 + */
23.194 + public static final byte UPPERCASE_LETTER = 1;
23.195 +
23.196 + /**
23.197 + * General category "Ll" in the Unicode specification.
23.198 + * @since 1.1
23.199 + */
23.200 + public static final byte LOWERCASE_LETTER = 2;
23.201 +
23.202 + /**
23.203 + * General category "Lt" in the Unicode specification.
23.204 + * @since 1.1
23.205 + */
23.206 + public static final byte TITLECASE_LETTER = 3;
23.207 +
23.208 + /**
23.209 + * General category "Lm" in the Unicode specification.
23.210 + * @since 1.1
23.211 + */
23.212 + public static final byte MODIFIER_LETTER = 4;
23.213 +
23.214 + /**
23.215 + * General category "Lo" in the Unicode specification.
23.216 + * @since 1.1
23.217 + */
23.218 + public static final byte OTHER_LETTER = 5;
23.219 +
23.220 + /**
23.221 + * General category "Mn" in the Unicode specification.
23.222 + * @since 1.1
23.223 + */
23.224 + public static final byte NON_SPACING_MARK = 6;
23.225 +
23.226 + /**
23.227 + * General category "Me" in the Unicode specification.
23.228 + * @since 1.1
23.229 + */
23.230 + public static final byte ENCLOSING_MARK = 7;
23.231 +
23.232 + /**
23.233 + * General category "Mc" in the Unicode specification.
23.234 + * @since 1.1
23.235 + */
23.236 + public static final byte COMBINING_SPACING_MARK = 8;
23.237 +
23.238 + /**
23.239 + * General category "Nd" in the Unicode specification.
23.240 + * @since 1.1
23.241 + */
23.242 + public static final byte DECIMAL_DIGIT_NUMBER = 9;
23.243 +
23.244 + /**
23.245 + * General category "Nl" in the Unicode specification.
23.246 + * @since 1.1
23.247 + */
23.248 + public static final byte LETTER_NUMBER = 10;
23.249 +
23.250 + /**
23.251 + * General category "No" in the Unicode specification.
23.252 + * @since 1.1
23.253 + */
23.254 + public static final byte OTHER_NUMBER = 11;
23.255 +
23.256 + /**
23.257 + * General category "Zs" in the Unicode specification.
23.258 + * @since 1.1
23.259 + */
23.260 + public static final byte SPACE_SEPARATOR = 12;
23.261 +
23.262 + /**
23.263 + * General category "Zl" in the Unicode specification.
23.264 + * @since 1.1
23.265 + */
23.266 + public static final byte LINE_SEPARATOR = 13;
23.267 +
23.268 + /**
23.269 + * General category "Zp" in the Unicode specification.
23.270 + * @since 1.1
23.271 + */
23.272 + public static final byte PARAGRAPH_SEPARATOR = 14;
23.273 +
23.274 + /**
23.275 + * General category "Cc" in the Unicode specification.
23.276 + * @since 1.1
23.277 + */
23.278 + public static final byte CONTROL = 15;
23.279 +
23.280 + /**
23.281 + * General category "Cf" in the Unicode specification.
23.282 + * @since 1.1
23.283 + */
23.284 + public static final byte FORMAT = 16;
23.285 +
23.286 + /**
23.287 + * General category "Co" in the Unicode specification.
23.288 + * @since 1.1
23.289 + */
23.290 + public static final byte PRIVATE_USE = 18;
23.291 +
23.292 + /**
23.293 + * General category "Cs" in the Unicode specification.
23.294 + * @since 1.1
23.295 + */
23.296 + public static final byte SURROGATE = 19;
23.297 +
23.298 + /**
23.299 + * General category "Pd" in the Unicode specification.
23.300 + * @since 1.1
23.301 + */
23.302 + public static final byte DASH_PUNCTUATION = 20;
23.303 +
23.304 + /**
23.305 + * General category "Ps" in the Unicode specification.
23.306 + * @since 1.1
23.307 + */
23.308 + public static final byte START_PUNCTUATION = 21;
23.309 +
23.310 + /**
23.311 + * General category "Pe" in the Unicode specification.
23.312 + * @since 1.1
23.313 + */
23.314 + public static final byte END_PUNCTUATION = 22;
23.315 +
23.316 + /**
23.317 + * General category "Pc" in the Unicode specification.
23.318 + * @since 1.1
23.319 + */
23.320 + public static final byte CONNECTOR_PUNCTUATION = 23;
23.321 +
23.322 + /**
23.323 + * General category "Po" in the Unicode specification.
23.324 + * @since 1.1
23.325 + */
23.326 + public static final byte OTHER_PUNCTUATION = 24;
23.327 +
23.328 + /**
23.329 + * General category "Sm" in the Unicode specification.
23.330 + * @since 1.1
23.331 + */
23.332 + public static final byte MATH_SYMBOL = 25;
23.333 +
23.334 + /**
23.335 + * General category "Sc" in the Unicode specification.
23.336 + * @since 1.1
23.337 + */
23.338 + public static final byte CURRENCY_SYMBOL = 26;
23.339 +
23.340 + /**
23.341 + * General category "Sk" in the Unicode specification.
23.342 + * @since 1.1
23.343 + */
23.344 + public static final byte MODIFIER_SYMBOL = 27;
23.345 +
23.346 + /**
23.347 + * General category "So" in the Unicode specification.
23.348 + * @since 1.1
23.349 + */
23.350 + public static final byte OTHER_SYMBOL = 28;
23.351 +
23.352 + /**
23.353 + * General category "Pi" in the Unicode specification.
23.354 + * @since 1.4
23.355 + */
23.356 + public static final byte INITIAL_QUOTE_PUNCTUATION = 29;
23.357 +
23.358 + /**
23.359 + * General category "Pf" in the Unicode specification.
23.360 + * @since 1.4
23.361 + */
23.362 + public static final byte FINAL_QUOTE_PUNCTUATION = 30;
23.363 +
23.364 + /**
23.365 + * Error flag. Use int (code point) to avoid confusion with U+FFFF.
23.366 + */
23.367 + static final int ERROR = 0xFFFFFFFF;
23.368 +
23.369 +
23.370 + /**
23.371 + * Undefined bidirectional character type. Undefined {@code char}
23.372 + * values have undefined directionality in the Unicode specification.
23.373 + * @since 1.4
23.374 + */
23.375 + public static final byte DIRECTIONALITY_UNDEFINED = -1;
23.376 +
23.377 + /**
23.378 + * Strong bidirectional character type "L" in the Unicode specification.
23.379 + * @since 1.4
23.380 + */
23.381 + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = 0;
23.382 +
23.383 + /**
23.384 + * Strong bidirectional character type "R" in the Unicode specification.
23.385 + * @since 1.4
23.386 + */
23.387 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = 1;
23.388 +
23.389 + /**
23.390 + * Strong bidirectional character type "AL" in the Unicode specification.
23.391 + * @since 1.4
23.392 + */
23.393 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = 2;
23.394 +
23.395 + /**
23.396 + * Weak bidirectional character type "EN" in the Unicode specification.
23.397 + * @since 1.4
23.398 + */
23.399 + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = 3;
23.400 +
23.401 + /**
23.402 + * Weak bidirectional character type "ES" in the Unicode specification.
23.403 + * @since 1.4
23.404 + */
23.405 + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = 4;
23.406 +
23.407 + /**
23.408 + * Weak bidirectional character type "ET" in the Unicode specification.
23.409 + * @since 1.4
23.410 + */
23.411 + public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = 5;
23.412 +
23.413 + /**
23.414 + * Weak bidirectional character type "AN" in the Unicode specification.
23.415 + * @since 1.4
23.416 + */
23.417 + public static final byte DIRECTIONALITY_ARABIC_NUMBER = 6;
23.418 +
23.419 + /**
23.420 + * Weak bidirectional character type "CS" in the Unicode specification.
23.421 + * @since 1.4
23.422 + */
23.423 + public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = 7;
23.424 +
23.425 + /**
23.426 + * Weak bidirectional character type "NSM" in the Unicode specification.
23.427 + * @since 1.4
23.428 + */
23.429 + public static final byte DIRECTIONALITY_NONSPACING_MARK = 8;
23.430 +
23.431 + /**
23.432 + * Weak bidirectional character type "BN" in the Unicode specification.
23.433 + * @since 1.4
23.434 + */
23.435 + public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = 9;
23.436 +
23.437 + /**
23.438 + * Neutral bidirectional character type "B" in the Unicode specification.
23.439 + * @since 1.4
23.440 + */
23.441 + public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = 10;
23.442 +
23.443 + /**
23.444 + * Neutral bidirectional character type "S" in the Unicode specification.
23.445 + * @since 1.4
23.446 + */
23.447 + public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = 11;
23.448 +
23.449 + /**
23.450 + * Neutral bidirectional character type "WS" in the Unicode specification.
23.451 + * @since 1.4
23.452 + */
23.453 + public static final byte DIRECTIONALITY_WHITESPACE = 12;
23.454 +
23.455 + /**
23.456 + * Neutral bidirectional character type "ON" in the Unicode specification.
23.457 + * @since 1.4
23.458 + */
23.459 + public static final byte DIRECTIONALITY_OTHER_NEUTRALS = 13;
23.460 +
23.461 + /**
23.462 + * Strong bidirectional character type "LRE" in the Unicode specification.
23.463 + * @since 1.4
23.464 + */
23.465 + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = 14;
23.466 +
23.467 + /**
23.468 + * Strong bidirectional character type "LRO" in the Unicode specification.
23.469 + * @since 1.4
23.470 + */
23.471 + public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = 15;
23.472 +
23.473 + /**
23.474 + * Strong bidirectional character type "RLE" in the Unicode specification.
23.475 + * @since 1.4
23.476 + */
23.477 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = 16;
23.478 +
23.479 + /**
23.480 + * Strong bidirectional character type "RLO" in the Unicode specification.
23.481 + * @since 1.4
23.482 + */
23.483 + public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = 17;
23.484 +
23.485 + /**
23.486 + * Weak bidirectional character type "PDF" in the Unicode specification.
23.487 + * @since 1.4
23.488 + */
23.489 + public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = 18;
23.490 +
23.491 + /**
23.492 + * The minimum value of a
23.493 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.494 + * Unicode high-surrogate code unit</a>
23.495 + * in the UTF-16 encoding, constant {@code '\u005CuD800'}.
23.496 + * A high-surrogate is also known as a <i>leading-surrogate</i>.
23.497 + *
23.498 + * @since 1.5
23.499 + */
23.500 + public static final char MIN_HIGH_SURROGATE = '\uD800';
23.501 +
23.502 + /**
23.503 + * The maximum value of a
23.504 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.505 + * Unicode high-surrogate code unit</a>
23.506 + * in the UTF-16 encoding, constant {@code '\u005CuDBFF'}.
23.507 + * A high-surrogate is also known as a <i>leading-surrogate</i>.
23.508 + *
23.509 + * @since 1.5
23.510 + */
23.511 + public static final char MAX_HIGH_SURROGATE = '\uDBFF';
23.512 +
23.513 + /**
23.514 + * The minimum value of a
23.515 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.516 + * Unicode low-surrogate code unit</a>
23.517 + * in the UTF-16 encoding, constant {@code '\u005CuDC00'}.
23.518 + * A low-surrogate is also known as a <i>trailing-surrogate</i>.
23.519 + *
23.520 + * @since 1.5
23.521 + */
23.522 + public static final char MIN_LOW_SURROGATE = '\uDC00';
23.523 +
23.524 + /**
23.525 + * The maximum value of a
23.526 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.527 + * Unicode low-surrogate code unit</a>
23.528 + * in the UTF-16 encoding, constant {@code '\u005CuDFFF'}.
23.529 + * A low-surrogate is also known as a <i>trailing-surrogate</i>.
23.530 + *
23.531 + * @since 1.5
23.532 + */
23.533 + public static final char MAX_LOW_SURROGATE = '\uDFFF';
23.534 +
23.535 + /**
23.536 + * The minimum value of a Unicode surrogate code unit in the
23.537 + * UTF-16 encoding, constant {@code '\u005CuD800'}.
23.538 + *
23.539 + * @since 1.5
23.540 + */
23.541 + public static final char MIN_SURROGATE = MIN_HIGH_SURROGATE;
23.542 +
23.543 + /**
23.544 + * The maximum value of a Unicode surrogate code unit in the
23.545 + * UTF-16 encoding, constant {@code '\u005CuDFFF'}.
23.546 + *
23.547 + * @since 1.5
23.548 + */
23.549 + public static final char MAX_SURROGATE = MAX_LOW_SURROGATE;
23.550 +
23.551 + /**
23.552 + * The minimum value of a
23.553 + * <a href="http://www.unicode.org/glossary/#supplementary_code_point">
23.554 + * Unicode supplementary code point</a>, constant {@code U+10000}.
23.555 + *
23.556 + * @since 1.5
23.557 + */
23.558 + public static final int MIN_SUPPLEMENTARY_CODE_POINT = 0x010000;
23.559 +
23.560 + /**
23.561 + * The minimum value of a
23.562 + * <a href="http://www.unicode.org/glossary/#code_point">
23.563 + * Unicode code point</a>, constant {@code U+0000}.
23.564 + *
23.565 + * @since 1.5
23.566 + */
23.567 + public static final int MIN_CODE_POINT = 0x000000;
23.568 +
23.569 + /**
23.570 + * The maximum value of a
23.571 + * <a href="http://www.unicode.org/glossary/#code_point">
23.572 + * Unicode code point</a>, constant {@code U+10FFFF}.
23.573 + *
23.574 + * @since 1.5
23.575 + */
23.576 + public static final int MAX_CODE_POINT = 0X10FFFF;
23.577 +
23.578 +
23.579 + /**
23.580 + * Instances of this class represent particular subsets of the Unicode
23.581 + * character set. The only family of subsets defined in the
23.582 + * {@code Character} class is {@link Character.UnicodeBlock}.
23.583 + * Other portions of the Java API may define other subsets for their
23.584 + * own purposes.
23.585 + *
23.586 + * @since 1.2
23.587 + */
23.588 + public static class Subset {
23.589 +
23.590 + private String name;
23.591 +
23.592 + /**
23.593 + * Constructs a new {@code Subset} instance.
23.594 + *
23.595 + * @param name The name of this subset
23.596 + * @exception NullPointerException if name is {@code null}
23.597 + */
23.598 + protected Subset(String name) {
23.599 + if (name == null) {
23.600 + throw new NullPointerException("name");
23.601 + }
23.602 + this.name = name;
23.603 + }
23.604 +
23.605 + /**
23.606 + * Compares two {@code Subset} objects for equality.
23.607 + * This method returns {@code true} if and only if
23.608 + * {@code this} and the argument refer to the same
23.609 + * object; since this method is {@code final}, this
23.610 + * guarantee holds for all subclasses.
23.611 + */
23.612 + public final boolean equals(Object obj) {
23.613 + return (this == obj);
23.614 + }
23.615 +
23.616 + /**
23.617 + * Returns the standard hash code as defined by the
23.618 + * {@link Object#hashCode} method. This method
23.619 + * is {@code final} in order to ensure that the
23.620 + * {@code equals} and {@code hashCode} methods will
23.621 + * be consistent in all subclasses.
23.622 + */
23.623 + public final int hashCode() {
23.624 + return super.hashCode();
23.625 + }
23.626 +
23.627 + /**
23.628 + * Returns the name of this subset.
23.629 + */
23.630 + public final String toString() {
23.631 + return name;
23.632 + }
23.633 + }
23.634 +
23.635 + // See http://www.unicode.org/Public/UNIDATA/Blocks.txt
23.636 + // for the latest specification of Unicode Blocks.
23.637 +
23.638 +
23.639 + /**
23.640 + * The value of the {@code Character}.
23.641 + *
23.642 + * @serial
23.643 + */
23.644 + private final char value;
23.645 +
23.646 + /** use serialVersionUID from JDK 1.0.2 for interoperability */
23.647 + private static final long serialVersionUID = 3786198910865385080L;
23.648 +
23.649 + /**
23.650 + * Constructs a newly allocated {@code Character} object that
23.651 + * represents the specified {@code char} value.
23.652 + *
23.653 + * @param value the value to be represented by the
23.654 + * {@code Character} object.
23.655 + */
23.656 + public Character(char value) {
23.657 + this.value = value;
23.658 + }
23.659 +
23.660 + private static class CharacterCache {
23.661 + private CharacterCache(){}
23.662 +
23.663 + static final Character cache[] = new Character[127 + 1];
23.664 +
23.665 + static {
23.666 + for (int i = 0; i < cache.length; i++)
23.667 + cache[i] = new Character((char)i);
23.668 + }
23.669 + }
23.670 +
23.671 + /**
23.672 + * Returns a <tt>Character</tt> instance representing the specified
23.673 + * <tt>char</tt> value.
23.674 + * If a new <tt>Character</tt> instance is not required, this method
23.675 + * should generally be used in preference to the constructor
23.676 + * {@link #Character(char)}, as this method is likely to yield
23.677 + * significantly better space and time performance by caching
23.678 + * frequently requested values.
23.679 + *
23.680 + * This method will always cache values in the range {@code
23.681 + * '\u005Cu0000'} to {@code '\u005Cu007F'}, inclusive, and may
23.682 + * cache other values outside of this range.
23.683 + *
23.684 + * @param c a char value.
23.685 + * @return a <tt>Character</tt> instance representing <tt>c</tt>.
23.686 + * @since 1.5
23.687 + */
23.688 + public static Character valueOf(char c) {
23.689 + if (c <= 127) { // must cache
23.690 + return CharacterCache.cache[(int)c];
23.691 + }
23.692 + return new Character(c);
23.693 + }
23.694 +
23.695 + /**
23.696 + * Returns the value of this {@code Character} object.
23.697 + * @return the primitive {@code char} value represented by
23.698 + * this object.
23.699 + */
23.700 + public char charValue() {
23.701 + return value;
23.702 + }
23.703 +
23.704 + /**
23.705 + * Returns a hash code for this {@code Character}; equal to the result
23.706 + * of invoking {@code charValue()}.
23.707 + *
23.708 + * @return a hash code value for this {@code Character}
23.709 + */
23.710 + public int hashCode() {
23.711 + return (int)value;
23.712 + }
23.713 +
23.714 + /**
23.715 + * Compares this object against the specified object.
23.716 + * The result is {@code true} if and only if the argument is not
23.717 + * {@code null} and is a {@code Character} object that
23.718 + * represents the same {@code char} value as this object.
23.719 + *
23.720 + * @param obj the object to compare with.
23.721 + * @return {@code true} if the objects are the same;
23.722 + * {@code false} otherwise.
23.723 + */
23.724 + public boolean equals(Object obj) {
23.725 + if (obj instanceof Character) {
23.726 + return value == ((Character)obj).charValue();
23.727 + }
23.728 + return false;
23.729 + }
23.730 +
23.731 + /**
23.732 + * Returns a {@code String} object representing this
23.733 + * {@code Character}'s value. The result is a string of
23.734 + * length 1 whose sole component is the primitive
23.735 + * {@code char} value represented by this
23.736 + * {@code Character} object.
23.737 + *
23.738 + * @return a string representation of this object.
23.739 + */
23.740 + public String toString() {
23.741 + char buf[] = {value};
23.742 + return String.valueOf(buf);
23.743 + }
23.744 +
23.745 + /**
23.746 + * Returns a {@code String} object representing the
23.747 + * specified {@code char}. The result is a string of length
23.748 + * 1 consisting solely of the specified {@code char}.
23.749 + *
23.750 + * @param c the {@code char} to be converted
23.751 + * @return the string representation of the specified {@code char}
23.752 + * @since 1.4
23.753 + */
23.754 + public static String toString(char c) {
23.755 + return String.valueOf(c);
23.756 + }
23.757 +
23.758 + /**
23.759 + * Determines whether the specified code point is a valid
23.760 + * <a href="http://www.unicode.org/glossary/#code_point">
23.761 + * Unicode code point value</a>.
23.762 + *
23.763 + * @param codePoint the Unicode code point to be tested
23.764 + * @return {@code true} if the specified code point value is between
23.765 + * {@link #MIN_CODE_POINT} and
23.766 + * {@link #MAX_CODE_POINT} inclusive;
23.767 + * {@code false} otherwise.
23.768 + * @since 1.5
23.769 + */
23.770 + public static boolean isValidCodePoint(int codePoint) {
23.771 + // Optimized form of:
23.772 + // codePoint >= MIN_CODE_POINT && codePoint <= MAX_CODE_POINT
23.773 + int plane = codePoint >>> 16;
23.774 + return plane < ((MAX_CODE_POINT + 1) >>> 16);
23.775 + }
23.776 +
23.777 + /**
23.778 + * Determines whether the specified character (Unicode code point)
23.779 + * is in the <a href="#BMP">Basic Multilingual Plane (BMP)</a>.
23.780 + * Such code points can be represented using a single {@code char}.
23.781 + *
23.782 + * @param codePoint the character (Unicode code point) to be tested
23.783 + * @return {@code true} if the specified code point is between
23.784 + * {@link #MIN_VALUE} and {@link #MAX_VALUE} inclusive;
23.785 + * {@code false} otherwise.
23.786 + * @since 1.7
23.787 + */
23.788 + public static boolean isBmpCodePoint(int codePoint) {
23.789 + return codePoint >>> 16 == 0;
23.790 + // Optimized form of:
23.791 + // codePoint >= MIN_VALUE && codePoint <= MAX_VALUE
23.792 + // We consistently use logical shift (>>>) to facilitate
23.793 + // additional runtime optimizations.
23.794 + }
23.795 +
23.796 + /**
23.797 + * Determines whether the specified character (Unicode code point)
23.798 + * is in the <a href="#supplementary">supplementary character</a> range.
23.799 + *
23.800 + * @param codePoint the character (Unicode code point) to be tested
23.801 + * @return {@code true} if the specified code point is between
23.802 + * {@link #MIN_SUPPLEMENTARY_CODE_POINT} and
23.803 + * {@link #MAX_CODE_POINT} inclusive;
23.804 + * {@code false} otherwise.
23.805 + * @since 1.5
23.806 + */
23.807 + public static boolean isSupplementaryCodePoint(int codePoint) {
23.808 + return codePoint >= MIN_SUPPLEMENTARY_CODE_POINT
23.809 + && codePoint < MAX_CODE_POINT + 1;
23.810 + }
23.811 +
23.812 + /**
23.813 + * Determines if the given {@code char} value is a
23.814 + * <a href="http://www.unicode.org/glossary/#high_surrogate_code_unit">
23.815 + * Unicode high-surrogate code unit</a>
23.816 + * (also known as <i>leading-surrogate code unit</i>).
23.817 + *
23.818 + * <p>Such values do not represent characters by themselves,
23.819 + * but are used in the representation of
23.820 + * <a href="#supplementary">supplementary characters</a>
23.821 + * in the UTF-16 encoding.
23.822 + *
23.823 + * @param ch the {@code char} value to be tested.
23.824 + * @return {@code true} if the {@code char} value is between
23.825 + * {@link #MIN_HIGH_SURROGATE} and
23.826 + * {@link #MAX_HIGH_SURROGATE} inclusive;
23.827 + * {@code false} otherwise.
23.828 + * @see Character#isLowSurrogate(char)
23.829 + * @see Character.UnicodeBlock#of(int)
23.830 + * @since 1.5
23.831 + */
23.832 + public static boolean isHighSurrogate(char ch) {
23.833 + // Help VM constant-fold; MAX_HIGH_SURROGATE + 1 == MIN_LOW_SURROGATE
23.834 + return ch >= MIN_HIGH_SURROGATE && ch < (MAX_HIGH_SURROGATE + 1);
23.835 + }
23.836 +
23.837 + /**
23.838 + * Determines if the given {@code char} value is a
23.839 + * <a href="http://www.unicode.org/glossary/#low_surrogate_code_unit">
23.840 + * Unicode low-surrogate code unit</a>
23.841 + * (also known as <i>trailing-surrogate code unit</i>).
23.842 + *
23.843 + * <p>Such values do not represent characters by themselves,
23.844 + * but are used in the representation of
23.845 + * <a href="#supplementary">supplementary characters</a>
23.846 + * in the UTF-16 encoding.
23.847 + *
23.848 + * @param ch the {@code char} value to be tested.