FileDocCategorySizeDatePackage
RootCache.javaAPI DocphoneME MR2 API (J2ME)3602Wed May 02 18:00:28 BST 2007com.sun.midp.io.j2me.file

RootCache

public class RootCache extends Object
Caches file system roots.

Fields Summary
private String[]
roots
Current root paths.
private static RootCache
instance
Reference to the root cache.
Constructors Summary
private RootCache()
Constructs the root cache instance.



          
      
        // retrieve up-to-date mounted roots; array can not be null
        Vector v = Protocol.listRoots();
        roots = new String[v.size()];
        v.copyInto(roots);
    
Methods Summary
public synchronized voidaddRoot(java.lang.String root)
Adds a root to the cache.

param
root path to add to roots

        String[] a = new String[roots.length + 1];
        System.arraycopy(roots, 0, a, 0, roots.length);
        a[roots.length] = root;
        roots = a;
    
public static synchronized com.sun.midp.io.j2me.file.RootCachegetInstance()
Gets reference to the root cache. If an instance does not exist then creates it, otherwise returns existing one.

return
root cache reference

        if (instance == null) {
            instance = new RootCache();
        }
        return instance;
    
public synchronized java.lang.String[]getRoots()
Gets the list of cached roots.

return
array of cached file system roots

        return roots;
    
public static synchronized voidinitialize()
Creates instance of root cache and fills it with current root paths.

        getInstance();
    
public synchronized booleanisRoot(java.lang.String root)
Checks if path is a root path.

param
root path to be checked
return
true if path is a root

        for (int i = 0; i < roots.length; i++) {
            if (root.equals(roots[i])) {
                return true;
            }
        }
        return false;
    
public synchronized voidremoveRoot(java.lang.String root)
Removes a root from the cache.

param
root path to be removed

        int index = -1;
        for (int i = 0; i < roots.length && index == -1; i++) {
            if (root.equals(roots[i])) {
                index = i;
            }
        }
        if (index != -1) {
            String[] a = new String[roots.length - 1];
            System.arraycopy(roots, 0, a, 0, index);
            System.arraycopy(roots, index + 1, a, index, a.length - index);
            roots = a;
        }