PublicSuffixListParser { public void parse(Reader list) throws IOException { Collection<String> rules = new ArrayList<String>(); Collection<String> exceptions = new ArrayList<String>(); BufferedReader r = new BufferedReader(list); StringBuilder sb = new StringBuilder(256); boolean more = true; while (more) { more = readLine(r, sb); String line = sb.toString(); if (line.length() == 0) continue; if (line.startsWith(" if (line.startsWith(".")) line = line.substring(1); boolean isException = line.startsWith("!"); if (isException) line = line.substring(1); if (isException) { exceptions.add(line); } else { rules.add(line); } } filter.setPublicSuffixes(rules); filter.setExceptions(exceptions); } PublicSuffixListParser(PublicSuffixFilter filter); void parse(Reader list);  }
@Test public void testParse() throws Exception { BasicClientCookie cookie = new BasicClientCookie("name", "value"); cookie.setDomain(".jp"); Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.jp", 80, "/stuff", false))); cookie.setDomain(".ac.jp"); Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.ac.jp", 80, "/stuff", false))); cookie.setDomain(".any.tokyo.jp"); Assert.assertFalse(filter.match(cookie, new CookieOrigin("apache.any.tokyo.jp", 80, "/stuff", false))); cookie.setDomain(".metro.tokyo.jp"); Assert.assertTrue(filter.match(cookie, new CookieOrigin("apache.metro.tokyo.jp", 80, "/stuff", false))); }