ccs.cdb
Class CDBFilesystem

java.lang.Object
  extended by ccs.cdb.CDBFilesystem

public class CDBFilesystem
extends java.lang.Object

Commonly-useful utility methods for manipulating CDB filesystems (sets of CDBFile s indexed by CDBDirectorys). It's OK to read CDBFiles directly. However, it is strongly recommended that you use this to write to a CDB filesystem; don't try to do it yourself, it's harder than it looks.


Method Summary
static void delete(CDBeeTree cdb, CDBFile cf)
          Delete the specified CDBFile and update its parent folder.
static void delTree(CDBeeTree cdb, CDBDirectory folder, BeeTreeObserver obs)
          Delete the entire tree rooted at the specified folder, including the folder itself.
static CDBFileMeta getFileMeta(CDBeeTree cdb, java.lang.String path)
          Return the metadata according to a given file.
static boolean hasFilesystem(CDBeeTree cdb, boolean needMetadata)
          Whether this CDB contains a filesystem.
static void insert(CDBeeTree cdb, CDBFile cf)
          Insert a CDBFile, updating and / or creating intervening folders.
static void insert(CDBeeTree cdb, CDBFile cf, CDBDirectory parent)
          Optimised version of insert for situations where the destination CDBDirectory is already available.
static CDBDirectory mkdirs(CDBeeTree cdb, java.lang.String path)
          Return the CDBDirectory corresponding to the specified path, creating it and / or any parent folders as required.
static void rename(CDBeeTree cdb, CDBFile cf, java.lang.String newName)
          Rename the specified CDBFile and update its parent folder.
static void renameFolder(CDBeeTree cdb, CDBDirectory folder, java.lang.String newName)
          Renames a folder.
static void update(CDBeeTree cdb, CDBFile cf)
          Update an existing CDBFile.
static void verifyFilesystem(CDBeeTree cdb)
          Verify that a valid CDB filesystem exists, and create it if not.
static void verifyLegacyFilesystem(CDBeeTree cdb)
          as verifyFilesystem, except that the result is compatible with Checkpoint 5 installations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

verifyFilesystem

public static void verifyFilesystem(CDBeeTree cdb)
                             throws java.io.IOException
Verify that a valid CDB filesystem exists, and create it if not.

Parameters:
cdb - The CDB to work on.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

verifyLegacyFilesystem

public static void verifyLegacyFilesystem(CDBeeTree cdb)
                                   throws java.io.IOException
as verifyFilesystem, except that the result is compatible with Checkpoint 5 installations. Subsequent calls to methods on this class will work either way. This may be deprecated in future.

Throws:
java.io.IOException

hasFilesystem

public static boolean hasFilesystem(CDBeeTree cdb,
                                    boolean needMetadata)
                             throws java.io.IOException
Whether this CDB contains a filesystem.

Parameters:
cdb -
needMetadata - Whether the filesystem must have metadata support (new in Checkpoint 6) in order to qualify.
Throws:
java.io.IOException

insert

public static void insert(CDBeeTree cdb,
                          CDBFile cf)
                   throws java.io.IOException
Insert a CDBFile, updating and / or creating intervening folders.

Parameters:
cdb - The CDB to insert into.
cf - The CDBFile to insert. Must be fully initialised and ready to insert.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

insert

public static void insert(CDBeeTree cdb,
                          CDBFile cf,
                          CDBDirectory parent)
                   throws java.io.IOException
Optimised version of insert for situations where the destination CDBDirectory is already available. Mostly for CPC. If in doubt, use the two-parameter version.

Parameters:
cdb - The CDB to insert into.
cf - The CDBFile to insert. Must be fully initialised and ready to insert.
parent - The CDBDirectory to add this file to. This must be the correct directory, or Bad Things will happen.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

update

public static void update(CDBeeTree cdb,
                          CDBFile cf)
                   throws java.io.IOException
Update an existing CDBFile.

Parameters:
cdb - The CDB to update into.
cf - The CDBFile to update. Must be fully initialised and ready to insert.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

getFileMeta

public static CDBFileMeta getFileMeta(CDBeeTree cdb,
                                      java.lang.String path)
                               throws java.io.IOException
Return the metadata according to a given file.

Parameters:
cdb - The CDB to look in.
path - The path to the file in question.
Returns:
The file's metadata, if it exists, else null. Note: This facility is new. Older CDBs may not contain metadata and apps MUST be prepared to handle this without throwing.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

mkdirs

public static CDBDirectory mkdirs(CDBeeTree cdb,
                                  java.lang.String path)
                           throws java.io.IOException
Return the CDBDirectory corresponding to the specified path, creating it and / or any parent folders as required.

Parameters:
cdb - The CDB to insert into.
path - The path to insert.
Returns:
the CDBDirectory corresponding to the specified path.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

delete

public static void delete(CDBeeTree cdb,
                          CDBFile cf)
                   throws java.io.IOException
Delete the specified CDBFile and update its parent folder.

Parameters:
cdb - The CDB to work on.
cf - The CDBFile to delete. This needs a correct internal path but need not have been initialised any further.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

rename

public static void rename(CDBeeTree cdb,
                          CDBFile cf,
                          java.lang.String newName)
                   throws java.io.IOException
Rename the specified CDBFile and update its parent folder.

Parameters:
cdb - The CDB to work on.
cf - The CDBFile to rename. This needs a correct internal path but need not have been initialised any further.
newName - the new name (terminal path element) of the file.
Throws:
java.io.IOException - If thrown by the CDBeeTree.

delTree

public static void delTree(CDBeeTree cdb,
                           CDBDirectory folder,
                           BeeTreeObserver obs)
                    throws java.io.IOException
Delete the entire tree rooted at the specified folder, including the folder itself.

Parameters:
cdb - The CDB to work on.
folder - The folder to delete. This needs a correct path but need not have been initialised any further. If root, all files and folders will be deleted but the now-empty root folder will be replaced afterwards.
obs - If not null, this will be notified as the deletion progresses. (Deleting CDBFiles involves wiping them, and takes time).
Throws:
java.io.IOException - If thrown by the CDBeeTree.

renameFolder

public static void renameFolder(CDBeeTree cdb,
                                CDBDirectory folder,
                                java.lang.String newName)
                         throws java.io.IOException
Renames a folder. This involves renaming all the files and subfolders underneath it. This can take some time.

Parameters:
cdb - The CDB to work on.
folder - The folder to rename. Cannot be the root folder.
newName - The new name (terminal) element of the path.
Throws:
java.io.IOException - If thrown by the CDBeeTree.