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?