UriData parse(String uri)

Parses a string as a data URI.

The string must have the format:

'data:' (type '/' subtype)? (';' attribute '=' value)* (';base64')? ',' data

where type, subtype, attribute and value are specified in RFC-2045, and data is a sequnce of URI-characters (RFC-2396 uric).

This means that all the characters must be ASCII, but the URI may contain percent-escapes for non-ASCII byte values that need an interpretation to be converted to the corresponding string.

Parsing doesn't check the validity of any part, it just checks that the input has the correct structure with the correct sequence of /, ;, = and , delimiters.

Accessing the individual parts may fail later if they turn out to have content that can't be decoded sucessfully as a string.

Source

static UriData parse(String uri) {
  if (!uri.startsWith("data:")) {
    throw new FormatException("Does not start with 'data:'", uri, 0);
  }
  return _parse(uri, 5, null);
}