Path: blob/master/test/jdk/java/util/ResourceBundle/Bug6204853.java
41149 views
/*1* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 620485325* @summary tests PropertyResourceBundle(Reader) constructor.26*/2728import java.io.File;29import java.io.FileInputStream;30import java.io.FileNotFoundException;31import java.io.InputStreamReader;32import java.io.IOException;33import java.util.ArrayList;34import java.util.Arrays;35import java.util.List;36import java.util.PropertyResourceBundle;3738public final class Bug6204853 {3940public Bug6204853() {41String srcDir = System.getProperty("test.src", ".");42try (FileInputStream fis8859_1 =43new FileInputStream(new File(srcDir, "Bug6204853.properties"));44FileInputStream fisUtf8 =45new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));46InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))47{48PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);49PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);5051String[] arrayUtf8 = createKeyValueArray(bundleUtf8);52String[] array = createKeyValueArray(bundle);5354if (!Arrays.equals(arrayUtf8, array)) {55throw 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.");56}57} catch (FileNotFoundException fnfe) {58throw new RuntimeException(fnfe);59} catch (IOException ioe) {60throw new RuntimeException(ioe);61}62}6364private final String[] createKeyValueArray(PropertyResourceBundle b) {65List<String> keyValueList = new ArrayList<String>();66StringBuilder sb = new StringBuilder();6768for (String key : b.keySet()) {69sb.setLength(0);70sb.append(key);71sb.append(" = ");72sb.append(b.getString(key));73keyValueList.add(sb.toString());74}7576String[] keyValueArray = keyValueList.toArray(new String[0]);77Arrays.sort(keyValueArray);78return keyValueArray;79}8081public static final void main(String[] args) {82new Bug6204853();83}84}858687