Any RFC 2397 Data URI Parser for Java?

半腔热情 提交于 2019-12-08 21:16:01

问题


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

   value := token / quoted-string

According to these BNF from the RFCs, the comma that separates the data from the mime type can actually appear in both the mime type and the data, so there's no simple way (i.e. reg ex) to break the URI into parts. Thus a full parser is needed.

I am wondering does any one know any data URI libraries in Java? My Google search didn't yield anything.


回答1:


There is a Java data URI parser implementation available on GitHub called jDataUri.

Disclaimer: I am the author




回答2:


I ended up having to implement my own parser. The RFCs provided BNFs, so it's possible to implement full lexers and syntax analysers. However, for this simple case, I jused used a simple scanning + stack mechamism to trace the quoted strings and locate the separating comma. javax.activation's MimeType is used for actual Mime parsing.



来源:https://stackoverflow.com/questions/12353552/any-rfc-2397-data-uri-parser-for-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!