X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Futil%2FTestPublicSuffixes.java;h=950224154004a111a326092bf02d9d1179a245ac;hb=d7be034f96e06985f57d86d2779c434276b5bd4d;hp=dba88303a827296b1593d93ff2477d92d623624d;hpb=7c008262bfef15165e6c9e5f16aaffa8177e5fbb;p=gigi.git diff --git a/tests/org/cacert/gigi/util/TestPublicSuffixes.java b/tests/org/cacert/gigi/util/TestPublicSuffixes.java index dba88303..95022415 100644 --- a/tests/org/cacert/gigi/util/TestPublicSuffixes.java +++ b/tests/org/cacert/gigi/util/TestPublicSuffixes.java @@ -24,29 +24,35 @@ public class TestPublicSuffixes { */ @Parameters(name = "publicSuffix({0}) = {1}") public static Iterable genParams() throws IOException { - BufferedReader br = new BufferedReader(new InputStreamReader(TestPublicSuffixes.class.getResourceAsStream("TestPublicSuffixes.txt"), "UTF-8")); - ArrayList result = new ArrayList<>(); - String line; - while ((line = br.readLine()) != null) { - if (line.startsWith("//") || line.isEmpty()) { - continue; - } - String parseSuffix = "checkPublicSuffix("; - if (line.startsWith(parseSuffix)) { - String data = line.substring(parseSuffix.length(), line.length() - 2); - String[] parts = data.split(", "); - if (parts.length != 2) { - throw new Error("Syntax error in public suffix test data file: " + line); + BufferedReader br = null; + try { + br = new BufferedReader(new InputStreamReader(TestPublicSuffixes.class.getResourceAsStream("TestPublicSuffixes.txt"), "UTF-8")); + ArrayList result = new ArrayList<>(); + String line; + while ((line = br.readLine()) != null) { + if (line.startsWith("//") || line.isEmpty()) { + continue; + } + String parseSuffix = "checkPublicSuffix("; + if (line.startsWith(parseSuffix)) { + String data = line.substring(parseSuffix.length(), line.length() - 2); + String[] parts = data.split(", "); + if (parts.length != 2) { + throw new Error("Syntax error in public suffix test data file: " + line); + } + result.add(new String[] { + parse(parts[0]), parse(parts[1]) + }); + } else { + throw new Error("Unparsable line: " + line); } - result.add(new String[] { - parse(parts[0]), parse(parts[1]) - }); - } else { - throw new Error("Unparsable line: " + line); + } + return result; + } finally { + if (br != null) { + br.close(); } } - - return result; } private static String parse(String data) {