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