jdk/test/java/util/ResourceBundle/Bug6204853.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 9035 1255eb81cc2f
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8543
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 6204853
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary tests PropertyResourceBundle(Reader) constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.InputStreamReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.PropertyResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public final class Bug6204853 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public Bug6204853() {
8543
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    42
        String srcDir = System.getProperty("test.src", ".");
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    43
        try (FileInputStream fis8859_1 =
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    44
                 new FileInputStream(new File(srcDir, "Bug6204853.properties"));
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    45
             FileInputStream fisUtf8 =
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    46
                 new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    47
             InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
e5ec12a932da 7021209: convert lang, math, util to use try-with-resources
smarks
parents: 5506
diff changeset
    48
        {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            String[] array = createKeyValueArray(bundle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            if (!Arrays.equals(arrayUtf8, array)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        } catch (FileNotFoundException fnfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            throw new RuntimeException(fnfe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            throw new RuntimeException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private final String[] createKeyValueArray(PropertyResourceBundle b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        List<String> keyValueList = new ArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        for (String key : b.keySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            sb.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            sb.append(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            sb.append(" = ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            sb.append(b.getString(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            keyValueList.add(sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        String[] keyValueArray = keyValueList.toArray(new String[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        Arrays.sort(keyValueArray);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return keyValueArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 9035
diff changeset
    82
    public static final void main(String[] args) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        new Bug6204853();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
}