Java Reference
In-Depth Information
Although the differences between the J2SE and CLDC classes appear large, they can be
easily grouped into three categories:
1.
Because CLDC/MIDP by itself has no concept of a local file system, all the classes
having to do with files have been pruned from the java.io package. This includes File ,
FileInputStream , FileOutputStream , the corresponding Reader and Writer classes,
RandomAccessFile , and various supporting classes. If you need to store data persistently
on a device, you'll need to use the javax.microedition.rms package API, described in
Chapter 8. Some devices may expose a file system through an optional API: the File
Connection Optional Package ( JSR 75). In addition, devices that act as a Personal Infor-
mation Manager (PIM) can also provide access to its persistent data through the
optional PIM APIs (also part of JSR 75). These optional APIs are described in Chapter 9.
Object serialization is not supported in CLDC. This means that the Serializable
interface and various object stream classes are not present.
2.
3.
Finally, J2SE includes a handful of utility stream classes—things you might want someday
but shouldn't include on a device with a small amount of memory. These classes include
piped streams, pushback streams, sequence streams, line numbering streams, and a
few other gems like StreamTokenizer . If you really need one of these in your MIDlet, you
may be able to package it with your application. 1 Bear in mind that there are licensing
restrictions and technical problems with using classes directly from J2SE; be sure you
understand the legal implications before you start copying files.
Character Encodings
MIDP includes the Reader and Writer character streams for working with Unicode characters.
InputStreamReader and OutputStreamWriter handle the conversion between byte streams and
character streams, just as in J2SE. An encoding determines how translation occurs between
byte streams and character streams. A default encoding is used if you don't specify one. You can
pass an encoding name to the constructors for InputStreamReader and OutputStreamWriter , if
you wish. So far, this is all the same as in J2SE. In MIDP, though, you will likely find many fewer
available encodings than in J2SE.
The default encoding for a MIDP implementation can be obtained by calling
System.getProperty("microedition.encoding") —for example, ISO8859-1.
Resource Files
As described in Chapter 8, you can retrieve resource files from your MIDlet suite's JAR file.
Use the getResourceAsStream() method in Class ; it returns an InputStream that you can use
as you please.
1.
A better idea would be to redesign your application so that complicated stream processing isn't
necessary on the device. In general, you should make your server do as much work as possible and
your MIDlet do as little as possible.
Search WWH ::




Custom Search