By default (when no XML SAX and DOM 2 present) parsing the properties stream with simple nanoXML parser
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
6 import java.io.ByteArrayInputStream;
7 import sun.util.xml.PropertiesXMLUtils;
9 import java.io.ByteArrayOutputStream;
10 import java.io.IOException;
11 import java.util.Properties;
13 /** Checks whether reading and writing via standard DOM and simplified API
14 * results in same results.
16 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
18 public class XMLReadAndWriteTest {
19 private static PropertiesXMLUtils FULL = new com.sun.xml.internal.PropertiesXMLUtilsImpl();
20 private static PropertiesXMLUtils SIMPLE = new sun.util.xml.DefaultPropertiesXMLUtils();
23 public static void main(String[] args) throws Exception {
24 XMLReadAndWriteTest test = new XMLReadAndWriteTest();
25 test.testCompareOutput();
26 test.testCompareInput();
30 public XMLReadAndWriteTest() {
33 public void testCompareOutput() throws IOException {
34 Properties p = new Properties();
35 p.setProperty("ahoj", "simple");
36 p.setProperty("kuk", "buk");
37 p.setProperty("multi", "one\ntwo\nthree\nfour");
39 ByteArrayOutputStream full = new ByteArrayOutputStream();
40 FULL.save(p, full, "my commment on beginging\nand on the second line\n", "UTF-8");
42 ByteArrayOutputStream simple = new ByteArrayOutputStream();
43 SIMPLE.save(p, simple, "my commment on beginging\nand on the second line\n", "UTF-8");
44 if (full.toString().equals(simple.toString())) {
46 System.err.println("OK: testCompareOutput");
49 "Full version differs from simplified. Full:\n" + full + "\nSimple:\n" + simple;
53 public void testCompareInput() throws IOException {
54 String text = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" +
55 " <!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>" +
57 "<comment>my commment on beginging\n" +
58 "and on the second line" +
60 "<entry key=\"ahoj\">simple</entry>\n" +
61 " <entry key=\"kuk\">buk</entry>" +
62 " <entry key='multi'>one\n" +
65 "four</entry>\n</properties>";
67 Properties p1 = new Properties();
69 ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
73 Properties p2 = new Properties();
75 ByteArrayInputStream is = new ByteArrayInputStream(text.getBytes("UTF-8"));
79 assert p1.equals(p2) : "P1: " + p1 + "\nP2: " + p2;
80 System.err.println("OK: testCompareInput");