List of utility methods to do URL Read
String | getHtml(String urlString) get Html if (urlString.contains("id")) { StringBuilder html = new StringBuilder(); InputStreamReader isr = null; BufferedReader br = null; try { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); isr = new InputStreamReader(conn.getInputStream()); ... |
String | getHTML(String urlToRead) get HTML URL url; HttpURLConnection conn; BufferedReader rd; String line; String result = ""; try { url = new URL(urlToRead); conn = (HttpURLConnection) url.openConnection(); ... |
String | getHTML(String urlToRead) Makes a get request to the provided url. URL url; HttpURLConnection conn; BufferedReader rd; String line; StringBuilder result = new StringBuilder(); try { url = new URL(urlToRead); conn = (HttpURLConnection) url.openConnection(); ... |
String | getHttpResponse(HttpURLConnection conn, int expectedReturnCode) get Http Response System.out.println("response code:" + conn.getResponseMessage()); if (conn.getResponseCode() != expectedReturnCode) { System.out.println("Custom Error:" + conn.getResponseCode()); throw new IOException(conn.getResponseMessage()); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; ... |
String | getHTTPResponse(String url) get HTTP Response HttpURLConnection con = (HttpURLConnection) (new URL(url)).openConnection(); BufferedReader reader = new BufferedReader(new InputStreamReader( "gzip".equals(con.getContentEncoding()) ? new GZIPInputStream(con.getInputStream()) : con.getInputStream())); StringBuilder response = new StringBuilder(); String l; while ((l = reader.readLine()) != null) { response.append(l); ... |
String | getHttpResponse(String urlStr) get Http Response URL url = new URL(urlStr); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); conn.setConnectTimeout(5000); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode()); BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); StringBuilder outputBuilder = new StringBuilder(); String output; while ((output = br.readLine()) != null) { outputBuilder.append(output); conn.disconnect(); return outputBuilder.toString(); |
long | getLastModified(HttpURLConnection conn) get Last Modified long result = conn.getHeaderFieldDate("Last-Modified", 0L); return result; |
long | getLastModified(HttpURLConnection connection) get Last Modified return connection.getHeaderFieldDate(LAST_MODIFIED, -1);
|
long | getRemoteFileLength(String url) get Remote File Length try { HttpURLConnection connection; connection = (HttpURLConnection) new URL(url).openConnection(); connection.setConnectTimeout(3000); connection.connect(); long length = connection.getContentLength(); connection.disconnect(); return length; ... |
int | getRemoteFileSize(URL url) get Remote File Size URLConnection connection; while (true) { connection = url.openConnection(); if (connection instanceof HttpURLConnection) { int responseCode = ((HttpURLConnection) connection).getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { break; } else { ... |