我想知道是否有任何很好的简单方法可以使用 Java 验证 Diameter URI(下面的描述)?
Note, a Diameter URI must have one of the forms:
aaa://FQDN[:PORT][;transport=TRANS][;protocol=PROT]
aaas://FQDN[:PORT][;transport=TRANS][;protocol=PROT]
The FQDN (mandatory) has to be replaced with the fully qualified host name (or IP), the PORT (optional, default is 3868) with the port number, TRANS (optional) with the transport protocol (can be TCP or SCTP) and PROT (optional) with diameter.
Some examples of the acceptable forms are:
aaa://server.com
aaa://127.0.0.1
aaa://server.com:1234
aaas://server.com:1234;transport=tcp
aaas://[::1]
aaas://[::1]:1234
aaas://[::1]:1234;transport=tcp;protocol=diameter
Note, as shown above, if using an IPv6 address, the address must be placed in box brackets, whereas the port number (if specified), with its colon separator, should be outside of the brackets.
我认为使用正则表达式执行此操作会非常混乱且难以理解,而且我看到的其他不使用正则表达式的示例看起来也很尴尬(例如https://code.google.com/p/cipango/源/浏览/主干/cipango-diameter/src/main/java/org/cipango/diameter/util/AAAUri.java?r=763)。
所以想知道是否有更好的方法来做到这一点,例如像 URI 验证器库这样的东西,它采用一些规则(例如上面的 Diameter URI 的规则),然后将它们应用于一些输入来验证它?
我还查看了 Google Guava 库,看看是否有什么可以帮助的,但我看不到任何东西。
非常感谢!