DataInput接口没有引入的包或继承的类;
接口注释如下:
/** * The {@code DataInput} 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} * from data in * <a href="#modified-utf-8">modified UTF-8</a> * 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} * (which is a kind of {@code IOException}) * is thrown. If any byte cannot be read for * any reason other than end of file, an {@code IOException} * other than {@code EOFException} is * thrown. In particular, an {@code IOException} * may be thrown if the input stream has been * closed. * * <h3><a name="modified-utf-8">Modified UTF-8</a></h3> * <p> * Implementations of the DataInput and DataOutput interfaces represent * Unicode strings in a format that is a slight modification of UTF-8. * (For information regarding the standard UTF-8 format, see section * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version * 4.0</i>). * Note that in the following table, the most significant bit appears in the * far left-hand column. * * <blockquote> * <table border="1" cellspacing="0" cellpadding="8" * summary="Bit values and bytes"> * <tr> * <th colspan="9"><span style="font-weight:normal"> * All characters in the range {@code '\u005Cu0001'} to * {@code '\u005Cu007F'} are represented by a single byte:</span></th> * </tr> * <tr> * <td></td> * <th colspan="8" id="bit_a">Bit Values</th> * </tr> * <tr> * <th id="byte1_a">Byte 1</th> * <td><center>0</center> * <td colspan="7"><center>bits 6-0</center> * </tr> * <tr> * <th colspan="9"><span style="font-weight:normal"> * The null character {@code '\u005Cu0000'} and characters * in the range {@code '\u005Cu0080'} to {@code '\u005Cu07FF'} are * represented by a pair of bytes:</span></th> * </tr> * <tr> * <td></td> * <th colspan="8" id="bit_b">Bit Values</th> * </tr> * <tr> * <th id="byte1_b">Byte 1</th> * <td><center>1</center> * <td><center>1</center> * <td><center>0</center> * <td colspan="5"><center>bits 10-6</center> * </tr> * <tr> * <th id="byte2_a">Byte 2</th> * <td><center>1</center> * <td><center>0</center> * <td colspan="6"><center>bits 5-0</center> * </tr> * <tr> * <th colspan="9"><span style="font-weight:normal"> * {@code char} values in the range {@code '\u005Cu0800'} * to {@code '\u005CuFFFF'} are represented by three bytes:</span></th> * </tr> * <tr> * <td></td> * <th colspan="8"id="bit_c">Bit Values</th> * </tr> * <tr> * <th id="byte1_c">Byte 1</th> * <td><center>1</center> * <td><center>1</center> * <td><center>1</center> * <td><center>0</center> * <td colspan="4"><center>bits 15-12</center> * </tr> * <tr> * <th id="byte2_b">Byte 2</th> * <td><center>1</center> * <td><center>0</center> * <td colspan="6"><center>bits 11-6</center> * </tr> * <tr> * <th id="byte3">Byte 3</th> * <td><center>1</center> * <td><center>0</center> * <td colspan="6"><center>bits 5-0</center> * </tr> * </table> * </blockquote> * <p> * The differences between this format and the * standard UTF-8 format are the following: * <ul> * <li>The null byte {@code '\u005Cu0000'} is encoded in 2-byte format * rather than 1-byte, so that the encoded strings never have * embedded nulls. * <li>Only the 1-byte, 2-byte, and 3-byte formats are used. * <li><a href="../lang/Character.html#unicode">Supplementary characters</a> * are represented in the form of surrogate pairs. * </ul> * @author Frank Yellin * @see java.io.DataInputStream * @see java.io.DataOutput * @since JDK1.0 */
大意如下:
该接口用于从二进制流中读取字节,并根据的所有基本类型对其进行重构
同时也可以根据修改版UTF-8的格式重构字符串
如果在被请求的byte数目被读取之前就读取到文件末尾,一个文件结束事件(EOFException)将会被抛出
如果在文件结束之前由于各种原因不能读取文件,一个除了EOFException意外的IO异常将会被抛出
尤其当输入流关闭后将会抛出一个IO异常
修改版UTF-8:(注释里面插标签语言真是看的头疼)
本接口规定了15个方法:
传入缓冲区数组的readFully
传入缓冲区数组、读取指针、读取长度的readFully
跳过输入流后续n个字符的skipBytes
读入输入字符对其进行条件检测的readBoolean
读取输入流中单个字节(有符号返回
读取输入流中单个字节(无符号返回
读取输入流中两个字节(有符号返回
读取输入流中两个字节(无符号返回
读取两个字节并转化为字符类型
读取四个字节返回int值
读取八个字节返回long值
读取四个字节返回float值
读取8个字节返回double
读入单行文本
读入修改版UTF-8,返回字符串
说实话,接口难以去分析什么(毕竟没有源码,只能看看注释),看注释不如直接翻看文档,不过接口也必须要学习,有助理解许多完成该接口的类的功能。