code: public static URI urlToUri( URL url ) throws URISyntaxException {
  
  		URI uri;
  		try {
  			// Possible failing step.
  			uri = url.toURI();
  
  		} catch( Exception e ) {
  			// URL did not comply with RFC 2396 => illegal non-escaped characters.
  			try {
  				uri = new URI(
  						url.getProtocol(),
  						url.getUserInfo(),
  						url.getHost(),
  						url.getPort(),
  						url.getPath(),
  						url.getQuery(),
  						url.getRef());
  
  			} catch( Exception e1 ) {
  				throw new URISyntaxException( String.valueOf( url ), "Broken URL." );
  			}
  		}
  
  		uri = uri.normalize();
  		return uri;
  	}
docs: Builds an URI from an URL (with a handle for URLs not compliant with RFC 2396).
  @param url an URL
  @return an URI
  @throws URISyntaxException if the URI is invalid and could not be repaired