Tải bản đầy đủ (.pdf) (52 trang)

J2ME in a Nutshell phần 7 pps

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (915.48 KB, 52 trang )

J2ME in a Nutshell
307
Type Of
This section lists all of the fields and constants that are of this type, which can
help you figure out how to obtain an object of this type.
II.3.6 A Note About Class Names
Throughout the quick reference, you'll notice that classes are sometimes
referred to by class name alone and at other times referred to by class name
and package name. If package names were always used, the class synopses
would become long and hard to read. On the other hand, if package names
were never used, it would sometimes be difficult to know what class was being
referred to. The rules for including or omitting the package name are complex.
They can be summarized approximately as follows, however:
• If the class name alone is ambiguous, the package name is always used.
• If the class is part of the java.lang package or is a very commonly
used class, the package name is omitted.
• If the class being referred to is part of the current package (and has a
quick-reference entry in the current chapter), the package name is
omitted.
J2ME in a Nutshell
308
Chapter 10. J2ME Packages and Classes
There are two types of packages and classes in the J2ME platform:
• Those that are inherited from the J2SE platform
• Those that are specific to J2ME and have no counterpart in J2SE
Most of J2ME falls into the first category. Depending on the configuration and profile you are
using, you can use a different subset of J2SE packages and a subset of those packages that are
part of J2ME itself, as shown in Table 10-1. Some J2SE packages, particularly those
associated with the user interface, are not currently part of any J2ME profile. These classes
are listed in Table 10-2.
Even when a package is available, it is not necessarily the case that all of its classes are


included in the J2ME implementation. The remaining sections of this chapter list all classes in
the J2SE packages included in at least one J2ME profile and show, for each configuration and
profile, the classes applicable to it.
1
In some cases, you'll see that a J2SE class is not available
at all in J2ME. Classes are usually omitted because of resource limitations, but there has also
been an effort to remove classes that are deprecated in Java 2 Version 1.3; where this is the
case, it is indicated in the tables.
10.1 J2ME Packages
The following table shows the packages that make up J2ME and the configurations and
profiles in which they are available. For example, the appearing on the top row of the
"CLDC 1.0" column indicates that the java.io package is available in the CLDC
configuration.
Table 10-1. J2ME Package List
Package
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
java.io

java.lang

java.lang.ref




java.lang.reflect



java.math



java.net



java.rmi



java.rmi.activation



java.rmi.dgc



java.rmi.registry




java.rmi.server



java.security



java.security.acl



java.security.cert



java.security.interfaces



java.security.spec




1
Since all of the J2ME profiles are based on Java 2 Version 1.3, the tables in this chapter show the packages and classes from that version.
J2ME in a Nutshell
309

java.text



java.util

java.util.jar



java.util.zip



javax.microedition.io

javax.microedition.lcdui





javax.microedition.midlet





javax.microedition.rms






Note that the presence of a package does not mean that all classes in that J2SE package are
available in J2ME. Class availability is covered in later sections of this chapter.
10.2 J2SE Packages Not Present in J2ME
The J2SE packages listed in the following table are not included in any J2ME configuration or
profile. Since all J2ME configurations and profiles are based on Java 2 Version 1.3, this list
does not include classes available in later J2SE platform releases.
Table 10-2. J2SE Packages Not Included in J2ME
java.applet javax.swing
java.awt javax.swing.border
java.awt.color javax.swing.colorchooser
java.awt.datatransfer javax.swing.event
java.awt.dnd javax.swing.filechooser
java.awt.event javax.swing.plaf
java.awt.font javax.swing.plaf.basic
java.awt.geom javax.swing.plaf.metal
java.awt.im javax.swing.plaf.multi
java.awt.im.spi javax.swing.table
java.awt.image javax.swing.text
java.awt.image.renderable javax.swing.text.html
java.awt.print javax.swing.text.html.parser
java.beans javax.swing.text.rtf
java.beans.beancontext javax.swing.tree
java.sql javax.swing.undo
javax.accessibility javax.transaction
javax.naming org.omg.CORBA
javax.naming.directory org.omg.CORBA_2_3

javax.naming.event org.omg.CORBA_2_3.portable
javax.naming.ldap org.omg.CORBA.DynAnyPackage
javax.naming.spi org.omg.CORBA.ORBPackage
javax.rmi org.omg.CORBA.portable
javax.rmi.CORBA org.omg.CORBA.TypeCodePackage
javax.sound.midi org.omg.CosNaming
javax.sound.midi.spi org.omg.CosNaming.NamingContextPackage
javax.sound.sampled org.omg.SendingContext
javax.sound.sampled.spi org.omg.stub.java.rmi
J2ME in a Nutshell
310
10.3 J2ME Package Contents
This section contains tables that indicate which classes are available in each of the J2ME
packages, itemized by configuration or profile. The presence of a symbol in a cell indicates
that the class corresponding to its row is available in the configuration or profile
corresponding to its column.
10.3.1 The java.io Package
Table 10-3. Classes in the J2ME java.io Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
BufferedInputStream




BufferedOutputStream



BufferedReader



BufferedWriter



ByteArrayInputStream

ByteArrayOutputStream

CharArrayReader



CharArrayWriter



CharConversionException




DataInput

DataInputStream

DataOutput

DataOutputStream

EOFException

Externalizable



File



FileDescriptor



FileFilter



FilenameFilter




FileInputStream



FileNotFoundException



FileOutputStream



FilePermission



FileReader



FileWriter



FilterInputStream



FilterOutputStream




FilterReader



FilterWriter



InputStream

InputStreamReader

InterruptedIOException

InvalidClassException



InvalidObjectException



IOException

LineNumberInputStream
Deprecated
J2ME in a Nutshell

311
LineNumberReader



NotActiveException



NotSerializableException



ObjectInput



ObjectInputStream



ObjectInputStream.GetField



ObjectInputValidation



ObjectOutput




ObjectOutputStream



ObjectOutputStream.PutField



ObjectStreamClass



ObjectStreamConstants



ObjectStreamException



ObjectStreamField



OptionalDataException




OutputStream

OutputStreamWriter

PipedInputStream



PipedOutputStream



PipedReader



PipedWriter



PrintStream

PrintWriter



PushbackInputStream




PushbackReader



RandomAccessFile



Reader

SequenceInputStream



Serializable



SerializablePermission



StreamCorruptedException



StreamTokenizer




StringBufferInputStream
Deprecated
StringReader



StringWriter



SyncFailedException



UnsupportedEncodingException

UTFDataFormatException

Writer

WriteAbortedException



10.3.2 The java.lang Package
Table 10-4. Classes in the J2ME java.lang Package
Class
CLDC
1.0

MID Profile
1.0
CDC
1.0
Foundation
Profile 1.0
RMI Profile
1.0
AbstractMethodError



ArithmeticException

J2ME in a Nutshell
312
ArrayIndexOutOfBoundsException

ArrayStoreException

Boolean

Byte

Character

Character.Subset




Character.UnicodeBlock



Class

ClassCastException

ClassCircularityError



ClassFormatError



ClassLoader



ClassNotFoundException

Cloneable



CloneNotSupportedException




Comparable



Compiler



Double



Error

Exception

ExceptionInInitializerError



Float



IllegalAccessError



IllegalAccessException


IllegalArgumentException

IllegalMonitorStateException

IllegalStateException



IllegalThreadStateException

IncompatibleClassChangeError



IndexOutOfBoundsException

InheritableThreadLocal



InstantiationError

InstantiationException



Integer

InternalError




InterruptedException

LinkageError



Long

Math

NegativeArraySizeException

NoClassDefFoundError



NoSuchFieldError



NoSuchFieldException



NoSuchMethodError




NoSuchMethodException



NullPointerException

Number



NumberFormatException

J2ME in a Nutshell
313
Object

OutOfMemoryError

Package



Process



Runnable

Runtime


RuntimeException

RuntimePermission



SecurityException

SecurityManager



Short

StackOverflowError



StrictMath



String

StringBuffer

StringIndexOutOfBoundsException

System


Thread

ThreadDeath



ThreadGroup



ThreadLocal



Throwable

UnknownError



UnsatisfiedLinkError



UnsupportedClassVersionError



UnsupportedOperationException




VerifyError



VirtualMachineError

Void



10.3.3 The java.lang.ref Package
Table 10-5. Classes in the J2ME java.lang.ref Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
PhantomReference



Reference



ReferenceQueue



SoftReference




WeakReference



10.3.4 The java.lang.reflect Package
Table 10-6. Classes in the J2ME java.lang.reflect Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
AccessibleObject



Array



Constructor




J2ME in a Nutshell
314
Field



InvocationHandler



InvocationTargetException



Member



Method



Modifier



Proxy




ReflectPermission



UndeclaredThrowableException



10.3.5 The java.math Package
Table 10-7. Classes in the J2ME java.math Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
BigDecimal


BigInteger



10.3.6 The java.net Package
Table 10-8. Classes in the J2ME java.net Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile

1.0
Authenticator



BindException



ConnectException



ContentHandler



ContentHandlerFactory



DatagramPacket



DatagramSocket



DatagramSocketImpl




DatagramSocketImplFactory



FileNameMap



HttpURLConnection



InetAddress



JarURLConnection



MalformedURLException



MulticastSocket




NetPermission



NoRouteToHostException



PasswordAuthentication



ProtocolException



ServerSocket



Socket



SocketException



SocketImpl




SocketImplFactory



SocketOptions



SocketPermission



J2ME in a Nutshell
315
UnknownHostException



UnknownServiceException



URL



URLClassLoader




URLConnection



URLDecoder



URLEncoder



URLStreamHandler



URLStreamHandlerFactory



10.3.7 The java.rmi Package
Table 10-9. Classes in the J2ME java.rmi Package
Class
CLDC
1.0
MID Profile
1.0

CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
AccessException



AlreadyBoundException



ConnectException



ConnectIOException



MarshalException



MarshalledObject




Naming



NoSuchObjectException



NotBoundException



Remote



RemoteException



RMISecurityException


RMISecurityManager



ServerError




ServerException



ServerRuntimeException


StubNotFoundException



UnexpectedException



UnknownHostException



UnmarshalException



10.3.8 The java.rmi.activation Package
Table 10-10. Classes in the J2ME java.rmi.activation Package
Class
CLDC
1.0
MID Profile

1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
Activatable


ActivateFailedException



ActivationDesc


ActivationException



ActivationGroup


ActivationGroupDesc


J2ME in a Nutshell
316
ActivationGroupDesc.

CommandEnvironment


ActivationGroupID


ActivationID



ActivationInstantiator


ActivationMonitor


ActivationSystem


Activator



UnknownGroupException


UnknownObjectException




The CDC RMI profile contains only a small subset of the J2SE java.rmi.activation
package, because it provides only the client-side functionality. The server side is assumed to
be hosted in a J2SE or J2EE environment.
10.3.9 The java.rmi.dgc Package
Table 10-11. Classes in the J2ME java.rmi.dgc Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
DGC



Lease



VMID



10.3.10 The java.rmi.registry Package
Table 10-12. Classes in the J2ME java.rmi.registry Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
LocateRegistry



Registry



RegistryHandler

Deprecated
10.3.11 The java.rmi.server Package
Table 10-13. Classes in the java.rmi.server Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
ExportException



LoaderHandler
Deprecated
LogStream
Deprecated
ObjID



Operation




RemoteCall



RemoteObject



RemoteRef



RemoteServer



RemoteStub



RMIClassLoader



J2ME in a Nutshell
317
RMIClientSocketFactory




RMIFailureHandler



RMIServerSocketFactory



RMISocketFactory



ServerCloneException



ServerNotActiveException



ServerRef


Skeleton
Deprecated
SkeletonMismatchException
Deprecated
SkeletonNotFoundException
Deprecated
SocketSecurityException




UID



UnicastRemoteObject



Unreferenced



10.3.12 The java.security Package
Table 10-14. Classes in the J2ME java.security Package
Class
CLDC
1.0
MID
Profile 1.0
CDC
1.0
Foundation
Profile 1.0
RMI
Profile 1.0
AccessControlContext




AccessControlException



AccessController



AlgorithmParameterGenerator



AlgorithmParameterGeneratorSpi



AlgorithmParameters



AlgorithmParametersSpi



AllPermission




BasicPermission



Certificate



CodeSource



DigestException



DigestInputStream



DigestOutputStream



DomainCombiner



GeneralSecurityException




Guard



GuardedObject



Identity



IdentityScope



InvalidAlgorithmParameterException



InvalidKeyException



InvalidParameterException




Key



KeyException



KeyFactory



KeyFactorySpi



KeyManagementException



J2ME in a Nutshell
318
KeyPair



KeyPairGenerator




KeyPairGeneratorSpi



KeyStore



KeyStoreException



KeyStoreSpi



MessageDigest



MessageDigestSpi



NoSuchAlgorithmException



NoSuchProviderException




Permission



PermissionCollection



Permissions



Policy



Principal



PrivateKey



PrivilegedAction




PrivilegedActionException



PrivilegedExceptionAction



ProtectionDomain



Provider



ProviderException



PublicKey



SecureClassLoader



SecureRandom




SecureRandomSpi



Security



SecurityPermission



Signature



SignatureException



SignatureSpi



SignedObject




Signer



UnrecoverableKeyException



UnresolvedPermission



10.3.13 The java.security.acl Package
Table 10-15. Classes in the J2ME java.security.acl Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
Acl



AclEntry



AclNotFoundException



Group




LastOwnerException



NotOwnerException



Owner



Permission



J2ME in a Nutshell
319
10.3.14 The java.security.cert Package
Table 10-16. Classes in the J2ME java.security.cert Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation
Profile 1.0

RMI Profile
1.0
Certificate



Certificate.CertificateRep



CertificateEncodingException



CertificateException



CertificateExpiredException



CertificateFactory



CertificateFactorySpi




CertificateNotYetValidException



CertificateParsingException



CRL



CRLException



X509Certificate



X509CRL



X509CRLEntry



X509Extension




10.3.15 The java.security.interfaces Package
Table 10-17. Classes in tn the J2ME java.security.interfaces Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
DSAKey



DSAKeyPairGenerator



DSAParams



DSAPrivateKey



DSAPublicKey



RSAKey



RSAPrivateCrtKey




RSAPrivateKey



RSAPublicKey



10.3.16 The java.security.spec Package
Table 10-18. Classes in the J2ME java.security.spec Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
AlgorithmParameterSpec



DSAParameterSpec




DSAPrivateKeySpec



DSAPublicKeySpec



EncodedKeySpec



InvalidKeySpecException



InvalidParameterSpecException



KeySpec



J2ME in a Nutshell
320
PKCS8EncodedKeySpec




RSAKeyGenParameterSpec



RSAPrivateCrtKeySpec



RSAPrivateKeySpec



RSAPublicKeySpec



X509EncodedKeySpec



10.3.17 The java.text Package
Table 10-19. Classes in the J2ME java.text Package
Class
CLDC
1.0
MID
Profile
1.0

CDC
1.0
Foundation
Profile 1.0
RMI
Profile
1.0
Annotation



AttributedCharacterIterator



AttributedCharacterIterator.Attribute



AttributedString



BreakIterator



CharacterIterator




ChoiceFormat



CollationElementIterator



CollationKey



Collator



DateFormat



DateFormatSymbols



DecimalFormat



DecimalFormatSymbols




FieldPosition



Format



MessageFormat



NumberFormat



ParseException



ParsePosition



RuleBasedCollator




SimpleDateFormat



StringCharacterIterator



10.3.18 The java.util Package
Table 10-20. Classes in the J2ME java.util Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation
Profile 1.0
RMI Profile
1.0
AbstractCollection



AbstractList




AbstractMap



AbstractSequentialList



AbstractSet



ArrayList



J2ME in a Nutshell
321
Arrays



BitSet



Calendar

Collection




Collections



Comparator



ConcurrentModificationException



Date

Dictionary



EmptyStackException

Enumeration

EventListener



EventObject




GregorianCalendar



HashMap



HashSet



Hashtable

Iterator



LinkedList



List



ListIterator




ListResourceBundle



Locale



Map



Map.Entry



MissingResourceException



NoSuchElementException

Observable



Observer




Properties



PropertyPermission



PropertyResourceBundle



Random

ResourceBundle



Set



SimpleTimeZone



SortedMap




SortedSet



Stack

StringTokenizer



Timer






TimerTask






TimeZone

TooManyListenersException




TreeMap



TreeSet



Vector

WeakHashMap



J2ME in a Nutshell
322
10.3.19 The java.util.jar Package
Table 10-21. Classes in the J2ME java.util.jar Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
Attributes



Attributes.Name



JarEntry




JarException



JarFile



JarInputStream



JarOutputStream



Manifest



10.3.20 The java.util.zip Package
Table 10-22. Classes in the J2ME java.util.zip Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
Adler32




CheckedInputStream



CheckedOutputStream



Checksum



CRC32



DataFormatException



Deflater



DeflaterOutputStream



GZIPInputStream




GZIPOutputStream



Inflater



InflaterInputStream



ZipEntry



ZipFile



ZipException



ZipInputStream




ZipOutputStream



10.3.21 The javax.microedition.io Package
Table 10-23. Classes in the J2ME javax.microedition.io Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
Connection

Connector

ConnectionNotFoundException

ContentConnection

Datagram

DatagramConnection

HttpConnection







InputConnection

J2ME in a Nutshell
323
OutputConnection

StreamConnection

StreamConnectionNotifier

10.3.22 The javax.microedition.lcdui Package
Table 10-24. Classes in the J2ME javax.microedition.lcdui Package
Class CLDC 1.0 MID Profile 1.0 CDC 1.0 Foundation Profile 1.0 RMI Profile 1.0
Alert





AlertType






Canvas





Choice





ChoiceGroup





Command





CommandListener






DateField





Display





Displayable





Font





Form






Gauge





Graphics





Image





ImageItem





Item






ItemStateListener





List





Screen





StringItem





TextBox






TextField





Ticker





10.3.23 The javax.microedition.midlet Package
Table 10-25. Classes in the J2ME javax.microedition.midlet Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
MIDlet






MIDletStateChangeException





10.3.24 The javax.microedition.rms Package
Table 10-26. Classes in the javax.microedition.rms Package
Class
CLDC
1.0
MID Profile
1.0
CDC
1.0
Foundation Profile
1.0
RMI Profile
1.0
InvalidRecordIDException





RecordComparator






J2ME in a Nutshell
324
RecordEnumeration





RecordFilter





RecordListener





RecordStore





RecordStoreException






RecordStoreFullException





RecordStoreNotFoundException





RecordStoreNotOpenException





J2ME in a Nutshell
325

Chapter 11. java.io
Package java.io CLDC 1.0, MIDP 1.0



This package, whose class hierarchy is shown in Figure 11-1, contains interfaces and classes
used to access input and output sources and treat them either as a sequence of 8-bit bytes or
16-bit characters.
The CLDC version of this package contains only the basic classes and interfaces from its
J2SE counterpart that provide 8-bit input and output, together with support for Unicode
conversion using the InputStreamReader and OutputStreamWriter classes. Most of the
concrete input and output stream and reader/writer classes available in J2SE are not provided.
In addition, some abstract classes (such as FilterInputStream) are also omitted so that
derived classes in CLDC are reparented directly to InputStream or OutputStream.
ByteArrayInputStream CLDC 1.0, MIDP 1.0

java.io

This is a subclass of InputStream that returns data from an array of bytes passed into one of
its constructors. It is useful when you have data stored in a byte array and wish to read it as if
it were coming from a file, pipe, or socket. A good example of this is provided by MIDlet
RecordStores, which hold their content in byte arrays. MIDlets typically read these records
by creating a
ByteArrayInputStream from the content of a record and then wrap it with a
DataInputStream to recover strings and Java data types without assuming the format used to
store them.
This class supports the mark() and reset() operations of InputStream. Once constructed,
the byte array from which this stream gets its data cannot be switched. However, because the
data is not copied by the stream, the contents of the array can be modified and then re-read
following a
reset(). Note that such an approach is only practical if the original byte array is
large enough to hold any desired modifications.







J2ME in a Nutshell
326
Figure 11-1. The java.io hierarchy


public class ByteArrayInputStream extends InputStream {
// Public Constructors
public ByteArrayInputStream( byte[] buf);
public ByteArrayInputStream(byte[] buf, int offset,
int length);
// Public Methods Overriding InputStream
public int available(); // synchronized
public void close() throws IOException; // synchronized empty
public void mark( int readAheadLimit);
public boolean markSupported(); // constant
public int read(); // synchronized
public int read( byte[] b, int off, int len); // synchronized
public void reset(); // synchronized
public long skip( long n); // synchronized
// Protected Instance Fields
protected byte[] buf;
protected int count;
protected int mark;
protected int pos;
}
J2ME in a Nutshell
327


ByteArrayOutputStream CLDC 1.0, MIDP 1.0

java.io

This subclass of OutputStream stores data written to it in a buffer which can later be
retrieved using its toByteArray() method. When the stream is created, the buffer is empty. It
is then expanded as data is written to the stream.
ByteArrayOutputStream is often used in J2ME in conjunction with a DataOutputStream to
allow strings and Java primitives types to be stored in a byte array. This byte array is written
to persistent storage on a device using the RecordStore APIs in the
javax.microedition.rms package.

public class ByteArrayOutputStream extends OutputStream {
// Public Constructors
public ByteArrayOutputStream();
public ByteArrayOutputStream( int size);
// Public Instance Methods
public void reset(); // synchronized
public int size();
public byte[] toByteArray(); // synchronized
// Public Methods Overriding OutputStream
public void close() throws IOException; // synchronized
public void write( int b); // synchronized
public void write( byte[] b, int off, int len); // synchronized
// Public Methods Overriding Object
public String toString();
// Protected Instance Fields
protected byte[] buf;
protected int count;

}
DataInput CLDC 1.0, MIDP 1.0

java.io

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
J2ME in a Nutshell
328
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;
public abstract long readLong() throws IOException;
public abstract short readShort() throws IOException;
public abstract int readUnsignedByte() throws IOException;
public abstract int readUnsignedShort(
) throws IOException;
public abstract String readUTF() throws IOException;
public abstract int skipBytes( int
n) throws IOException;
}
Implementations
DataInputStream, javax.microedition.io.Datagram
Passed To
DataInputStream.readUTF()
DataInputStream CLDC 1.0, MIDP 1.0

java.io

This subclass of InputStream implements the methods of the DataInput interface, reading
encoded data as a sequence of bytes from another InputStream. Instances of this class can
not only be created directly, but can also be obtained from various other methods, such as the
openDataInputStream method of javax.microedition.io.Connector. In this case, the
openDataInputStream method returns a stream to read data from a network connection or
some other type of data source accessed using the CLDC Generic Connection Framework.
Note that the CLDC version of this class is derived from InputStream and not
FilterInputStream as in J2SE. This is because CLDC does not have a FilterInputStream
class.
J2ME in a Nutshell
329


public class DataInputStream extends InputStream 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 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 InputStream
public int available() throws IOException;
public void close() throws IOException;
public void mark( int readlimit); //
synchronized
public boolean markSupported();
public int read() throws IOException;
public final int read(

byte[] b) throws IOException;
public final int read(byte[] b, int off,
int len) throws IOException;
public void reset() throws IOException; //
synchronized
public long skip( long n) throws IOException;
// Protected Instance Fields
protected InputStream in;
}
Returned By
javax.microedition.io.Connector.openDataInputStream(),
javax.microedition.io.InputConnection.openDataInputStream()

DataOutput CLDC 1.0, MIDP 1.0

java.io

This interface is implemented by classes that write strings and Java primitive types to
a platform-independent binary encoding that can be read by a class implementing
the DataInput interface.
J2ME in a Nutshell
330
Methods are provided for writing a single byte or an array of bytes as well as primitives of
type boolean, char, int, long and short.
The writeChars() method writes the content of a String as an array of 16-bit characters. In
many cases, it is more efficient to output a String by using the writeUtf() method. This
method encodes the characters in the String using 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.
public interface DataOutput {

// Public Instance Methods
public abstract void write(
byte[] b) throws IOException;
public abstract void write( int b) throws IOException;
public abstract void write(byte[] b, int off,
int len) throws IOException;
public abstract void writeBoolean(
boolean v) throws IOException;
public abstract void writeByte( int v) throws IOException;
public abstract void writeChar( int v) throws IOException;
public abstract void writeChars(
String s) throws IOException;
public abstract void writeInt( int v) throws IOException;
public abstract void writeLong(long v) throws IOException;
public abstract void writeShort(int v) throws IOException;
public abstract void writeUTF(
String str) throws IOException;
}
Implementations
DataOutputStream, javax.microedition.io.Datagram
DataOutputStream CLDC 1.0, MIDP 1.0

java.io

This is a subclass of OutputStream that implements the methods of the DataOutput
interface, writing encoded data as a sequence of bytes to another OutputStream. Instances of
this class can be created directly. In addition, they can also be obtained from various other
sources, such as the openDataOutputStream method of
the javax.microedition.io.Connector. This example returns a stream to write data to
a network connection or some other type of data source accessed using the CLDC Generic

Connection Framework.
Note that the CLDC version of this class is derived from
OutputStream and not
FilterOutputStream, as it is in J2SE. This is because the CLDC does not have
a
FilterOutputStream class.
J2ME in a Nutshell
331

public class DataOutputStream extends OutputStream implements DataOutput {
// Public Constructors
public DataOutputStream( OutputStream out);
// Methods Implementing DataOutput
public void write( int b) throws IOException;
public void write(byte[] b, int off,
int len) throws IOException;
public final void writeBoolean(
boolean v) throws IOException;
public final void writeByte( int v) throws IOException;
public final void writeChar( int v) throws IOException;
public final void writeChars(String s) throws IOException;
public final void writeInt( int v) throws IOException;
public final void writeLong( long v) throws IOException;
public final void writeShort( int v) throws IOException;
public final void writeUTF(String str) throws IOException;
// Public Methods Overriding OutputStream
public void close() throws IOException;
public void flush() throws IOException;
// Protected Instance Fields
protected OutputStream out;

}
Returned By
javax.microedition.io.Connector.openDataOutputStream(),
javax.microedition.io.OutputConnection.openDataOutputStream()

EOFException CLDC 1.0, MIDP 1.0

java.io checked
An exception that signals that all available data on an input stream or a reader has been
consumed. This class is identical to its J2SE equivalent, apart from its inability to be
serialized.
public class EOFException extends IOException {
// Public Constructors
public EOFException();
public EOFException( String s);
}

×