Java URL Connection getStreamWithTimeOut(String stringUrl, Integer timeOutInMilli)

Here you can find the source of getStreamWithTimeOut(String stringUrl, Integer timeOutInMilli)

Description

get Stream With Time Out

License

Apache License

Declaration

public static URLConnection getStreamWithTimeOut(String stringUrl, Integer timeOutInMilli) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.net.URL;
import java.net.URLConnection;

public class Main {
    private static final Integer DEFAULT_TIME_OUT_IN_MILLI = 10000;

    public static URLConnection getStreamWithTimeOut(String stringUrl, Integer timeOutInMilli) throws IOException {
        URL url = new URL(stringUrl);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setReadTimeout(timeOutInMilli);
        urlConnection.setConnectTimeout(timeOutInMilli);
        return urlConnection;
    }/*from w ww.j a  v  a 2 s . c  om*/

    public static URLConnection getStreamWithTimeOut(String stringUrl) throws IOException {
        return getStreamWithTimeOut(stringUrl, DEFAULT_TIME_OUT_IN_MILLI);
    }
}

Related

  1. getRemoteTimestamp(final String url)
  2. getRequest(URLConnection conn)
  3. getRequestHeaders(URLConnection conn)
  4. getResultsWithEncoding(URLConnection source, String encoding)
  5. getStream(URL url)
  6. getString(URL url)
  7. getType(URLConnection connection)
  8. getUrl(String serverName, String docid, String pageid)
  9. getURL(String url)