emul/mini/src/main/java/java/io/DataInput.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 23 Jan 2013 20:39:23 +0100
branchemul
changeset 554 05224402145d
parent 146 emul/src/main/java/java/io/DataInput.java@394379b81e73
permissions -rw-r--r--
First attempt to separate 'mini' profile from the rest of JDK APIs
jtulach@146
     1
/*
jtulach@146
     2
 * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
jtulach@146
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@146
     4
 *
jtulach@146
     5
 * This code is free software; you can redistribute it and/or modify it
jtulach@146
     6
 * under the terms of the GNU General Public License version 2 only, as
jtulach@146
     7
 * published by the Free Software Foundation.  Oracle designates this
jtulach@146
     8
 * particular file as subject to the "Classpath" exception as provided
jtulach@146
     9
 * by Oracle in the LICENSE file that accompanied this code.
jtulach@146
    10
 *
jtulach@146
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@146
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@146
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jtulach@146
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jtulach@146
    15
 * accompanied this code).
jtulach@146
    16
 *
jtulach@146
    17
 * You should have received a copy of the GNU General Public License version
jtulach@146
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@146
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@146
    20
 *
jtulach@146
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@146
    22
 * or visit www.oracle.com if you need additional information or have any
jtulach@146
    23
 * questions.
jtulach@146
    24
 */
jtulach@146
    25
jtulach@146
    26
package java.io;
jtulach@146
    27
jtulach@146
    28
/**
jtulach@146
    29
 * The <code>DataInput</code> interface provides
jtulach@146
    30
 * for reading bytes from a binary stream and
jtulach@146
    31
 * reconstructing from them data in any of
jtulach@146
    32
 * the Java primitive types. There is also
jtulach@146
    33
 * a
jtulach@146
    34
 * facility for reconstructing a <code>String</code>
jtulach@146
    35
 * from data in
jtulach@146
    36
 * <a href="#modified-utf-8">modified UTF-8</a>
jtulach@146
    37
 * format.
jtulach@146
    38
 * <p>
jtulach@146
    39
 * It is generally true of all the reading
jtulach@146
    40
 * routines in this interface that if end of
jtulach@146
    41
 * file is reached before the desired number
jtulach@146
    42
 * of bytes has been read, an <code>EOFException</code>
jtulach@146
    43
 * (which is a kind of <code>IOException</code>)
jtulach@146
    44
 * is thrown. If any byte cannot be read for
jtulach@146
    45
 * any reason other than end of file, an <code>IOException</code>
jtulach@146
    46
 * other than <code>EOFException</code> is
jtulach@146
    47
 * thrown. In particular, an <code>IOException</code>
jtulach@146
    48
 * may be thrown if the input stream has been
jtulach@146
    49
 * closed.
jtulach@146
    50
 *
jtulach@146
    51
 * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
jtulach@146
    52
 * <p>
jtulach@146
    53
 * Implementations of the DataInput and DataOutput interfaces represent
jtulach@146
    54
 * Unicode strings in a format that is a slight modification of UTF-8.
jtulach@146
    55
 * (For information regarding the standard UTF-8 format, see section
jtulach@146
    56
 * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
jtulach@146
    57
 * 4.0</i>).
jtulach@146
    58
 * Note that in the following tables, the most significant bit appears in the
jtulach@146
    59
 * far left-hand column.
jtulach@146
    60
 * <p>
jtulach@146
    61
 * All characters in the range <code>'&#92;u0001'</code> to
jtulach@146
    62
 * <code>'&#92;u007F'</code> are represented by a single byte:
jtulach@146
    63
 *
jtulach@146
    64
 * <blockquote>
jtulach@146
    65
 *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
jtulach@146
    66
 *          summary="Bit values and bytes">
jtulach@146
    67
 *     <tr>
jtulach@146
    68
 *       <td></td>
jtulach@146
    69
 *       <th id="bit">Bit Values</th>
jtulach@146
    70
 *     </tr>
jtulach@146
    71
 *     <tr>
jtulach@146
    72
 *       <th id="byte1">Byte 1</th>
jtulach@146
    73
 *       <td>
jtulach@146
    74
 *         <table border="1" cellspacing="0" width="100%">
jtulach@146
    75
 *           <tr>
jtulach@146
    76
 *             <td width="12%"><center>0</center>
jtulach@146
    77
 *             <td colspan="7"><center>bits 6-0</center>
jtulach@146
    78
 *           </tr>
jtulach@146
    79
 *         </table>
jtulach@146
    80
 *       </td>
jtulach@146
    81
 *     </tr>
jtulach@146
    82
 *   </table>
jtulach@146
    83
 * </blockquote>
jtulach@146
    84
 *
jtulach@146
    85
 * <p>
jtulach@146
    86
 * The null character <code>'&#92;u0000'</code> and characters in the
jtulach@146
    87
 * range <code>'&#92;u0080'</code> to <code>'&#92;u07FF'</code> are
jtulach@146
    88
 * represented by a pair of bytes:
jtulach@146
    89
 *
jtulach@146
    90
 * <blockquote>
jtulach@146
    91
 *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
jtulach@146
    92
 *          summary="Bit values and bytes">
jtulach@146
    93
 *     <tr>
jtulach@146
    94
 *       <td></td>
jtulach@146
    95
 *       <th id="bit">Bit Values</th>
jtulach@146
    96
 *     </tr>
jtulach@146
    97
 *     <tr>
jtulach@146
    98
 *       <th id="byte1">Byte 1</th>
jtulach@146
    99
 *       <td>
jtulach@146
   100
 *         <table border="1" cellspacing="0" width="100%">
jtulach@146
   101
 *           <tr>
jtulach@146
   102
 *             <td width="12%"><center>1</center>
jtulach@146
   103
 *             <td width="13%"><center>1</center>
jtulach@146
   104
 *             <td width="12%"><center>0</center>
jtulach@146
   105
 *             <td colspan="5"><center>bits 10-6</center>
jtulach@146
   106
 *           </tr>
jtulach@146
   107
 *         </table>
jtulach@146
   108
 *       </td>
jtulach@146
   109
 *     </tr>
jtulach@146
   110
 *     <tr>
jtulach@146
   111
 *       <th id="byte2">Byte 2</th>
jtulach@146
   112
 *       <td>
jtulach@146
   113
 *         <table border="1" cellspacing="0" width="100%">
jtulach@146
   114
 *           <tr>
jtulach@146
   115
 *             <td width="12%"><center>1</center>
jtulach@146
   116
 *             <td width="13%"><center>0</center>
jtulach@146
   117
 *             <td colspan="6"><center>bits 5-0</center>
jtulach@146
   118
 *           </tr>
jtulach@146
   119
 *         </table>
jtulach@146
   120
 *       </td>
jtulach@146
   121
 *     </tr>
jtulach@146
   122
 *   </table>
jtulach@146
   123
 *  </blockquote>
jtulach@146
   124
 *
jtulach@146
   125
 * <br>
jtulach@146
   126
 * <code>char</code> values in the range <code>'&#92;u0800'</code> to
jtulach@146
   127
 * <code>'&#92;uFFFF'</code> are represented by three bytes:
jtulach@146
   128
 *
jtulach@146
   129
 * <blockquote>
jtulach@146
   130
 *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
jtulach@146
   131
 *          summary="Bit values and bytes">
jtulach@146
   132
 *     <tr>
jtulach@146
   133
 *       <td></td>
jtulach@146
   134
 *       <th id="bit">Bit Values</th>
jtulach@146
   135
 *     </tr>
jtulach@146
   136
 *     <tr>
jtulach@146
   137
 *       <th id="byte1">Byte 1</th>
jtulach@146
   138
 *       <td>
jtulach@146
   139
 *         <table border="1" cellspacing="0" width="100%">
jtulach@146
   140
 *           <tr>
jtulach@146
   141
 *             <td width="12%"><center>1</center>
jtulach@146
   142
 *             <td width="13%"><center>1</center>
jtulach@146
   143
 *             <td width="12%"><center>1</center>
jtulach@146
   144
 *             <td width="13%"><center>0</center>
jtulach@146
   145
 *             <td colspan="4"><center>bits 15-12</center>
jtulach@146
   146
 *           </tr>
jtulach@146
   147
 *         </table>
jtulach@146
   148
 *       </td>
jtulach@146
   149
 *     </tr>
jtulach@146
   150
 *     <tr>
jtulach@146
   151
 *       <th id="byte2">Byte 2</th>
jtulach@146
   152
 *       <td>
jtulach@146
   153
 *         <table border="1" cellspacing="0" width="100%">
jtulach@146
   154
 *           <tr>
jtulach@146
   155
 *             <td width="12%"><center>1</center>
jtulach@146
   156
 *             <td width="13%"><center>0</center>
jtulach@146
   157
 *             <td colspan="6"><center>bits 11-6</center>
jtulach@146
   158
 *           </tr>
jtulach@146
   159
 *         </table>
jtulach@146
   160
 *       </td>
jtulach@146
   161
 *     </tr>
jtulach@146
   162
 *     <tr>
jtulach@146
   163
 *       <th id="byte3">Byte 3</th>
jtulach@146
   164
 *       <td>
jtulach@146
   165
 *         <table border="1" cellspacing="0" width="100%">
jtulach@146
   166
 *           <tr>
jtulach@146
   167
 *             <td width="12%"><center>1</center>
jtulach@146
   168
 *             <td width="13%"><center>0</center>
jtulach@146
   169
 *             <td colspan="6"><center>bits 5-0</center>
jtulach@146
   170
 *           </tr>
jtulach@146
   171
 *         </table>
jtulach@146
   172
 *       </td>
jtulach@146
   173
 *     </tr>
jtulach@146
   174
 *   </table>
jtulach@146
   175
 *  </blockquote>
jtulach@146
   176
 *
jtulach@146
   177
 * <p>
jtulach@146
   178
 * The differences between this format and the
jtulach@146
   179
 * standard UTF-8 format are the following:
jtulach@146
   180
 * <ul>
jtulach@146
   181
 * <li>The null byte <code>'&#92;u0000'</code> is encoded in 2-byte format
jtulach@146
   182
 *     rather than 1-byte, so that the encoded strings never have
jtulach@146
   183
 *     embedded nulls.
jtulach@146
   184
 * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
jtulach@146
   185
 * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
jtulach@146
   186
 *     are represented in the form of surrogate pairs.
jtulach@146
   187
 * </ul>
jtulach@146
   188
 * @author  Frank Yellin
jtulach@146
   189
 * @see     java.io.DataInputStream
jtulach@146
   190
 * @see     java.io.DataOutput
jtulach@146
   191
 * @since   JDK1.0
jtulach@146
   192
 */
jtulach@146
   193
public
jtulach@146
   194
interface DataInput {
jtulach@146
   195
    /**
jtulach@146
   196
     * Reads some bytes from an input
jtulach@146
   197
     * stream and stores them into the buffer
jtulach@146
   198
     * array <code>b</code>. The number of bytes
jtulach@146
   199
     * read is equal
jtulach@146
   200
     * to the length of <code>b</code>.
jtulach@146
   201
     * <p>
jtulach@146
   202
     * This method blocks until one of the
jtulach@146
   203
     * following conditions occurs:<p>
jtulach@146
   204
     * <ul>
jtulach@146
   205
     * <li><code>b.length</code>
jtulach@146
   206
     * bytes of input data are available, in which
jtulach@146
   207
     * case a normal return is made.
jtulach@146
   208
     *
jtulach@146
   209
     * <li>End of
jtulach@146
   210
     * file is detected, in which case an <code>EOFException</code>
jtulach@146
   211
     * is thrown.
jtulach@146
   212
     *
jtulach@146
   213
     * <li>An I/O error occurs, in
jtulach@146
   214
     * which case an <code>IOException</code> other
jtulach@146
   215
     * than <code>EOFException</code> is thrown.
jtulach@146
   216
     * </ul>
jtulach@146
   217
     * <p>
jtulach@146
   218
     * If <code>b</code> is <code>null</code>,
jtulach@146
   219
     * a <code>NullPointerException</code> is thrown.
jtulach@146
   220
     * If <code>b.length</code> is zero, then
jtulach@146
   221
     * no bytes are read. Otherwise, the first
jtulach@146
   222
     * byte read is stored into element <code>b[0]</code>,
jtulach@146
   223
     * the next one into <code>b[1]</code>, and
jtulach@146
   224
     * so on.
jtulach@146
   225
     * If an exception is thrown from
jtulach@146
   226
     * this method, then it may be that some but
jtulach@146
   227
     * not all bytes of <code>b</code> have been
jtulach@146
   228
     * updated with data from the input stream.
jtulach@146
   229
     *
jtulach@146
   230
     * @param     b   the buffer into which the data is read.
jtulach@146
   231
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   232
     *               all the bytes.
jtulach@146
   233
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   234
     */
jtulach@146
   235
    void readFully(byte b[]) throws IOException;
jtulach@146
   236
jtulach@146
   237
    /**
jtulach@146
   238
     *
jtulach@146
   239
     * Reads <code>len</code>
jtulach@146
   240
     * bytes from
jtulach@146
   241
     * an input stream.
jtulach@146
   242
     * <p>
jtulach@146
   243
     * This method
jtulach@146
   244
     * blocks until one of the following conditions
jtulach@146
   245
     * occurs:<p>
jtulach@146
   246
     * <ul>
jtulach@146
   247
     * <li><code>len</code> bytes
jtulach@146
   248
     * of input data are available, in which case
jtulach@146
   249
     * a normal return is made.
jtulach@146
   250
     *
jtulach@146
   251
     * <li>End of file
jtulach@146
   252
     * is detected, in which case an <code>EOFException</code>
jtulach@146
   253
     * is thrown.
jtulach@146
   254
     *
jtulach@146
   255
     * <li>An I/O error occurs, in
jtulach@146
   256
     * which case an <code>IOException</code> other
jtulach@146
   257
     * than <code>EOFException</code> is thrown.
jtulach@146
   258
     * </ul>
jtulach@146
   259
     * <p>
jtulach@146
   260
     * If <code>b</code> is <code>null</code>,
jtulach@146
   261
     * a <code>NullPointerException</code> is thrown.
jtulach@146
   262
     * If <code>off</code> is negative, or <code>len</code>
jtulach@146
   263
     * is negative, or <code>off+len</code> is
jtulach@146
   264
     * greater than the length of the array <code>b</code>,
jtulach@146
   265
     * then an <code>IndexOutOfBoundsException</code>
jtulach@146
   266
     * is thrown.
jtulach@146
   267
     * If <code>len</code> is zero,
jtulach@146
   268
     * then no bytes are read. Otherwise, the first
jtulach@146
   269
     * byte read is stored into element <code>b[off]</code>,
jtulach@146
   270
     * the next one into <code>b[off+1]</code>,
jtulach@146
   271
     * and so on. The number of bytes read is,
jtulach@146
   272
     * at most, equal to <code>len</code>.
jtulach@146
   273
     *
jtulach@146
   274
     * @param     b   the buffer into which the data is read.
jtulach@146
   275
     * @param off  an int specifying the offset into the data.
jtulach@146
   276
     * @param len  an int specifying the number of bytes to read.
jtulach@146
   277
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   278
     *               all the bytes.
jtulach@146
   279
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   280
     */
jtulach@146
   281
    void readFully(byte b[], int off, int len) throws IOException;
jtulach@146
   282
jtulach@146
   283
    /**
jtulach@146
   284
     * Makes an attempt to skip over
jtulach@146
   285
     * <code>n</code> bytes
jtulach@146
   286
     * of data from the input
jtulach@146
   287
     * stream, discarding the skipped bytes. However,
jtulach@146
   288
     * it may skip
jtulach@146
   289
     * over some smaller number of
jtulach@146
   290
     * bytes, possibly zero. This may result from
jtulach@146
   291
     * any of a
jtulach@146
   292
     * number of conditions; reaching
jtulach@146
   293
     * end of file before <code>n</code> bytes
jtulach@146
   294
     * have been skipped is
jtulach@146
   295
     * only one possibility.
jtulach@146
   296
     * This method never throws an <code>EOFException</code>.
jtulach@146
   297
     * The actual
jtulach@146
   298
     * number of bytes skipped is returned.
jtulach@146
   299
     *
jtulach@146
   300
     * @param      n   the number of bytes to be skipped.
jtulach@146
   301
     * @return     the number of bytes actually skipped.
jtulach@146
   302
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   303
     */
jtulach@146
   304
    int skipBytes(int n) throws IOException;
jtulach@146
   305
jtulach@146
   306
    /**
jtulach@146
   307
     * Reads one input byte and returns
jtulach@146
   308
     * <code>true</code> if that byte is nonzero,
jtulach@146
   309
     * <code>false</code> if that byte is zero.
jtulach@146
   310
     * This method is suitable for reading
jtulach@146
   311
     * the byte written by the <code>writeBoolean</code>
jtulach@146
   312
     * method of interface <code>DataOutput</code>.
jtulach@146
   313
     *
jtulach@146
   314
     * @return     the <code>boolean</code> value read.
jtulach@146
   315
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   316
     *               all the bytes.
jtulach@146
   317
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   318
     */
jtulach@146
   319
    boolean readBoolean() throws IOException;
jtulach@146
   320
jtulach@146
   321
    /**
jtulach@146
   322
     * Reads and returns one input byte.
jtulach@146
   323
     * The byte is treated as a signed value in
jtulach@146
   324
     * the range <code>-128</code> through <code>127</code>,
jtulach@146
   325
     * inclusive.
jtulach@146
   326
     * This method is suitable for
jtulach@146
   327
     * reading the byte written by the <code>writeByte</code>
jtulach@146
   328
     * method of interface <code>DataOutput</code>.
jtulach@146
   329
     *
jtulach@146
   330
     * @return     the 8-bit value read.
jtulach@146
   331
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   332
     *               all the bytes.
jtulach@146
   333
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   334
     */
jtulach@146
   335
    byte readByte() throws IOException;
jtulach@146
   336
jtulach@146
   337
    /**
jtulach@146
   338
     * Reads one input byte, zero-extends
jtulach@146
   339
     * it to type <code>int</code>, and returns
jtulach@146
   340
     * the result, which is therefore in the range
jtulach@146
   341
     * <code>0</code>
jtulach@146
   342
     * through <code>255</code>.
jtulach@146
   343
     * This method is suitable for reading
jtulach@146
   344
     * the byte written by the <code>writeByte</code>
jtulach@146
   345
     * method of interface <code>DataOutput</code>
jtulach@146
   346
     * if the argument to <code>writeByte</code>
jtulach@146
   347
     * was intended to be a value in the range
jtulach@146
   348
     * <code>0</code> through <code>255</code>.
jtulach@146
   349
     *
jtulach@146
   350
     * @return     the unsigned 8-bit value read.
jtulach@146
   351
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   352
     *               all the bytes.
jtulach@146
   353
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   354
     */
jtulach@146
   355
    int readUnsignedByte() throws IOException;
jtulach@146
   356
jtulach@146
   357
    /**
jtulach@146
   358
     * Reads two input bytes and returns
jtulach@146
   359
     * a <code>short</code> value. Let <code>a</code>
jtulach@146
   360
     * be the first byte read and <code>b</code>
jtulach@146
   361
     * be the second byte. The value
jtulach@146
   362
     * returned
jtulach@146
   363
     * is:
jtulach@146
   364
     * <p><pre><code>(short)((a &lt;&lt; 8) | (b &amp; 0xff))
jtulach@146
   365
     * </code></pre>
jtulach@146
   366
     * This method
jtulach@146
   367
     * is suitable for reading the bytes written
jtulach@146
   368
     * by the <code>writeShort</code> method of
jtulach@146
   369
     * interface <code>DataOutput</code>.
jtulach@146
   370
     *
jtulach@146
   371
     * @return     the 16-bit value read.
jtulach@146
   372
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   373
     *               all the bytes.
jtulach@146
   374
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   375
     */
jtulach@146
   376
    short readShort() throws IOException;
jtulach@146
   377
jtulach@146
   378
    /**
jtulach@146
   379
     * Reads two input bytes and returns
jtulach@146
   380
     * an <code>int</code> value in the range <code>0</code>
jtulach@146
   381
     * through <code>65535</code>. Let <code>a</code>
jtulach@146
   382
     * be the first byte read and
jtulach@146
   383
     * <code>b</code>
jtulach@146
   384
     * be the second byte. The value returned is:
jtulach@146
   385
     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
jtulach@146
   386
     * </code></pre>
jtulach@146
   387
     * This method is suitable for reading the bytes
jtulach@146
   388
     * written by the <code>writeShort</code> method
jtulach@146
   389
     * of interface <code>DataOutput</code>  if
jtulach@146
   390
     * the argument to <code>writeShort</code>
jtulach@146
   391
     * was intended to be a value in the range
jtulach@146
   392
     * <code>0</code> through <code>65535</code>.
jtulach@146
   393
     *
jtulach@146
   394
     * @return     the unsigned 16-bit value read.
jtulach@146
   395
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   396
     *               all the bytes.
jtulach@146
   397
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   398
     */
jtulach@146
   399
    int readUnsignedShort() throws IOException;
jtulach@146
   400
jtulach@146
   401
    /**
jtulach@146
   402
     * Reads two input bytes and returns a <code>char</code> value.
jtulach@146
   403
     * Let <code>a</code>
jtulach@146
   404
     * be the first byte read and <code>b</code>
jtulach@146
   405
     * be the second byte. The value
jtulach@146
   406
     * returned is:
jtulach@146
   407
     * <p><pre><code>(char)((a &lt;&lt; 8) | (b &amp; 0xff))
jtulach@146
   408
     * </code></pre>
jtulach@146
   409
     * This method
jtulach@146
   410
     * is suitable for reading bytes written by
jtulach@146
   411
     * the <code>writeChar</code> method of interface
jtulach@146
   412
     * <code>DataOutput</code>.
jtulach@146
   413
     *
jtulach@146
   414
     * @return     the <code>char</code> value read.
jtulach@146
   415
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   416
     *               all the bytes.
jtulach@146
   417
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   418
     */
jtulach@146
   419
    char readChar() throws IOException;
jtulach@146
   420
jtulach@146
   421
    /**
jtulach@146
   422
     * Reads four input bytes and returns an
jtulach@146
   423
     * <code>int</code> value. Let <code>a-d</code>
jtulach@146
   424
     * be the first through fourth bytes read. The value returned is:
jtulach@146
   425
     * <p><pre>
jtulach@146
   426
     * <code>
jtulach@146
   427
     * (((a &amp; 0xff) &lt;&lt; 24) | ((b &amp; 0xff) &lt;&lt; 16) |
jtulach@146
   428
     * &#32;((c &amp; 0xff) &lt;&lt; 8) | (d &amp; 0xff))
jtulach@146
   429
     * </code></pre>
jtulach@146
   430
     * This method is suitable
jtulach@146
   431
     * for reading bytes written by the <code>writeInt</code>
jtulach@146
   432
     * method of interface <code>DataOutput</code>.
jtulach@146
   433
     *
jtulach@146
   434
     * @return     the <code>int</code> value read.
jtulach@146
   435
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   436
     *               all the bytes.
jtulach@146
   437
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   438
     */
jtulach@146
   439
    int readInt() throws IOException;
jtulach@146
   440
jtulach@146
   441
    /**
jtulach@146
   442
     * Reads eight input bytes and returns
jtulach@146
   443
     * a <code>long</code> value. Let <code>a-h</code>
jtulach@146
   444
     * be the first through eighth bytes read.
jtulach@146
   445
     * The value returned is:
jtulach@146
   446
     * <p><pre> <code>
jtulach@146
   447
     * (((long)(a &amp; 0xff) &lt;&lt; 56) |
jtulach@146
   448
     *  ((long)(b &amp; 0xff) &lt;&lt; 48) |
jtulach@146
   449
     *  ((long)(c &amp; 0xff) &lt;&lt; 40) |
jtulach@146
   450
     *  ((long)(d &amp; 0xff) &lt;&lt; 32) |
jtulach@146
   451
     *  ((long)(e &amp; 0xff) &lt;&lt; 24) |
jtulach@146
   452
     *  ((long)(f &amp; 0xff) &lt;&lt; 16) |
jtulach@146
   453
     *  ((long)(g &amp; 0xff) &lt;&lt;  8) |
jtulach@146
   454
     *  ((long)(h &amp; 0xff)))
jtulach@146
   455
     * </code></pre>
jtulach@146
   456
     * <p>
jtulach@146
   457
     * This method is suitable
jtulach@146
   458
     * for reading bytes written by the <code>writeLong</code>
jtulach@146
   459
     * method of interface <code>DataOutput</code>.
jtulach@146
   460
     *
jtulach@146
   461
     * @return     the <code>long</code> value read.
jtulach@146
   462
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   463
     *               all the bytes.
jtulach@146
   464
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   465
     */
jtulach@146
   466
    long readLong() throws IOException;
jtulach@146
   467
jtulach@146
   468
    /**
jtulach@146
   469
     * Reads four input bytes and returns
jtulach@146
   470
     * a <code>float</code> value. It does this
jtulach@146
   471
     * by first constructing an <code>int</code>
jtulach@146
   472
     * value in exactly the manner
jtulach@146
   473
     * of the <code>readInt</code>
jtulach@146
   474
     * method, then converting this <code>int</code>
jtulach@146
   475
     * value to a <code>float</code> in
jtulach@146
   476
     * exactly the manner of the method <code>Float.intBitsToFloat</code>.
jtulach@146
   477
     * This method is suitable for reading
jtulach@146
   478
     * bytes written by the <code>writeFloat</code>
jtulach@146
   479
     * method of interface <code>DataOutput</code>.
jtulach@146
   480
     *
jtulach@146
   481
     * @return     the <code>float</code> value read.
jtulach@146
   482
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   483
     *               all the bytes.
jtulach@146
   484
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   485
     */
jtulach@146
   486
    float readFloat() throws IOException;
jtulach@146
   487
jtulach@146
   488
    /**
jtulach@146
   489
     * Reads eight input bytes and returns
jtulach@146
   490
     * a <code>double</code> value. It does this
jtulach@146
   491
     * by first constructing a <code>long</code>
jtulach@146
   492
     * value in exactly the manner
jtulach@146
   493
     * of the <code>readlong</code>
jtulach@146
   494
     * method, then converting this <code>long</code>
jtulach@146
   495
     * value to a <code>double</code> in exactly
jtulach@146
   496
     * the manner of the method <code>Double.longBitsToDouble</code>.
jtulach@146
   497
     * This method is suitable for reading
jtulach@146
   498
     * bytes written by the <code>writeDouble</code>
jtulach@146
   499
     * method of interface <code>DataOutput</code>.
jtulach@146
   500
     *
jtulach@146
   501
     * @return     the <code>double</code> value read.
jtulach@146
   502
     * @exception  EOFException  if this stream reaches the end before reading
jtulach@146
   503
     *               all the bytes.
jtulach@146
   504
     * @exception  IOException   if an I/O error occurs.
jtulach@146
   505
     */
jtulach@146
   506
    double readDouble() throws IOException;
jtulach@146
   507
jtulach@146
   508
    /**
jtulach@146
   509
     * Reads the next line of text from the input stream.
jtulach@146
   510
     * It reads successive bytes, converting
jtulach@146
   511
     * each byte separately into a character,
jtulach@146
   512
     * until it encounters a line terminator or
jtulach@146
   513
     * end of
jtulach@146
   514
     * file; the characters read are then
jtulach@146
   515
     * returned as a <code>String</code>. Note
jtulach@146
   516
     * that because this
jtulach@146
   517
     * method processes bytes,
jtulach@146
   518
     * it does not support input of the full Unicode
jtulach@146
   519
     * character set.
jtulach@146
   520
     * <p>
jtulach@146
   521
     * If end of file is encountered
jtulach@146
   522
     * before even one byte can be read, then <code>null</code>
jtulach@146
   523
     * is returned. Otherwise, each byte that is
jtulach@146
   524
     * read is converted to type <code>char</code>
jtulach@146
   525
     * by zero-extension. If the character <code>'\n'</code>
jtulach@146
   526
     * is encountered, it is discarded and reading
jtulach@146
   527
     * ceases. If the character <code>'\r'</code>
jtulach@146
   528
     * is encountered, it is discarded and, if
jtulach@146
   529
     * the following byte converts &#32;to the
jtulach@146
   530
     * character <code>'\n'</code>, then that is
jtulach@146
   531
     * discarded also; reading then ceases. If
jtulach@146
   532
     * end of file is encountered before either
jtulach@146
   533
     * of the characters <code>'\n'</code> and
jtulach@146
   534
     * <code>'\r'</code> is encountered, reading
jtulach@146
   535
     * ceases. Once reading has ceased, a <code>String</code>
jtulach@146
   536
     * is returned that contains all the characters
jtulach@146
   537
     * read and not discarded, taken in order.
jtulach@146
   538
     * Note that every character in this string
jtulach@146
   539
     * will have a value less than <code>&#92;u0100</code>,
jtulach@146
   540
     * that is, <code>(char)256</code>.
jtulach@146
   541
     *
jtulach@146
   542
     * @return the next line of text from the input stream,
jtulach@146
   543
     *         or <CODE>null</CODE> if the end of file is
jtulach@146
   544
     *         encountered before a byte can be read.
jtulach@146
   545
     * @exception  IOException  if an I/O error occurs.
jtulach@146
   546
     */
jtulach@146
   547
    String readLine() throws IOException;
jtulach@146
   548
jtulach@146
   549
    /**
jtulach@146
   550
     * Reads in a string that has been encoded using a
jtulach@146
   551
     * <a href="#modified-utf-8">modified UTF-8</a>
jtulach@146
   552
     * format.
jtulach@146
   553
     * The general contract of <code>readUTF</code>
jtulach@146
   554
     * is that it reads a representation of a Unicode
jtulach@146
   555
     * character string encoded in modified
jtulach@146
   556
     * UTF-8 format; this string of characters
jtulach@146
   557
     * is then returned as a <code>String</code>.
jtulach@146
   558
     * <p>
jtulach@146
   559
     * First, two bytes are read and used to
jtulach@146
   560
     * construct an unsigned 16-bit integer in
jtulach@146
   561
     * exactly the manner of the <code>readUnsignedShort</code>
jtulach@146
   562
     * method . This integer value is called the
jtulach@146
   563
     * <i>UTF length</i> and specifies the number
jtulach@146
   564
     * of additional bytes to be read. These bytes
jtulach@146
   565
     * are then converted to characters by considering
jtulach@146
   566
     * them in groups. The length of each group
jtulach@146
   567
     * is computed from the value of the first
jtulach@146
   568
     * byte of the group. The byte following a
jtulach@146
   569
     * group, if any, is the first byte of the
jtulach@146
   570
     * next group.
jtulach@146
   571
     * <p>
jtulach@146
   572
     * If the first byte of a group
jtulach@146
   573
     * matches the bit pattern <code>0xxxxxxx</code>
jtulach@146
   574
     * (where <code>x</code> means "may be <code>0</code>
jtulach@146
   575
     * or <code>1</code>"), then the group consists
jtulach@146
   576
     * of just that byte. The byte is zero-extended
jtulach@146
   577
     * to form a character.
jtulach@146
   578
     * <p>
jtulach@146
   579
     * If the first byte
jtulach@146
   580
     * of a group matches the bit pattern <code>110xxxxx</code>,
jtulach@146
   581
     * then the group consists of that byte <code>a</code>
jtulach@146
   582
     * and a second byte <code>b</code>. If there
jtulach@146
   583
     * is no byte <code>b</code> (because byte
jtulach@146
   584
     * <code>a</code> was the last of the bytes
jtulach@146
   585
     * to be read), or if byte <code>b</code> does
jtulach@146
   586
     * not match the bit pattern <code>10xxxxxx</code>,
jtulach@146
   587
     * then a <code>UTFDataFormatException</code>
jtulach@146
   588
     * is thrown. Otherwise, the group is converted
jtulach@146
   589
     * to the character:<p>
jtulach@146
   590
     * <pre><code>(char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
jtulach@146
   591
     * </code></pre>
jtulach@146
   592
     * If the first byte of a group
jtulach@146
   593
     * matches the bit pattern <code>1110xxxx</code>,
jtulach@146
   594
     * then the group consists of that byte <code>a</code>
jtulach@146
   595
     * and two more bytes <code>b</code> and <code>c</code>.
jtulach@146
   596
     * If there is no byte <code>c</code> (because
jtulach@146
   597
     * byte <code>a</code> was one of the last
jtulach@146
   598
     * two of the bytes to be read), or either
jtulach@146
   599
     * byte <code>b</code> or byte <code>c</code>
jtulach@146
   600
     * does not match the bit pattern <code>10xxxxxx</code>,
jtulach@146
   601
     * then a <code>UTFDataFormatException</code>
jtulach@146
   602
     * is thrown. Otherwise, the group is converted
jtulach@146
   603
     * to the character:<p>
jtulach@146
   604
     * <pre><code>
jtulach@146
   605
     * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
jtulach@146
   606
     * </code></pre>
jtulach@146
   607
     * If the first byte of a group matches the
jtulach@146
   608
     * pattern <code>1111xxxx</code> or the pattern
jtulach@146
   609
     * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
jtulach@146
   610
     * is thrown.
jtulach@146
   611
     * <p>
jtulach@146
   612
     * If end of file is encountered
jtulach@146
   613
     * at any time during this entire process,
jtulach@146
   614
     * then an <code>EOFException</code> is thrown.
jtulach@146
   615
     * <p>
jtulach@146
   616
     * After every group has been converted to
jtulach@146
   617
     * a character by this process, the characters
jtulach@146
   618
     * are gathered, in the same order in which
jtulach@146
   619
     * their corresponding groups were read from
jtulach@146
   620
     * the input stream, to form a <code>String</code>,
jtulach@146
   621
     * which is returned.
jtulach@146
   622
     * <p>
jtulach@146
   623
     * The <code>writeUTF</code>
jtulach@146
   624
     * method of interface <code>DataOutput</code>
jtulach@146
   625
     * may be used to write data that is suitable
jtulach@146
   626
     * for reading by this method.
jtulach@146
   627
     * @return     a Unicode string.
jtulach@146
   628
     * @exception  EOFException            if this stream reaches the end
jtulach@146
   629
     *               before reading all the bytes.
jtulach@146
   630
     * @exception  IOException             if an I/O error occurs.
jtulach@146
   631
     * @exception  UTFDataFormatException  if the bytes do not represent a
jtulach@146
   632
     *               valid modified UTF-8 encoding of a string.
jtulach@146
   633
     */
jtulach@146
   634
    String readUTF() throws IOException;
jtulach@146
   635
}