8003846: Override mechanism for currency data should not require creating currency.properties in java.home
Reviewed-by: naoto
diff --git a/test/java/util/Currency/PropertiesTest.java b/test/java/util/Currency/PropertiesTest.java
index ab78ec0..4b84e06 100644
--- a/test/java/util/Currency/PropertiesTest.java
+++ b/test/java/util/Currency/PropertiesTest.java
@@ -27,22 +27,15 @@
import java.util.regex.*;
public class PropertiesTest {
- public static void main(String[] s) throws Exception {
- for (int i = 0; i < s.length; i ++) {
- if ("-d".equals(s[i])) {
- i++;
- if (i == s.length) {
- throw new RuntimeException("-d needs output file name");
- } else {
- dump(s[i]);
- }
- } else if ("-c".equals(s[i])) {
- if (i+2 == s.length) {
- throw new RuntimeException("-d needs two file name arguments, before and after respectively");
- } else {
- compare(s[++i], s[++i]);
- }
- }
+ public static void main(String[] args) throws Exception {
+ if (args.length == 2 && args[0].equals("-d")) {
+ dump(args[1]);
+ } else if (args.length == 4 && args[0].equals("-c")) {
+ compare(args[1], args[2], args[3]);
+ } else {
+ System.err.println("Usage: java PropertiesTest -d <dumpfile>");
+ System.err.println(" java PropertiesTest -c <beforedump> <afterdump> <propsfile>");
+ System.exit(-1);
}
}
@@ -77,15 +70,17 @@
pw.close();
}
- private static void compare(String beforeFile, String afterFile) throws Exception {
+ private static void compare(String beforeFile, String afterFile, String propsFile)
+ throws IOException
+ {
// load file contents
Properties before = new Properties();
+ try (Reader reader = new FileReader(beforeFile)) {
+ before.load(reader);
+ }
Properties after = new Properties();
- try {
- before.load(new FileReader(beforeFile));
- after.load(new FileReader(afterFile));
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
+ try (Reader reader = new FileReader(afterFile)) {
+ after.load(reader);
}
// remove the same contents from the 'after' properties
@@ -103,13 +98,9 @@
}
// now look at the currency.properties
- String propFileName = System.getProperty("java.home") + File.separator +
- "lib" + File.separator + "currency.properties";
Properties p = new Properties();
- try {
- p.load(new FileReader(propFileName));
- } catch (IOException ioe) {
- throw new RuntimeException(ioe);
+ try (Reader reader = new FileReader(propsFile)) {
+ p.load(reader);
}
// test each replacements