From d409b8a8f3984adc3f87285d0acc77bdd086ce53 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 23 Sep 2013 17:41:38 +0200 Subject: [PATCH] Improve export methods. --- src/fr/devinsy/sikevadb/XMLSikevaDB.java | 41 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/fr/devinsy/sikevadb/XMLSikevaDB.java b/src/fr/devinsy/sikevadb/XMLSikevaDB.java index 9dfe957..dac4227 100644 --- a/src/fr/devinsy/sikevadb/XMLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/XMLSikevaDB.java @@ -15,6 +15,7 @@ import fr.devinsy.util.xml.XMLReader; import fr.devinsy.util.xml.XMLTag; import fr.devinsy.util.xml.XMLTag.TagType; import fr.devinsy.util.xml.XMLWriter; +import fr.devinsy.util.xml.XMLZipWriter; /** * This class represents a AccountManager File reader and writer. @@ -24,6 +25,23 @@ import fr.devinsy.util.xml.XMLWriter; public class XMLSikevaDB { static private final Logger logger = LoggerFactory.getLogger(XMLSikevaDB.class); + /** + * Saves a net in a file. + * + * @param file + * Target. + * @param source + * Source. + * + */ + public static void export(final OutputStream out, final SikevaDB source) throws Exception { + // + String fileName = "sikevadb-" + DateTime.now().toString("yyyy-MM-dd-HH'h'mm'mn'ss's'") + ".xml.zip"; + + // + export(out, source, fileName); + } + /** * Saves a net in a file. * @@ -39,17 +57,26 @@ public class XMLSikevaDB { throw new NullPointerException("out is null."); } else if (source == null) { throw new NullPointerException("source is null."); + } else if (fileName == null) { + export(out, source, fileName); } else { // - XMLWriter target = new XMLWriter(out);// new XMLZipWriter(out, - // fileName, - // "Generated by SikevaDB."); + XMLZipWriter target = null; + try { + // + target = new XMLZipWriter(out, fileName, "Generated by SikevaDB."); - // - target.writeXMLHeader(); + // + target.writeXMLHeader(); - // - write(target, source); + // + write(target, source); + + } finally { + if (target != null) { + target.close(); + } + } } }