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.
根据来自RFC的这些BNF,将数据与mime类型分开的逗号实际上可以同时出现在mime类型和数据中,因此没有简单的方法(即reg ex)将URI分解为部分。因此需要完整的解析器。
I am wondering does any one know any data URI libraries in Java? My Google search didn't yield anything.
我想知道有没有人知道Java中的任何数据URI库?我的Google搜索没有产生任何结果。
2 个解决方案
#1
3
There is a Java data URI parser implementation available on GitHub called jDataUri.
GitHub上有一个名为jDataUri的Java数据URI解析器实现。
Disclaimer: I am the author
免责声明:我是作者
#2
0
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.
我最终不得不实现自己的解析器。 RFC提供了BNF,因此可以实现完整的词法分析器和语法分析器。然而,对于这个简单的情况,我使用了一个简单的扫描+堆栈机制来跟踪引用的字符串并找到分隔逗号。 javax.activation的MimeType用于实际的Mime解析。
#1
3
There is a Java data URI parser implementation available on GitHub called jDataUri.
GitHub上有一个名为jDataUri的Java数据URI解析器实现。
Disclaimer: I am the author
免责声明:我是作者
#2
0
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.
我最终不得不实现自己的解析器。 RFC提供了BNF,因此可以实现完整的词法分析器和语法分析器。然而,对于这个简单的情况,我使用了一个简单的扫描+堆栈机制来跟踪引用的字符串并找到分隔逗号。 javax.activation的MimeType用于实际的Mime解析。