code: private static URLConnection getConnection(String url, final ProxyConfig proxy) throws IOException {
          URLConnection conn = null;
  
          if (proxy != null && proxy.getProxyUser() != null) {
              Authenticator.setDefault(new Authenticator() {
                  @Override
                  protected PasswordAuthentication getPasswordAuthentication() {
                      return new PasswordAuthentication(proxy.getProxyUser(), proxy.getProxyPassword().toCharArray());
                  }
  
              });
          }
  
          if (proxy != null) {
              Proxy thisProxy = new Proxy(proxy.getProxyType(), new InetSocketAddress(proxy.getProxyHost(), proxy.getProxyPort()));
              conn = new URL(url).openConnection(thisProxy);
          } else {
              conn = new URL(url).openConnection();
          }
  
          return conn;
      }
docs: Method to open/establish a URLConnection.
  
  @param url The URL to connect to.
  @param proxy The proxy configuration.
  @return {@link URLConnection}
  @throws IOException