1

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.

2
  • The scheme tag does not fit this question. It is used to refer to Scheme the language. Commented Mar 29, 2010 at 11:29
  • What do you expect the URI class to do with your scheme? A URI instance is just a representation of the URI and does not contain any scheme specific logic. Commented Mar 29, 2010 at 11:36

2 Answers 2

4

Are you sure you need to create a new URI scheme?

It's considered bad practice to create implementation-specific schemes.

See:

Sign up to request clarification or add additional context in comments.

Comments

1

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)

1 Comment

That's what I was looking at. But it doesn't really fit the needs. Since it does nothing to verify the URI structure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.