### Question:
DataSchemeDataSource extends BaseDataSource { @Override public long open(DataSpec dataSpec) throws IOException { transferInitializing(dataSpec); this.dataSpec = dataSpec; Uri uri = dataSpec.uri; String scheme = uri.getScheme(); if (!SCHEME_DATA.equals(scheme)) { throw new ParserException("Unsupported scheme: " + scheme); } String[] uriParts = Util.split(uri.getSchemeSpecificPart(), ","); if (uriParts.length != 2) { throw new ParserException("Unexpected URI format: " + uri); } String dataString = uriParts[1]; if (uriParts[0].contains(";base64")) { try { data = Base64.decode(dataString, 0); } catch (IllegalArgumentException e) { throw new ParserException("Error while parsing Base64 encoded string: " + dataString, e); } } else { data = Util.getUtf8Bytes(URLDecoder.decode(dataString, C.ASCII_NAME)); } transferStarted(dataSpec); return data.length; } DataSchemeDataSource(); @Override long open(DataSpec dataSpec); @Override int read(byte[] buffer, int offset, int readLength); @Override @Nullable Uri getUri(); @Override void close(); static final String SCHEME_DATA; }### Answer:
@Test public void testIncorrectScheme() { try { schemeDataDataSource.open(buildDataSpec("http: fail(); } catch (IOException e) { } }
@Test public void testMalformedData() { try { schemeDataDataSource.open(buildDataSpec("data:text/plain;base64,,This%20is%20Content")); fail(); } catch (IOException e) { } try { schemeDataDataSource.open(buildDataSpec("data:text/plain;base64,IncorrectPadding==")); fail(); } catch (IOException e) { } }