@@ -29,6 +29,7 @@ public static Homoglyph build() throws IOException {
2929 throw new MissingResourceException ("Unable to read " + CHAR_CODES_FILE ,
3030 HomoglyphBuilder .class .getName (), CHAR_CODES_FILE );
3131 }
32+
3233 return build (new InputStreamReader (is ));
3334 }
3435
@@ -58,23 +59,24 @@ public static Homoglyph build(final String path) throws IOException {
5859 */
5960 public static Homoglyph build (final Reader reader ) throws IOException {
6061 final List <Set <Integer >> homoglyphs = new ArrayList <Set <Integer >>();
61- final BufferedReader bufferedReader = new BufferedReader (reader );
6262
63- String line ;
64- while ((line = bufferedReader .readLine ()) != null ){
65- line = line .trim ();
66- if (line .startsWith ("#" ) || line .length () == 0 ){
67- continue ;
68- }
69- final Set <Integer > set = new HashSet <Integer >();
70- for (String charCode : line .split ("," )) {
71- try {
72- set .add (Integer .parseInt (charCode , 16 ));
73- } catch (NumberFormatException ex ){
74- // ignore badly formatted lines
63+ try (final BufferedReader bufferedReader = new BufferedReader (reader )) {
64+ String line ;
65+ while ((line = bufferedReader .readLine ()) != null ){
66+ line = line .trim ();
67+ if (line .startsWith ("#" ) || line .length () == 0 ){
68+ continue ;
69+ }
70+ final Set <Integer > set = new HashSet <Integer >();
71+ for (String charCode : line .split ("," )) {
72+ try {
73+ set .add (Integer .parseInt (charCode , 16 ));
74+ } catch (NumberFormatException ex ){
75+ // ignore badly formatted lines
76+ }
7577 }
78+ homoglyphs .add (set );
7679 }
77- homoglyphs .add (set );
7880 }
7981
8082 return new Homoglyph (homoglyphs );
0 commit comments