Modifying the port of a URI
<p>In Java, the <code>URI</code> class is immutable.</p>

<p>Here's how I'm currently modifying the port:</p>

<pre><code>public URI setUriPort(URI uri,int port)
{
    try {
        URI newUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), port, uri.getPath(), uri.getQuery(), uri.getFragment());
        return newUri;
    } catch (URISyntaxException e) {
        LOG.error("Updating URI port failed:",e);
        return uri;
    }
}
</code></pre>

<p>Is there a simpler way?</p>
