X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Futil%2FPublicSuffixes.java;h=19c7b1dc952d15bf6255f98209c0ce7ebe1e1a5d;hb=557a8a2e5f395400467459f003956bf7660cc044;hp=9fd2217b2ecd89f4b67891762eab1c0b34a6fb95;hpb=30d4d39245698b9257a6ce6810f55273a3ec25ef;p=gigi.git diff --git a/src/org/cacert/gigi/util/PublicSuffixes.java b/src/org/cacert/gigi/util/PublicSuffixes.java index 9fd2217b..19c7b1dc 100644 --- a/src/org/cacert/gigi/util/PublicSuffixes.java +++ b/src/org/cacert/gigi/util/PublicSuffixes.java @@ -2,32 +2,39 @@ package org.cacert.gigi.util; import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.net.IDN; import java.util.HashSet; public class PublicSuffixes { - HashSet suffixes = new HashSet<>(); + private HashSet suffixes = new HashSet<>(); - HashSet wildcards = new HashSet<>(); + private HashSet wildcards = new HashSet<>(); - HashSet exceptions = new HashSet<>(); + private HashSet exceptions = new HashSet<>(); - private static final String url = "https://publicsuffix.org/list/effective_tld_names.dat"; + static final String url = "https://publicsuffix.org/list/effective_tld_names.dat"; private static PublicSuffixes instance; - private static void generateDefault() throws IOException { - try (BufferedReader br = new BufferedReader(new InputStreamReader(PublicSuffixes.class.getResourceAsStream("effective_tld_names.dat"), "UTF-8"))) { - instance = new PublicSuffixes(br); + private static PublicSuffixes generateDefault() throws IOException { + InputStream res = PublicSuffixes.class.getResourceAsStream("effective_tld_names.dat"); + + if (null == res) { + throw new Error("Public Suffix List could not be loaded."); + } + + try (BufferedReader br = new BufferedReader(new InputStreamReader(res, "UTF-8"))) { + return new PublicSuffixes(br); } } - public static PublicSuffixes getInstance() { + public synchronized static PublicSuffixes getInstance() { if (instance == null) { try { - generateDefault(); + instance = generateDefault(); } catch (IOException e) { throw new Error(e); } @@ -44,7 +51,11 @@ public class PublicSuffixes { if (line.isEmpty()) { continue; } - line = line.split("\\s", 2)[0]; + String[] lineParts = line.split("\\s", 2); + if (lineParts.length == 0) { + throw new Error("split had strange behavior"); + } + line = lineParts[0]; if (line.startsWith("*.")) { String data = line.substring(2); if (data.contains("*") || data.contains("!")) { @@ -124,4 +135,5 @@ public class PublicSuffixes { } return false; } + }