Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Properties/LoadAndStoreXMLWithDefaults.java
41152 views
1
/*
2
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
import java.io.ByteArrayInputStream;
24
import java.io.ByteArrayOutputStream;
25
import java.io.IOException;
26
import java.util.Properties;
27
28
29
/**
30
* @test
31
* @bug 8016344
32
* @summary checks that Properties.storeToXML only stores properties locally
33
* defined on the Properties object, excluding those that are inherited.
34
* @author danielfuchs
35
*/
36
public class LoadAndStoreXMLWithDefaults {
37
38
static String writeToXML(Properties props) throws IOException {
39
ByteArrayOutputStream baos = new ByteArrayOutputStream();
40
props.storeToXML(baos, "Test 8016344");
41
return baos.toString();
42
}
43
44
static Properties loadFromXML(String xml, Properties defaults) throws IOException {
45
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes("UTF-8"));
46
Properties props = new Properties(defaults);
47
props.loadFromXML(bais);
48
return props;
49
}
50
51
static enum Objects { OBJ1, OBJ2, OBJ3 };
52
53
public static void main(String[] args) throws IOException {
54
Properties p1 = new Properties();
55
p1.setProperty("p1.prop", "prop1-p1");
56
p1.setProperty("p1.and.p2.prop", "prop2-p1");
57
p1.setProperty("p1.and.p2.and.p3.prop", "prop3-p1");
58
Properties p2 = new Properties(p1);
59
p2.setProperty("p2.prop", "prop4-p2");
60
p2.setProperty("p1.and.p2.prop", "prop5-p2");
61
p2.setProperty("p1.and.p2.and.p3.prop", "prop6-p2");
62
p2.setProperty("p2.and.p3.prop", "prop7-p2");
63
Properties p3 = new Properties(p2);
64
p3.setProperty("p3.prop", "prop8-p3");
65
p3.setProperty("p1.and.p2.and.p3.prop", "prop9-p3");
66
p3.setProperty("p2.and.p3.prop", "prop10-p3");
67
68
Properties P1 = loadFromXML(writeToXML(p1), null);
69
Properties P2 = loadFromXML(writeToXML(p2), P1);
70
Properties P3 = loadFromXML(writeToXML(p3), P2);
71
72
testResults(p1, P1, p2, P2, p3, P3);
73
}
74
75
public static void testResults(Properties... pps) {
76
for (int i=0 ; i < pps.length ; i += 2) {
77
if (!pps[i].equals(pps[i+1])) {
78
System.err.println("P" + (i/2+1)
79
+ " Reloaded properties differ from original");
80
System.err.println("\toriginal: " + pps[i]);
81
System.err.println("\treloaded: " + pps[i+1]);
82
throw new RuntimeException("P" + (i/2+1)
83
+ " Reloaded properties differ from original");
84
}
85
if (!pps[i].keySet().equals(pps[i+1].keySet())) {
86
System.err.println("P" + (i/2+1)
87
+ " Reloaded property names differ from original");
88
System.err.println("\toriginal: " + pps[i].keySet());
89
System.err.println("\treloaded: " + pps[i+1].keySet());
90
throw new RuntimeException("P" + (i/2+1)
91
+ " Reloaded property names differ from original");
92
}
93
if (!pps[i].stringPropertyNames().equals(pps[i+1].stringPropertyNames())) {
94
System.err.println("P" + (i/2+1)
95
+ " Reloaded string property names differ from original");
96
System.err.println("\toriginal: " + pps[i].stringPropertyNames());
97
System.err.println("\treloaded: " + pps[i+1].stringPropertyNames());
98
throw new RuntimeException("P" + (i/2+1)
99
+ " Reloaded string property names differ from original");
100
}
101
}
102
}
103
104
}
105
106