Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/ResourceBundle/Bug6204853.java
41149 views
1
/*
2
* Copyright (c) 2007, 2011, 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
/*
24
* @test
25
* @bug 6204853
26
* @summary tests PropertyResourceBundle(Reader) constructor.
27
*/
28
29
import java.io.File;
30
import java.io.FileInputStream;
31
import java.io.FileNotFoundException;
32
import java.io.InputStreamReader;
33
import java.io.IOException;
34
import java.util.ArrayList;
35
import java.util.Arrays;
36
import java.util.List;
37
import java.util.PropertyResourceBundle;
38
39
public final class Bug6204853 {
40
41
public Bug6204853() {
42
String srcDir = System.getProperty("test.src", ".");
43
try (FileInputStream fis8859_1 =
44
new FileInputStream(new File(srcDir, "Bug6204853.properties"));
45
FileInputStream fisUtf8 =
46
new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
47
InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
48
{
49
PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
50
PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
51
52
String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
53
String[] array = createKeyValueArray(bundle);
54
55
if (!Arrays.equals(arrayUtf8, array)) {
56
throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
57
}
58
} catch (FileNotFoundException fnfe) {
59
throw new RuntimeException(fnfe);
60
} catch (IOException ioe) {
61
throw new RuntimeException(ioe);
62
}
63
}
64
65
private final String[] createKeyValueArray(PropertyResourceBundle b) {
66
List<String> keyValueList = new ArrayList<String>();
67
StringBuilder sb = new StringBuilder();
68
69
for (String key : b.keySet()) {
70
sb.setLength(0);
71
sb.append(key);
72
sb.append(" = ");
73
sb.append(b.getString(key));
74
keyValueList.add(sb.toString());
75
}
76
77
String[] keyValueArray = keyValueList.toArray(new String[0]);
78
Arrays.sort(keyValueArray);
79
return keyValueArray;
80
}
81
82
public static final void main(String[] args) {
83
new Bug6204853();
84
}
85
}
86
87