Methods Summary |
---|
public static boolean | addFileSystemListener(FileSystemListener listener)
if (listener == null) {
throw new NullPointerException();
}
checkReadPermission();
// Create and register file system events listener in MIDP event system
// (if there is no registered yet)
if (!isListenerRegistered) {
// Create root cache object and fill it's internal cache with
// currently mounted roots.
// Cache is used to determine which roots were mounted/unmounted
// if EventTypes.FC_DISKS_CHANGED_EVENT event arrives.
RootCache.initialize();
FileSystemEventHandler.setListener(new FileSystemEventHandler());
isListenerRegistered = true;
}
fileSystemListeners.addElement(listener);
return true;
|
static synchronized void | addRoot(java.lang.String root)Adds a root to the cache.
RootCache cache = RootCache.getInstance();
if (!cache.isRoot(root)) {
cache.addRoot(root);
notifyListeners(FileSystemListener.ROOT_ADDED, root);
}
|
private static void | checkReadPermission()Checks the read permission.
MIDletSuite suite = Scheduler.getScheduler().getMIDletSuite();
try {
suite.checkForPermission
(Permissions.FILE_CONNECTION_READ, null);
} catch (InterruptedException ie) {
throw new SecurityException(
"Interrupted while trying to ask the user permission");
}
|
static java.util.Enumeration | listCachedRoots()Gets a list of cached file system roots without checking permissions.
/** List of file system roots. */
return new Enumeration() {
/** Array of root pathnames. */
String[] roots = RootCache.getInstance().getRoots();
/** Current index int the enumeration. */
int index = 0;
/**
* Checks if more data available.
* @return <code>true</code> if more
* elements available.
*/
public boolean hasMoreElements() {
return index < roots.length;
}
/**
* Gets the next element.
* @return next object in list
*/
public Object nextElement() {
try {
return roots[index++];
} catch (ArrayIndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
}
};
|
public static java.util.Enumeration | listRoots()
checkReadPermission();
// retrieve up-to-date list of mounted roots
return Protocol.listRoots().elements();
|
private static void | notifyListeners(int event, java.lang.String root)Notify registered listeners about mount/unmount event.
for (int i = 0; i < fileSystemListeners.size(); i++) {
try {
((FileSystemListener)fileSystemListeners.elementAt(i)).
rootChanged(event, root);
} catch (Throwable t) {
t.printStackTrace();
}
}
|
public static boolean | removeFileSystemListener(FileSystemListener listener)
if (listener == null) {
throw new NullPointerException();
}
return fileSystemListeners.removeElement(listener);
|
static synchronized void | removeRoot(java.lang.String root)Removes a root from the cache.
RootCache cache = RootCache.getInstance();
if (cache.isRoot(root)) {
cache.removeRoot(root);
notifyListeners(FileSystemListener.ROOT_REMOVED, root);
}
|