use of jgnash.engine.xstream.XMLDataStore in project jgnash by ccavanaugh.
the class EngineFactory method exportCompressedXML.
public static void exportCompressedXML(final String fileName, final Collection<StoredObject> objects) {
final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd-HHmm");
final DataStore xmlDataStore = new XMLDataStore();
Path xmlFile = Paths.get(FileUtils.stripFileExtension(fileName) + "-" + dateTimeFormatter.format(LocalDateTime.now()) + xmlDataStore.getFileExt());
// push the intermediary file to the temporary directory
xmlFile = Paths.get(System.getProperty("java.io.tmpdir") + xmlFile.getFileSystem().getSeparator() + xmlFile.getFileName().toString());
xmlDataStore.saveAs(xmlFile, objects);
Path zipFile = Paths.get(FileUtils.stripFileExtension(fileName) + "-" + dateTimeFormatter.format(LocalDateTime.now()) + ".zip");
FileUtils.compressFile(xmlFile, zipFile);
try {
Files.delete(xmlFile);
} catch (final IOException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
logger.log(Level.WARNING, "Was not able to delete the temporary file: {0}", xmlFile.toString());
}
}
Aggregations