author | martin |
Tue, 15 Sep 2015 21:56:04 -0700 | |
changeset 32649 | 2ee9017c7597 |
parent 9035 | 1255eb81cc2f |
permissions | -rw-r--r-- |
2 | 1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8543
diff
changeset
|
2 |
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 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() { |
|
8543
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
42 |
String srcDir = System.getProperty("test.src", "."); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
43 |
try (FileInputStream fis8859_1 = |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
44 |
new FileInputStream(new File(srcDir, "Bug6204853.properties")); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
45 |
FileInputStream fisUtf8 = |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
46 |
new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties")); |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
47 |
InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8")) |
e5ec12a932da
7021209: convert lang, math, util to use try-with-resources
smarks
parents:
5506
diff
changeset
|
48 |
{ |
2 | 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 |
||
32649
2ee9017c7597
8136583: Core libraries should use blessed modifier order
martin
parents:
9035
diff
changeset
|
82 |
public static final void main(String[] args) { |
2 | 83 |
new Bug6204853(); |
84 |
} |
|
85 |
} |