|
8 | 8 | */ |
9 | 9 | package de.rub.nds.tlsattacker.core.config; |
10 | 10 |
|
| 11 | +import de.rub.nds.modifiablevariable.util.XMLPrettyPrinter; |
11 | 12 | import de.rub.nds.tlsattacker.core.config.filter.ConfigDisplayFilter; |
12 | 13 | import java.io.*; |
| 14 | +import java.util.logging.Level; |
| 15 | +import java.util.logging.Logger; |
13 | 16 | import javax.xml.bind.JAXB; |
| 17 | +import javax.xml.parsers.ParserConfigurationException; |
| 18 | +import javax.xml.transform.TransformerException; |
| 19 | +import javax.xml.xpath.XPathExpressionException; |
| 20 | +import javax.xml.xpath.XPathFactoryConfigurationException; |
| 21 | +import org.xml.sax.SAXException; |
14 | 22 |
|
15 | 23 | public class ConfigIO { |
| 24 | + |
16 | 25 | public static void write(Config config, File f) { |
17 | | - JAXB.marshal(config, f); |
| 26 | + try { |
| 27 | + write(config, new FileOutputStream(f)); |
| 28 | + } catch (FileNotFoundException ex) { |
| 29 | + throw new RuntimeException(ex); |
| 30 | + } |
18 | 31 | } |
19 | 32 |
|
20 | 33 | public static void write(Config config, OutputStream os) { |
21 | | - JAXB.marshal(config, os); |
| 34 | + ByteArrayOutputStream tempStream = new ByteArrayOutputStream(); |
| 35 | + |
| 36 | + JAXB.marshal(config, tempStream); |
| 37 | + try { |
| 38 | + os.write(XMLPrettyPrinter.prettyPrintXML(new String(tempStream.toByteArray())).getBytes()); |
| 39 | + } catch (IOException | TransformerException | XPathExpressionException | XPathFactoryConfigurationException |
| 40 | + | ParserConfigurationException | SAXException ex) { |
| 41 | + throw new RuntimeException("Could not format XML"); |
| 42 | + } |
22 | 43 | } |
23 | 44 |
|
24 | 45 | public static void write(Config config, File f, ConfigDisplayFilter filter) { |
|
0 commit comments