0N/A/*
3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/*
0N/A * @test
0N/A * @bug 6204853
0N/A * @summary tests PropertyResourceBundle(Reader) constructor.
0N/A */
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.FileInputStream;
0N/Aimport java.io.FileNotFoundException;
0N/Aimport java.io.InputStreamReader;
0N/Aimport java.io.IOException;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Arrays;
0N/Aimport java.util.List;
0N/Aimport java.util.PropertyResourceBundle;
0N/A
0N/Apublic final class Bug6204853 {
0N/A
0N/A public Bug6204853() {
3646N/A String srcDir = System.getProperty("test.src", ".");
3646N/A try (FileInputStream fis8859_1 =
3646N/A new FileInputStream(new File(srcDir, "Bug6204853.properties"));
3646N/A FileInputStream fisUtf8 =
3646N/A new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
3646N/A InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
3646N/A {
0N/A PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
0N/A PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
0N/A
0N/A String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
0N/A String[] array = createKeyValueArray(bundle);
0N/A
0N/A if (!Arrays.equals(arrayUtf8, array)) {
0N/A 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.");
0N/A }
0N/A } catch (FileNotFoundException fnfe) {
0N/A throw new RuntimeException(fnfe);
0N/A } catch (IOException ioe) {
0N/A throw new RuntimeException(ioe);
0N/A }
0N/A }
0N/A
0N/A private final String[] createKeyValueArray(PropertyResourceBundle b) {
0N/A List<String> keyValueList = new ArrayList<String>();
0N/A StringBuilder sb = new StringBuilder();
0N/A
0N/A for (String key : b.keySet()) {
0N/A sb.setLength(0);
0N/A sb.append(key);
0N/A sb.append(" = ");
0N/A sb.append(b.getString(key));
0N/A keyValueList.add(sb.toString());
0N/A }
0N/A
0N/A String[] keyValueArray = keyValueList.toArray(new String[0]);
0N/A Arrays.sort(keyValueArray);
0N/A return keyValueArray;
0N/A }
0N/A
0N/A public final static void main(String[] args) {
0N/A new Bug6204853();
0N/A }
0N/A}