duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 1 | /* |
ohair | bf91ea1 | 2011-04-06 22:06:11 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 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 | * |
ohair | 2283b9d | 2010-05-25 15:58:33 -0700 | [diff] [blame] | 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. |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 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() { |
smarks | 1dba359 | 2011-02-22 15:34:17 -0800 | [diff] [blame] | 42 | String srcDir = System.getProperty("test.src", "."); |
| 43 | try (FileInputStream fis8859_1 = |
| 44 | new FileInputStream(new File(srcDir, "Bug6204853.properties")); |
| 45 | FileInputStream fisUtf8 = |
| 46 | new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties")); |
| 47 | InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8")) |
| 48 | { |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 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 | |
duke | 6e45e10 | 2007-12-01 00:00:00 +0000 | [diff] [blame] | 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 | |
| 82 | public final static void main(String[] args) { |
| 83 | new Bug6204853(); |
| 84 | } |
| 85 | } |