code: public static URI toURI(URL url) throws URISyntaxException {
          if (url == null) {
              throw MESSAGES.nullArgument("url");
          }
          try {
              return url.toURI();
          } catch (URISyntaxException e) {
              String urispec = url.toExternalForm();
              // Escape percent sign and spaces
              urispec = urispec.replaceAll("%", "%25");
              urispec = urispec.replaceAll(" ", "%20");
              return new URI(urispec);
          }
      }
docs: Deal with urls that may include spaces.
  
  @param url the url
  @return uri the uri
  @throws URISyntaxException for any error