In Java, the URI
class is immutable.
Here's how I'm currently modifying the port:
public URI uriWithPort(URI uri, int port) {
try {
return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), port,
uri.getPath(), uri.getQuery(), uri.getFragment());
} catch (URISyntaxException e) {
LOG.error("Updating URI port failed:",e);
return uri;
}
}
Is there a simpler way?
You can also use URIBuider
http://download.oracle.com/javaee/6/api/javax/ws/rs/core/UriBuilder.html
UriBuilder.fromURI(uri).port(port).build("foo", "bar");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With