* @param fs
* @return
* @throws RepositoryException
*/
protected NodeId loadRootNodeId(FileSystem fs) throws RepositoryException {
FileSystemResource uuidFile = new FileSystemResource(fs, "rootUUID");
try {
if (uuidFile.exists()) {
try {
// load uuid of the repository's root node
InputStream in = uuidFile.getInputStream();
/*
// uuid is stored in binary format (16 bytes)
byte[] bytes = new byte[16];
try {
in.read(bytes);
} finally {
try {
in.close();
} catch (IOException ioe) {
// ignore
}
}
rootNodeUUID = new UUID(bytes).toString(); // uuid is stored in binary format (16 bytes)
*/
// uuid is stored in text format (36 characters) for better readability
char[] chars = new char[36];
InputStreamReader reader = new InputStreamReader(in);
try {
reader.read(chars);
} finally {
IOUtils.closeQuietly(reader);
}
return NodeId.valueOf(new String(chars));
} catch (Exception e) {
String msg = "failed to load persisted repository state";
log.debug(msg);
throw new RepositoryException(msg, e);
}
} else {
// create new uuid
/*
UUID rootUUID = UUID.randomUUID(); // version 4 uuid
rootNodeUUID = rootUUID.toString();
*/
/**
* 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.
*/
try {
// persist uuid of the repository's root node
OutputStream out = uuidFile.getOutputStream();
/*
// store uuid in binary format
try {
out.write(rootUUID.getBytes());
} finally {