List of utility methods to do URL Connection
String | getUrl(String serverName, String docid, String pageid) get Url String url = "http://" + serverName + "/pages/uri_template"; String template = getFromUrl(url); if (template.contains("{pageid}")) template = template.replace("{pageid}", pageid); if (template.contains("{docid}")) template = template.replace("{docid}", docid); return template; |
String | getURL(String url) get URL URLConnection conn = new URL(url).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String result = in.readLine(); return result; |
Properties | getUrlAsProperties(String urlString) get Url As Properties Properties props = new Properties(); InputStream in = getUrlAsStream(urlString); props.load(in); in.close(); return props; |
String | getUrlContent(String urlAddress) get Url Content URL url = new URL(urlAddress); URLConnection connection = url.openConnection(); connection.setUseCaches(false); InputStream inStream = null; inStream = connection.getInputStream(); InputStreamReader inStreamReader = new InputStreamReader(inStream); BufferedReader buffer = new BufferedReader(inStreamReader); StringBuffer strbuf = new StringBuffer(); ... |
String | getURLContents(URL u, Map get URL Contents URLConnection conn = u.openConnection(); conn.setDoOutput(true); OutputStreamWriter postWriter = new OutputStreamWriter(conn.getOutputStream()); boolean first = true; for (Entry<String, String> ent : data.entrySet()) { if (!first) postWriter.write("&"); String set = URLEncoder.encode(ent.getKey(), "UTF-8") + "=" ... |
String | getURLContentsAsString(URL url) Get the contents of a URL as a string StringBuffer ret = new StringBuffer(); BufferedReader br = null; try { URLConnection conn = url.openConnection(); br = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = br.readLine()) != null) { ret.append(line).append("\n"); ... |
List | getURLDataList(URL StrurlStringing) get URL Data List List list = new ArrayList(); try { System.out.println("Loading - " + StrurlStringing); URLConnection connection = StrurlStringing.openConnection(); connection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String str = in.readLine(); while (str != null) { ... |
String | getUrlEncoding(URLConnection connection) get Url Encoding String contentType = connection.getContentType(); String[] values = contentType.split(";"); String charset = defaultEncoding; for (String value : values) { value = value.trim(); if (value.toLowerCase(Locale.ENGLISH).startsWith("charset=")) { charset = value.substring("charset=".length()); return charset; |
URL | getURLForward(URL url) get URL Forward URLConnection con = url.openConnection(); String location = con.getHeaderField("Location"); if (location != null) { return new URL(location); return url; |
InputStream | getURLInputStream(final URL url) Get an InputStream from a URL. return getURLInputStream(url, DEFAULT_URL_CONNECT_TIMEOUT, DEFAULT_URL_READ_TIMEOUT);
|