Java Reference
In-Depth Information
Note that only a MIDlet belonging to the suite that created the record store can change its
authorization mode and writable flag.
How do you access a shared record store? One final openRecordStore() method provides
the answer:
public static RecordStore openRecordStore(String recordStoreName,
String vendorName, String suiteName)
throws RecordStoreException, RecordStoreNotFoundException
To access a shared record store, you need to know its name, the name of the MIDlet
suite that created it, and the name of the MIDlet suite's vendor. These names must be the
MIDlet-Name and MIDlet-Vendor attributes in the MIDlet suite JAR manifest or the application
descriptor.
Record Store Size
Record stores consist of records; each record is simply an array of bytes. On space-constrained
devices, you'll probably want to keep a close eye on the size of your record stores. To find out
the number of bytes used by a record store, call the following method on a RecordStore instance:
public int getSize()
You can find out how much more space is available by calling the following method:
public int getSizeAvailable()
Note that this method returns the total space available in the record store, which is not the
same as the amount of record data that is available. That is, there is some overhead associated
with each record in the record store; the getSizeAvailable() method returns the amount of
space available for both record data and overhead.
Version and Timestamp
Record stores maintain both a version number and a timestamp. The version number is updated
every time the record store is modified. It is represented by an integer and can be retrieved by
calling getVersion() .
The record store also remembers the last time it was modified. This moment in time is
represented by a long , which can be retrieved with getLastModified() . The long represents the
number of milliseconds since midnight on January 1, 1970. You may recall (from Chapter 4)
that this is the same way that Date uses a long to represent a moment in time. If you need to
examine the timestamp of a record store, you can create a Date from the long timestamp. Then
you could use a Calendar to translate from a Date to calendar fields like month, day, hour, and
minute.
Working with Records
A record is simply an array of bytes. Each record in a RecordStore has an integer identification
number. Figure 8-2 shows a diagram of a RecordStore with four records.
Search WWH ::




Custom Search