* @return root node identifier
* @throws RepositoryException if the identifier can not be loaded or saved
*/
private NodeId loadRootNodeId() throws RepositoryException {
try {
FileSystemResource uuidFile = new FileSystemResource(
context.getFileSystem(), "/meta/rootUUID");
if (uuidFile.exists()) {
// Load uuid of the repository's root node. It is stored in
// text format (36 characters) for better readability.
InputStream in = uuidFile.getInputStream();
try {
return NodeId.valueOf(IOUtils.toString(in, "US-ASCII"));
} finally {
IOUtils.closeQuietly(in);
}
} else {
// Use hard-coded uuid for root node rather than generating
// a different uuid per repository instance; using a
// hard-coded uuid makes it easier to copy/move entire
// workspaces from one repository instance to another.
uuidFile.makeParentDirs();
OutputStream out = uuidFile.getOutputStream();
try {
out.write(ROOT_NODE_ID.toString().getBytes("US-ASCII"));
return ROOT_NODE_ID;
} finally {
IOUtils.closeQuietly(out);