test/java/lang/Character/CheckScript.java

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

*** 10,33 **** import java.util.regex.*; import java.lang.Character.UnicodeScript; public class CheckScript { ! public static void main(String[] args) throws Exception { ! ! BufferedReader sbfr = null; if (args.length == 0) { ! sbfr = new BufferedReader(new FileReader(new File(System.getProperty("test.src", "."), "Scripts.txt"))); } else if (args.length == 1) { ! sbfr = new BufferedReader(new FileReader(args[0])); } else { System.out.println("java CharacterScript Scripts.txt"); throw new RuntimeException("Datafile name should be specified."); } Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s+;\\s+(\\w+)\\s+#.*").matcher(""); String line = null; HashMap<String,ArrayList<Integer>> scripts = new HashMap<>(); while ((line = sbfr.readLine()) != null) { if (line.length() <= 1 || line.charAt(0) == '#') { continue; } m.reset(line); --- 10,36 ---- import java.util.regex.*; import java.lang.Character.UnicodeScript; public class CheckScript { ! static BufferedReader open(String[] args) throws FileNotFoundException { if (args.length == 0) { ! return new BufferedReader(new FileReader(new File(System.getProperty("test.src", "."), "Scripts.txt"))); } else if (args.length == 1) { ! return new BufferedReader(new FileReader(args[0])); } else { System.out.println("java CharacterScript Scripts.txt"); throw new RuntimeException("Datafile name should be specified."); } + } + + public static void main(String[] args) throws Exception { + Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s+;\\s+(\\w+)\\s+#.*").matcher(""); String line = null; HashMap<String,ArrayList<Integer>> scripts = new HashMap<>(); + try (BufferedReader sbfr = open(args)) { while ((line = sbfr.readLine()) != null) { if (line.length() <= 1 || line.charAt(0) == '#') { continue; } m.reset(line);
*** 43,53 **** } ranges.add(start); ranges.add(end); } } ! sbfr.close(); // check all defined ranges Integer[] ZEROSIZEARRAY = new Integer[0]; for (String name : scripts.keySet()) { System.out.println("Checking " + name + "..."); Integer[] ranges = scripts.get(name).toArray(ZEROSIZEARRAY); --- 46,56 ---- } ranges.add(start); ranges.add(end); } } ! } // check all defined ranges Integer[] ZEROSIZEARRAY = new Integer[0]; for (String name : scripts.keySet()) { System.out.println("Checking " + name + "..."); Integer[] ranges = scripts.get(name).toArray(ZEROSIZEARRAY);