Reputation: 5582
I have existing code that uses java.net.URL
instead of java.net.URI
all over the codebase.
Also, the code has URL parser that parses URLs appearing in some text body. All URLs that do not have a protocol prefix, such as www.google.com, are considered malformed when converting to URL
object.
Is there a clean way to handle such cases in Java?
Upvotes: -1
Views: 1348
Reputation: 310913
Create a URI and see if it has a scheme. Set the scheme, or reconstruct the URI with a scheme argument, if not present. Convert to URL.
Upvotes: -1