Skip to content

Commit

Permalink
ConfigIO now also uses the pretty xml printer, reformatted default_co…
Browse files Browse the repository at this point in the history
…nfig
  • Loading branch information
ic0ns committed Jun 1, 2018
1 parent 26c6b0c commit b3078cc
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 243 deletions.
Expand Up @@ -8,17 +8,38 @@
*/
package de.rub.nds.tlsattacker.core.config;

import de.rub.nds.modifiablevariable.util.XMLPrettyPrinter;
import de.rub.nds.tlsattacker.core.config.filter.ConfigDisplayFilter;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXB;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactoryConfigurationException;
import org.xml.sax.SAXException;

public class ConfigIO {

public static void write(Config config, File f) {
JAXB.marshal(config, f);
try {
write(config, new FileOutputStream(f));
} catch (FileNotFoundException ex) {
throw new RuntimeException(ex);
}
}

public static void write(Config config, OutputStream os) {
JAXB.marshal(config, os);
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();

JAXB.marshal(config, tempStream);
try {
os.write(XMLPrettyPrinter.prettyPrintXML(new String(tempStream.toByteArray())).getBytes());
} catch (IOException | TransformerException | XPathExpressionException | XPathFactoryConfigurationException
| ParserConfigurationException | SAXException ex) {
throw new RuntimeException("Could not format XML");
}
}

public static void write(Config config, File f, ConfigDisplayFilter filter) {
Expand Down

0 comments on commit b3078cc

Please sign in to comment.