test/java/util/Currency/PropertiesTest.java

Print this page

        

*** 25,52 **** 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"); } 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]); } - } - } - } private static void dump(String outfile) { File f = new File(outfile); PrintWriter pw; try { --- 25,45 ---- import java.text.*; import java.util.*; import java.util.regex.*; public class PropertiesTest { ! 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); } } private static void dump(String outfile) { File f = new File(outfile); PrintWriter pw; try {
*** 75,93 **** } pw.flush(); pw.close(); } ! private static void compare(String beforeFile, String afterFile) throws Exception { // load file contents Properties before = new Properties(); Properties after = new Properties(); ! try { ! before.load(new FileReader(beforeFile)); ! after.load(new FileReader(afterFile)); ! } catch (IOException ioe) { ! throw new RuntimeException(ioe); } // remove the same contents from the 'after' properties Set<String> keys = before.stringPropertyNames(); for (String key: keys) { --- 68,88 ---- } pw.flush(); pw.close(); } ! 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 (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,117 **** 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); } // test each replacements keys = p.stringPropertyNames(); Pattern propertiesPattern = --- 96,108 ---- System.out.printf(" --- NOT removed\n"); } } // now look at the currency.properties Properties p = new Properties(); ! try (Reader reader = new FileReader(propsFile)) { ! p.load(reader); } // test each replacements keys = p.stringPropertyNames(); Pattern propertiesPattern =