Search in sources :

Example 1 with XMLDataStore

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());
    }
}
Also used : Path(java.nio.file.Path) BinaryXStreamDataStore(jgnash.engine.xstream.BinaryXStreamDataStore) XMLDataStore(jgnash.engine.xstream.XMLDataStore) XMLDataStore(jgnash.engine.xstream.XMLDataStore) IOException(java.io.IOException) DateTimeFormatter(java.time.format.DateTimeFormatter)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 BinaryXStreamDataStore (jgnash.engine.xstream.BinaryXStreamDataStore)1 XMLDataStore (jgnash.engine.xstream.XMLDataStore)1