Skip to content

Commit b3078cc

Browse files
committed
ConfigIO now also uses the pretty xml printer, reformatted default_config
1 parent 26c6b0c commit b3078cc

File tree

2 files changed

+263
-243
lines changed

2 files changed

+263
-243
lines changed

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/ConfigIO.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,38 @@
88
*/
99
package de.rub.nds.tlsattacker.core.config;
1010

11+
import de.rub.nds.modifiablevariable.util.XMLPrettyPrinter;
1112
import de.rub.nds.tlsattacker.core.config.filter.ConfigDisplayFilter;
1213
import java.io.*;
14+
import java.util.logging.Level;
15+
import java.util.logging.Logger;
1316
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;
1422

1523
public class ConfigIO {
24+
1625
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+
}
1831
}
1932

2033
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+
}
2243
}
2344

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

0 commit comments

Comments
 (0)