### Question:
Utils { public static Base64DataURI decodeBase64DataURI(String dataURI) throws ParseException { if (dataURI.startsWith(DATA_URI_PREFIX) == false) { throw new ParseException("Data URI should start with 'data:'", 0); } int commaIndex = dataURI.indexOf(','); if (commaIndex == -1) { throw new ParseException("Comma is mandatory in Data URI", 0); } String header = dataURI.substring(0, commaIndex); int indexOfBase64 = header.indexOf(DATA_URI_BASE64_ENC); if (indexOfBase64 == -1) { throw new ParseException("Only Data URI encoded in base64 are supported", header.length()); } byte[] data = decodeBase64(dataURI.substring(commaIndex + 1)); String mimeType = header.substring(DATA_URI_PREFIX.length(), indexOfBase64); return new Base64DataURI(mimeType, data); } private  Utils(); static List<String> getIPAddresses(); static boolean isOnEV3(); static String encodeBase64(byte[] buf); static byte[] decodeBase64(String data); static Base64DataURI decodeBase64DataURI(String dataURI); static final String DATA_URI_PREFIX; static final String DATA_URI_BASE64_ENC; }### Answer:
@Test public void testDataURI() throws ParseException { byte[] src = new byte[] { (byte) 30, (byte) 130, (byte) 230, (byte) 30 }; Utils.Base64DataURI dataURI = new Utils.Base64DataURI("application/octet-stream", src); System.out.println(dataURI.encode()); Assert.assertEquals(dataURI.encode(), "data:application/octet-stream;base64,HoLmHg=="); Utils.Base64DataURI actual = Utils.decodeBase64DataURI("data:application/octet-stream;base64,HoLmHg=="); Assert.assertEquals(actual.getMimeType(), "application/octet-stream"); Assert.assertEquals(actual.getData(), src); try { Utils.decodeBase64DataURI("HoLmHg=="); Assert.fail("Parse exception expected if 'data:' not present"); } catch (ParseException pe) { } try { Utils.decodeBase64DataURI("data:HoLmHg=="); Assert.fail("Parse exception expected if ',' not present"); } catch (ParseException pe) { } try { Utils.decodeBase64DataURI("data:application/octet-stream,HoLmHg=="); Assert.fail("Parse exception expected if not base64 encoding"); } catch (ParseException pe) { } }