问题
I need to create a custom URI scheme for my project. i.e
urn:myprotocol:{p1}:{p2}:{p3}:{p4}
- opaque representation
myprotocol://{p1}/{p2}/{p3}/{p4}
- hierarchical representation.
How can I add my scheme to Java URI class? Or, how can I make Java URI to understand my scheme, so I could use it in my code?
Concrete examples are welcome.
Thanks.
回答1:
Are you sure you need to create a new URI scheme?
It's considered bad practice to create implementation-specific schemes.
See:
- http://infomesh.net/2001/09/urischemes
- http://www.w3.org/TR/webarch/#URI-scheme
- http://tools.ietf.org/search/rfc4395
回答2:
The Java API has a pretty good explanation of how to do that: http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html
Without knowing what you are trying to do, I would use this constructor of URI: URI(String scheme, String authority, String path, String query, String fragment)
来源:https://stackoverflow.com/questions/2537255/creating-custom-uri-scheme-using-uri-class