Here you can find the source of openConnection(URL localURL)
private static URLConnection openConnection(URL localURL) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import java.net.URLConnection; public class Main { private static String proxyHost = null; private static Integer proxyPort = null; private static URLConnection openConnection(URL localURL) throws IOException { URLConnection connection; if (proxyHost != null && proxyPort != null) { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)); connection = localURL.openConnection(proxy); } else {/*from ww w. j a va 2 s . c o m*/ connection = localURL.openConnection(); } return connection; } }