Any RFC 2397 URI Data Analyzer for Java?

dataurl := "data:" [ mediatype ] [ ";base64" ] "," data mediatype := [ type "/" subtype ] *( ";" parameter ) data := *urlchar parameter := attribute "=" value value := token / quoted-string 

According to these BNFs from the RFC, a comma that separates data from the mime type can actually be displayed both in the mime type and in the data, so there is no easy way (e.g. reg ex) to split the URI into parts. Thus, a complete parser is needed.

I am wondering if anyone knows of any data URI libraries in Java? My search on Google brought nothing.

+4
source share
2 answers

I had to implement my own parser. RFCs provided BNF, so full lexers and parsers can be implemented. However, in this simple case, I used a simple scan + stack mechanism to track quoted strings and determine the delimiter. javax.activation MimeType is used for actual Mime parsing.

0
source

GitHub has an implementation of a Java data URI parser called jDataUri .

Disclaimer: I am the author

+3
source

Source: https://habr.com/ru/post/1433378/


All Articles