public CatalogLeafNode createNode(String filename, CatalogNodeId parentId, CatalogNodeId nodeId,
int nodeType) throws IOException {
CatalogLeafNode node;
HfsUnicodeString name = new HfsUnicodeString(filename);
// find parent leaf record.
LeafRecord record = this.getRecord(parentId, name);
if (record == null) {
NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, 2);
node = new CatalogLeafNode(nd, 8192);
// Normal record
CatalogKey key = new CatalogKey(parentId, name);
if (nodeType == CatalogFolder.RECORD_TYPE_FOLDER) {
CatalogFolder folder = new CatalogFolder(0, parentId);
key = new CatalogKey(parentId, name);
record = new LeafRecord(key, folder.getBytes());
node.addNodeRecord(record);
} else {
// Catalog file
}
// Thread record
key = new CatalogKey(parentId, name);
int threadType;
if (nodeType == CatalogFolder.RECORD_TYPE_FOLDER) {
threadType = CatalogFolder.RECORD_TYPE_FOLDER_THREAD;
} else {
threadType = CatalogFile.RECORD_TYPE_FILE_THREAD;
}
CatalogThread thread = new CatalogThread(threadType, nodeId, name);
record = new LeafRecord(key, thread.getBytes());
node.addNodeRecord(record);
} else {
throw new IOException("Leaf record for parent (" + parentId.getId() + ") doesn't exist.");
}