This class is a type of FilterInputStream that allows you to read binary representations of Java primitive data types in a portable way. Create a DataInputStream by specifying the InputStream that is to be filtered in the call to the constructor. DataInputStream reads only primitive Java types; use ObjectInputStream to read object values. Many of the methods read and return a single Java primitive type, in binary format, from the stream. readUnsignedByte( ) and readUnsignedShort( ) read unsigned values and return them as int values, since unsigned byte and short types are not supported in Java. read( ) reads data into an array of bytes, blocking until at least some data is available. By contrast, readFully( ) reads data into an array of bytes, but blocks until all requested data becomes available. skipBytes( ) blocks until the specified number of bytes have been read and discarded. readLine( ) reads characters from the stream until it encounters a newline, a carriage return, or a newline/ carriage return pair. The returned string is not terminated with a newline or carriage return. This method is deprecated as of Java 1.1; see BufferedReader for an alternative. readUTF( ) reads a string of Unicode text encoded in a slightly modified version of the UTF-8 transformation format. UTF-8 is an ASCII-compatible encoding of Unicode characters that is often used for the transmission and storage of Unicode text. This class uses a modified UTF-8 encoding that never contains embedded null characters. Figure 9-10. java.io.DataInputStream public class DataInputStream extends FilterInputStream implements DataInput { // Public Constructors public DataInputStream (InputStream in ); // Public Class Methods public static final String readUTF (DataInput in ) throws IOException; // Methods Implementing DataInput public final boolean readBoolean ( ) throws IOException; public final byte readByte ( ) throws IOException; public final char readChar ( ) throws IOException; public final double readDouble ( ) throws IOException; public final float readFloat ( ) throws IOException; public final void readFully (byte[ ] b ) throws IOException; public final void readFully (byte[ ] b , int off , int len ) throws IOException; public final int readInt ( ) throws IOException; public final long readLong ( ) throws IOException; public final short readShort ( ) throws IOException; public final int readUnsignedByte ( ) throws IOException; public final int readUnsignedShort ( ) throws IOException; public final String readUTF ( ) throws IOException; public final int skipBytes (int n ) throws IOException; // Public Methods Overriding FilterInputStream public final int read (byte[ ] b ) throws IOException; public final int read (byte[ ] b , int off , int len ) throws IOException; // Deprecated Public Methods # public final String readLine ( ) throws IOException; Implements: DataInput } |