test/java/util/Currency/PropertiesTest.java

Print this page

        

@@ -25,28 +25,21 @@
 import java.text.*;
 import java.util.*;
 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");
+    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 {
-                    dump(s[i]);
+            System.err.println("Usage:  java PropertiesTest -d <dumpfile>");
+            System.err.println("        java PropertiesTest -c <beforedump> <afterdump> <propsfile>");
+            System.exit(-1);
                 }
-            } 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]);
                 }
-            }
-        }
-    }
 
     private static void dump(String outfile) {
         File f = new File(outfile);
         PrintWriter pw;
         try {

@@ -75,19 +68,21 @@
         }
         pw.flush();
         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
         Set<String> keys = before.stringPropertyNames();
         for (String key: keys) {

@@ -101,17 +96,13 @@
                 System.out.printf(" --- NOT removed\n");
             }
         }
 
         // 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
         keys = p.stringPropertyNames();
         Pattern propertiesPattern =