URLUtil { public static byte[] getData(String url, String encoding) throws IOException { if (url.startsWith(DATA_PROTOCOL)) { return parseDataURL(url, encoding); } else { final URL u = new URL(url); final InputStream in = u.openStream(); try { final ByteArrayOutputStream baout = new ByteArrayOutputStream(); IOUtil.copy(in, baout); return baout.toByteArray(); } finally { IOUtil.closeQuietly(in); } } }  static byte[] getData(String url, String encoding); static String getDataEncoding(String url); static boolean isURL(String message); static String getURL(String message); static final String URL_START; static final String URL_END; }
@Test public void testGetData() throws Exception { byte[] data = URLUtil.getData("data:;base64,flRlc3R+", "US-ASCII"); String text = new String(data, "US-ASCII"); assertEquals("~Test~", text); data = URLUtil.getData("data:text/plain;charset=iso-8859-1,%7ETest%7E%E5", "ISO-8859-1"); text = new String(data, "ISO-8859-1"); assertEquals("~Test~\u00E5", text); }