blob: e644f360bf4c62bd7f54807f5e3c9e985d9de906 [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright (c) 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23/*
24 * @test
25 * @bug 6204853
26 * @summary tests PropertyResourceBundle(Reader) constructor.
27 */
28
29import java.io.File;
30import java.io.FileInputStream;
31import java.io.FileNotFoundException;
32import java.io.InputStreamReader;
33import java.io.IOException;
34import java.util.ArrayList;
35import java.util.Arrays;
36import java.util.List;
37import java.util.PropertyResourceBundle;
38
39public final class Bug6204853 {
40
41 public Bug6204853() {
42 try {
43 String srcDir = System.getProperty("test.src", ".");
44 FileInputStream fis8859_1 =
45 new FileInputStream(new File(srcDir, "Bug6204853.properties"));
46 FileInputStream fisUtf8 =
47 new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
48 InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8");
49
50 PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
51 PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
52
53 String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
54 String[] array = createKeyValueArray(bundle);
55
56 isrUtf8.close();
57 fisUtf8.close();
58 fis8859_1.close();
59
60 if (!Arrays.equals(arrayUtf8, array)) {
61 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.");
62 }
63 } catch (FileNotFoundException fnfe) {
64 throw new RuntimeException(fnfe);
65 } catch (IOException ioe) {
66 throw new RuntimeException(ioe);
67 }
68 }
69
70 private final String[] createKeyValueArray(PropertyResourceBundle b) {
71 List<String> keyValueList = new ArrayList<String>();
72 StringBuilder sb = new StringBuilder();
73
74 for (String key : b.keySet()) {
75 sb.setLength(0);
76 sb.append(key);
77 sb.append(" = ");
78 sb.append(b.getString(key));
79 keyValueList.add(sb.toString());
80 }
81
82 String[] keyValueArray = keyValueList.toArray(new String[0]);
83 Arrays.sort(keyValueArray);
84 return keyValueArray;
85 }
86
87 public final static void main(String[] args) {
88 new Bug6204853();
89 }
90}