code: public static URI changeProtocolAndPort(String protocol, int port, URI template) throws URISyntaxException {
      return new URI(protocol, template.getUserInfo(), template.getHost(), port, template.getPath(), template.getQuery(), null);
    }
docs: Returns a new URI object, based on the specified URI template, with an updated port (scheme) and port.  If the port
  number is -1, then the default port is used in the resulting URI.
  
  @param protocol the new protocol (scheme) in the resulting URI.
  @param port the new port in the resulting URI, or the default port if -1 is provided.
  @param template the source of all other values for the new URI.
  @return a new URI object with the updated protocol and port.
  @throws URISyntaxException