Java Reference
In-Depth Information
Discovering the Available File Systems
Another frequent use for the centralized FileSystemRegistry is for listing all the available file
systems. Recall that each file system has a unique corresponding root name. The static method
to call to discover all the root names is the following:
public static Enumeration listRoots() throws SecurityException
The returned value is an Enumeration of strings. Each element in the Enumeration is an
available file system root. Typical code to iterate through the roots may be as follows:
Enumeration roots = FileSystemRegistry.listRoots();
String currentRoot = null;
while (roots.hasMoreElements()) {
currentRoot = (String) roots.nextElement();
... do something with the discovered root...
}
FileConnection and Security
JSR 75 requires that all implementations of the File Connection Optional Package to isolate the
MIDP RMS databases from the file system exposed through FileConnection . This means that
there will be no way for you to accidentally overwrite any data that is accessed through
RecordStore .
The specification recommends strongly that general file system access only be granted to
designated public areas. It also recommends that file systems be protected based on users,
applications, and system. However, enforcement is left up to the individual device implemen-
tation. Most CLDC devices are single user, and access restrictions based on user may not
make sense.
When you make a call to Connector.open() , the MIDP protection domain-based security
policy will kick in. For untrusted MIDlet suites, a user must explicitly allow access to the
protected FileConnection API. This is identical to the behavior when untrusted MIDlet suites
access the network through GCR.
For trusted MIDlet suites, a set of permissions is used to provide specific access to the
FileConnection API. This set of permissions include the following:
javax.microedition.io.Connector.file.read
javax.microedition.io.Connector.file.write
Review Chapter 3 if you need a refresher on protection domains, permissions, or the MIDP
security model in general.
An Example
Putting some of this to work, the example in Listing 9-1 stores preferences to the file system
using the File Connection Optional Package. FileBasedPreferences is similar to the
RecordStore -based Preferences class from Chapter 8. It maintains a preferences hash table
that is persisted to the file system using the File Connection API.
Search WWH ::




Custom Search