writer.close();
}
}
}
} catch (IOException e) {
throw new SynchronizationException(
MessageCode.ERROR_IN_CREATING_TEMP_FILE_FOR_DUMP,
e);
} catch (XMLStreamException e) {
throw new SynchronizationException(
MessageCode.ERROR_IN_CREATING_XML_STREAM_WRITER, e);
}
// do the restoring
try {
Reader reader = null;
try {
reader = new FileReader(tempFile);
registry.restore(checkInPath, reader);
} finally {
if (reader != null) {
reader.close();
}
}
} catch (IOException e) {
throw new SynchronizationException(
MessageCode.ERROR_IN_READING_TEMP_FILE_OF_DUMP, e);
} catch (RegistryException e) {
throw new SynchronizationException(MessageCode.ERROR_IN_RESTORING, e,
new String[]{"path: " + checkInPath,
"registry url: " + registryUrl,
"username: " + username});
}
} finally {
if (tempFile != null) {
// Our intention here is to delete the temporary file. We are not bothered whether
// this operation fails.
deleteTempFileFailed = !tempFile.delete();
}
}
if (deleteTempFileFailed) {
throw new SynchronizationException(MessageCode.ERROR_IN_CLEANING_UP,
new String[]{"file path: " + tempFile.getAbsolutePath()});
}
if (cleanRegistry && registryUrl == null) {
Utils.cleanEmbeddedRegistry();
}
// clean all the dangling meta files.
if (filesToClean != null && filesToClean.size() > 0) {
for (String filePath : filesToClean) {
if (!Utils.deleteFile(new File(filePath))) {
throw new SynchronizationException(MessageCode.ERROR_IN_CLEANING_UP,
new String[]{"file path: " + filePath});
}
}
}