📄 datainput.java
字号:
/* * Copyright 1995-2002 Sun Microsystems, Inc. All Rights Reserved. * * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */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. * * @author Frank Yellin * @version 1.15, 12/04/99 (CLDC 1.0, Spring 2000) * @see java.io.DataInputStream * @see java.io.DataOutput * @since JDK1.0, CLDC 1.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 skipped, which is always <code>n</code>. * @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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -