test/java/util/ResourceBundle/Bug6204853.java

Print this page
rev 3509 : 7021209: convert lang, math, util to use try-with-resources
Reviewed-by: XXX


  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() {
  42         try {
  43             String srcDir = System.getProperty("test.src", ".");
  44             FileInputStream  fis8859_1 =
  45                 new FileInputStream(new File(srcDir, "Bug6204853.properties"));
  46             FileInputStream fisUtf8 =
  47                 new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
  48             InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8");
  49 
  50             PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
  51             PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
  52 
  53             String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
  54             String[] array = createKeyValueArray(bundle);
  55 
  56             isrUtf8.close();
  57             fisUtf8.close();
  58             fis8859_1.close();
  59 
  60             if (!Arrays.equals(arrayUtf8, array)) {
  61                 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.");
  62             }
  63         } catch (FileNotFoundException fnfe) {
  64             throw new RuntimeException(fnfe);
  65         } catch (IOException ioe) {
  66             throw new RuntimeException(ioe);
  67         }
  68     }
  69 
  70     private final String[] createKeyValueArray(PropertyResourceBundle b) {
  71         List<String> keyValueList = new ArrayList<String>();
  72         StringBuilder sb = new StringBuilder();
  73 
  74         for (String key : b.keySet()) {
  75             sb.setLength(0);
  76             sb.append(key);
  77             sb.append(" = ");
  78             sb.append(b.getString(key));
  79             keyValueList.add(sb.toString());


  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() {

  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         {
  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 




  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());