Name

DataInput

Synopsis

This interface is implemented by classes that can read strings and Java primitive types from a platform-independent binary encoding created by a class implementing the DataOutput interface.

The class provides methods for reading primitives of type boolean, byte, char, int, long and short. There is also provision for reading an unsigned short, which is a 16-bit value that is returned in a Java int without sign extension.

Strings are held in a slightly modified form of UTF-8, which results in Unicode characters with values in the range 0-127 inclusive being encoded as a single byte. This is an optimization for the most common characters in Western locales. The readUTF() returns a String from a sequence of bytes held in this form.

The readFully() methods read a stream of bytes into a buffer, blocking until either a specified number of bytes has been read or an end-of-file is reached. This is a convenience method that repeatedly reads from the underlying input stream until the end condition is met; it removes the need for application code to include this loop.

public interface DataInput {  
// Public Instance Methods
   public abstract boolean readBoolean() throws IOException;  
   public abstract byte readByte() throws IOException;  
   public abstract char readChar() throws IOException;  
   public abstract void readFully(
        byte[] b) throws IOException;  
   public abstract void readFully(byte[] b, int off, 
        int len) throws IOException;  
   public abstract int readInt() throws IOException; ...

Get J2ME in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.