Java Utililty Methods URL Connection

List of utility methods to do URL Connection

Description

The list of methods to do URL Connection are organized into topic(s).

Method

StringurlContents(String urlString)
url Contents
try {
    URL url = new URL(urlString);
    URLConnection connection = url.openConnection();
    connection.setConnectTimeout(30000);
    connection.setReadTimeout(30000);
    return bufferedReaderToString(new BufferedReader(new InputStreamReader(connection.getInputStream())));
} catch (Exception e) {
    e.printStackTrace();
...
booleanurlExists(String urlString)
url Exists
InputStream is = null;
try {
    URL url = new URL(urlString);
    URLConnection con = url.openConnection();
    is = con.getInputStream();
    return true;
} catch (Exception e) {
    return false;
...
booleanURLExists(URL url, StringBuffer errorMsg)
Method to tell whether a given URL exists.
if (url == null) {
    return false;
try {
    URLConnection con = url.openConnection();
    con.connect();
    int conLength = con.getContentLength();
    con.getInputStream().close();
...
StringurlifyMap(Long nid, double latitude, double longitude)
urlify Map
String url = "http://mapas.sapo.pt/cmap/cmap.html?sz=640,960&ll=" + latitude + "," + longitude
        + "&z=16&t=m&mks=" + longitude + "," + latitude + ",0,asd," + "&nid=" + nid;
return shortenUrl(url);
voidurlToHtm(String word, String findurl, String path)
url To Htm
URL url = null;
try {
    url = new URL(findurl);
} catch (MalformedURLException e) {
    e.printStackTrace();
String charset = "utf-8";
int sec_cont = 1000;
...
ReaderurlToReader(URL url)
url To Reader
URLConnection con = url.openConnection();
return new InputStreamReader(con.getInputStream());
StringurlToString(String url)
url To String
URLConnection conn = new URL(url).openConnection();
InputStream is = conn.getInputStream();
String contentType = conn.getContentType();
if (contentType != null) {
    contentType = contentType.toLowerCase();
    int i = contentType.indexOf(CHARSET_MARKER);
    if (i > -1) {
        String charsetName = contentType.substring(i + CHARSET_MARKER.length());
...
StringurlToText(@Nonnull String url)
Obtains content of URL to String.
URL website = new URL(url);
URLConnection connection = website.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine + "\n");
in.close();
return response.toString();