Java Utililty Methods URLConnection Create

List of utility methods to do URLConnection Create

Description

The list of methods to do URLConnection Create are organized into topic(s).

Method

URLConnectionopenConnection(final URL url)
open Connection
URLConnection conn = url.openConnection();
conn.setReadTimeout(3000);
conn.setDefaultUseCaches(false);
conn.setUseCaches(false);
return conn;
URLConnectionopenConnection(String urlPath)
open Connection
try {
    URL url = new URL(urlPath);
    return url.openConnection();
} catch (IOException ex) {
    throw new UncheckedIOException(ex);
URLConnectionopenConnection(URL localURL)
open Connection
URLConnection connection;
if (proxyHost != null && proxyPort != null) {
    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
    connection = localURL.openConnection(proxy);
} else {
    connection = localURL.openConnection();
return connection;
...
URLConnectionopenConnection(URL url)
open Connection
try {
    URLConnection connection = url.openConnection();
    connection.setUseCaches(false);
    return connection;
} catch (IOException e) {
    throw new IllegalStateException(e);
URLConnectionopenConnection(URL url)
Opens a url with read and connect timeouts
URLConnection connection = url.openConnection();
connection.setConnectTimeout(SOCKET_TIMEOUT);
connection.setReadTimeout(SOCKET_TIMEOUT);
return connection;
URLConnectionopenConnection(URL url)
opens a connection to a url and adds the headers (see below) you should use this instead of the method in the URL class
URLConnection conn = url.openConnection();
addHeaders(conn);
return conn;
URLConnectionopenConnection(URL url)
open Connection
long timeoutExpiredMs = System.currentTimeMillis() + WAIT_TIME;
URLConnection jaggeryServerConnection = null;
try {
    jaggeryServerConnection = url.openConnection();
} catch (IOException ignored) {
while ((jaggeryServerConnection == null) && (System.currentTimeMillis() <= timeoutExpiredMs)) {
    try {
...
URLConnectionopenConnectionForceNoProxy(URL url)
open Connection Force No Proxy
return url.openConnection(Proxy.NO_PROXY);
URLConnectionopenConnectionTo(URL descriptor)
Checks that descriptor exist, is a file and is readable
URLConnection conn;
try {
    conn = descriptor.openConnection();
} catch (IOException e) {
    throw new IllegalArgumentException(
            "Connection to " + descriptor.toExternalForm() + " could not be established.", e);
return conn;
...
InputStreamopenInputStream(URL url)
open Input Stream
URLConnection uRLConnection = url.openConnection();
uRLConnection.setRequestProperty("User-Agent", "Valve/Steam HTTP Client 1.0 (tenfoot)");
uRLConnection.setRequestProperty("Cookie", "birthtime=-3599; lastagecheckage=1-January-1970");
uRLConnection.setConnectTimeout(8000);
uRLConnection.setReadTimeout(8000);
return uRLConnection.getInputStream();