datainput.java

来自「This is a resource based on j2me embedde」· Java 代码 · 共 509 行 · 第 1/2 页

JAVA
509
字号
/* * @(#)DataInput.java	1.24 06/10/10 * * Copyright  1990-2008 Sun Microsystems, Inc. All Rights Reserved.   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER   *    * This program is free software; you can redistribute it and/or   * modify it under the terms of the GNU General Public License version   * 2 only, as published by the Free Software Foundation.    *    * This program is distributed in the hope that it will be useful, but   * WITHOUT ANY WARRANTY; without even the implied warranty of   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   * General Public License version 2 for more details (a copy is   * included at /legal/license.txt).    *    * You should have received a copy of the GNU General Public License   * version 2 along with this work; if not, write to the Free Software   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA   * 02110-1301 USA    *    * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa   * Clara, CA 95054 or visit www.sun.com if you need additional   * information or have any questions.  * */package java.io;/** * The <code>DataInput</code> interface provides * for reading bytes from a binary stream and * reconstructing from them data in any of * the Java primitive types. There is also * a * facility for reconstructing a <code>String</code> * from data in Java modified UTF-8 format. * <p> * It is generally true of all the reading * routines in this interface that if end of * file is reached before the desired number * of bytes has been read, an <code>EOFException</code> * (which is a kind of <code>IOException</code>) * is thrown. If any byte cannot be read for * any reason other than end of file, an <code>IOException</code> * other than <code>EOFException</code> is * thrown. In particular, an <code>IOException</code> * may be thrown if the input stream has been * closed. * * @version 1.16, 02/02/00 * @see     java.io.DataInputStream * @see     java.io.DataOutput * @since   JDK1.0 */publicinterface DataInput {    /**     * Reads some bytes from an input     * stream and stores them into the buffer     * array <code>b</code>. The number of bytes     * read is equal     * to the length of <code>b</code>.     * <p>     * This method blocks until one of the     * following conditions occurs:<p>     * <ul>     * <li><code>b.length</code>     * bytes of input data are available, in which     * case a normal return is made.     *     * <li>End of     * file is detected, in which case an <code>EOFException</code>     * is thrown.     *     * <li>An I/O error occurs, in     * which case an <code>IOException</code> other     * than <code>EOFException</code> is thrown.     * </ul>     * <p>     * If <code>b</code> is <code>null</code>,     * a <code>NullPointerException</code> is thrown.     * If <code>b.length</code> is zero, then     * no bytes are read. Otherwise, the first     * byte read is stored into element <code>b[0]</code>,     * the next one into <code>b[1]</code>, and     * so on.     * If an exception is thrown from     * this method, then it may be that some but     * not all bytes of <code>b</code> have been     * updated with data from the input stream.     *     * @param     b   the buffer into which the data is read.     * @exception  EOFException  if this stream reaches the end before reading     *               all the bytes.     * @exception  IOException   if an I/O error occurs.     */    void readFully(byte b[]) throws IOException;    /**     *     * Reads <code>len</code>     * bytes from     * an input stream.     * <p>     * This method     * blocks until one of the following conditions     * occurs:<p>     * <ul>     * <li><code>len</code> bytes     * of input data are available, in which case     * a normal return is made.     *     * <li>End of file     * is detected, in which case an <code>EOFException</code>     * is thrown.     *     * <li>An I/O error occurs, in     * which case an <code>IOException</code> other     * than <code>EOFException</code> is thrown.     * </ul>     * <p>     * If <code>b</code> is <code>null</code>,     * a <code>NullPointerException</code> is thrown.     * If <code>off</code> is negative, or <code>len</code>     * is negative, or <code>off+len</code> is     * greater than the length of the array <code>b</code>,     * then an <code>IndexOutOfBoundsException</code>     * is thrown.     * If <code>len</code> is zero,     * then no bytes are read. Otherwise, the first     * byte read is stored into element <code>b[off]</code>,     * the next one into <code>b[off+1]</code>,     * and so on. The number of bytes read is,     * at most, equal to <code>len</code>.     *     * @param     b   the buffer into which the data is read.     * @param off  an int specifying the offset into the data.     * @param len  an int specifying the number of bytes to read.     * @exception  EOFException  if this stream reaches the end before reading     *               all the bytes.     * @exception  IOException   if an I/O error occurs.     */    void readFully(byte b[], int off, int len) throws IOException;    /**     * Makes an attempt to skip over     * <code>n</code> bytes     * of data from the input     * stream, discarding the skipped bytes. However,     * it may skip     * over some smaller number of     * bytes, possibly zero. This may result from     * any of a     * number of conditions; reaching     * end of file before <code>n</code> bytes     * have been skipped is     * only one possibility.     * This method never throws an <code>EOFException</code>.     * The actual     * number of bytes skipped is returned.     *     * @param      n   the number of bytes to be skipped.     * @return     the number of bytes actually skipped.     * @exception  IOException   if an I/O error occurs.     */    int skipBytes(int n) throws IOException;    /**     * Reads one input byte and returns     * <code>true</code> if that byte is nonzero,     * <code>false</code> if that byte is zero.     * This method is suitable for reading     * the byte written by the <code>writeBoolean</code>     * method of interface <code>DataOutput</code>.     *     * @return     the <code>boolean</code> value read.     * @exception  EOFException  if this stream reaches the end before reading     *               all the bytes.     * @exception  IOException   if an I/O error occurs.     */    boolean readBoolean() throws IOException;    /**     * Reads and returns one input byte.     * The byte is treated as a signed value in     * the range <code>-128</code> through <code>127</code>,     * inclusive.     * This method is suitable for     * reading the byte written by the <code>writeByte</code>     * method of interface <code>DataOutput</code>.     *     * @return     the 8-bit value read.     * @exception  EOFException  if this stream reaches the end before reading     *               all the bytes.     * @exception  IOException   if an I/O error occurs.     */    byte readByte() throws IOException;    /**     * Reads one input byte, zero-extends     * it to type <code>int</code>, and returns     * the result, which is therefore in the range     * <code>0</code>     * through <code>255</code>.     * This method is suitable for reading     * the byte written by the <code>writeByte</code>     * method of interface <code>DataOutput</code>     * if the argument to <code>writeByte</code>     * was intended to be a value in the range     * <code>0</code> through <code>255</code>.     *     * @return     the unsigned 8-bit value read.     * @exception  EOFException  if this stream reaches the end before reading     *               all the bytes.     * @exception  IOException   if an I/O error occurs.     */    int readUnsignedByte() throws IOException;    /**     * Reads two input bytes and returns     * a <code>short</code> value. Let <code>a</code>     * be the first byte read and <code>b</code>     * be the second byte. The value     * returned     * is:     * <p><pre><code>(short)((a &lt;&lt; 8) * | (b &amp; 0xff))     * </code></pre>     * This method     * is suitable for reading the bytes written     * by the <code>writeShort</code> method of     * interface <code>DataOutput</code>.     *     * @return     the 16-bit value read.     * @exception  EOFException  if this stream reaches the end before reading     *               all the bytes.     * @exception  IOException   if an I/O error occurs.     */    short readShort() throws IOException;    /**     * Reads two input bytes and returns     * an <code>int</code> value in the range <code>0</code>     * through <code>65535</code>. Let <code>a</code>     * be the first byte read and     * <code>b</code>     * be the second byte. The value returned is:     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))     * </code></pre>     * This method is suitable for reading the bytes     * written by the <code>writeShort</code> method     * of interface <code>DataOutput</code>  if     * the argument to <code>writeShort</code>     * was intended to be a value in the range     * <code>0</code> through <code>65535</code>.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?