List of utility methods to do URL Connection
String | urlContents(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(); ... |
boolean | urlExists(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; ... |
boolean | URLExists(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(); ... |
String | urlifyMap(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); |
void | urlToHtm(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; ... |
Reader | urlToReader(URL url) url To Reader URLConnection con = url.openConnection(); return new InputStreamReader(con.getInputStream()); |
String | urlToString(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()); ... |
String | urlToText(@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(); |