TldURIUtil { public static String getTldURI(URL url) throws IOException { try (InputStream inputStream = url.openStream(); InputStreamReader inputStreamReader = new InputStreamReader( inputStream); UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(inputStreamReader)) { StringBundler sb = null; String line = null; while ((line = unsyncBufferedReader.readLine()) != null) { if (sb == null) { int x = line.indexOf("<uri>"); if (x < 0) { continue; } x += 5; int y = line.indexOf("</uri>", x); if (y >= 0) { return line.substring(x, y); } sb = new StringBundler(line.substring(x)); } else { int y = line.indexOf("</uri>"); if (y >= 0) { sb.append(line.substring(0, y)); return sb.toString(); } sb.append(line); } } return null; } }  static String getTldURI(URL url);  }
@Test public void testGetTldUri1() throws IOException { URL url = TldURIUtilTest.class.getResource("dependencies/test_1.tld"); Assert.assertEquals("This is a test.", TldURIUtil.getTldURI(url)); }
@Test public void testGetTldUri2() throws IOException { URL url = TldURIUtilTest.class.getResource("dependencies/test_2.tld"); Assert.assertEquals("This is a test.", TldURIUtil.getTldURI(url)); }
@Test public void testGetTldUri3() throws IOException { URL url = TldURIUtilTest.class.getResource("dependencies/test_3.tld"); Assert.assertNull(TldURIUtil.getTldURI(url)); }
@Test public void testGetTldUri4() throws IOException { URL url = TldURIUtilTest.class.getResource("dependencies/test_4.tld"); Assert.assertNull(TldURIUtil.getTldURI(url)); }