List of utility methods to do URL Download
void | downloadUrlToFile(String surl, File file, String method) download Url To File URL url = new URL(surl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (notEmpty(method)) conn.setRequestMethod(method); else conn.setRequestMethod("GET"); conn.setDoInput(true); conn.connect(); ... |
void | downloadUrlToFile(URL url, File file) Downloads the byte contents of a URL to a specified file. BufferedInputStream is = null; BufferedOutputStream os = null; try { is = new BufferedInputStream(url.openStream()); os = new BufferedOutputStream(new FileOutputStream(file)); byte[] b = new byte[4096]; int len = -1; while ((len = is.read(b)) != -1) ... |
void | downloadUrlToFile(URL url, File result) download Url To File IOException exception = null; InputStream is = null; DataInputStream dis = null; FileOutputStream fos = null; byte[] buf = new byte[1024]; try { is = url.openStream(); dis = new DataInputStream(new BufferedInputStream(is)); ... |
String | downloadWebpage(String url) download Webpage try { return downloadWebpage(new URL(url)); } catch (MalformedURLException e) { return null; |
void | downloadZip(URL file, File dump) Downloads a Zip Archive and extracts it to specified folder. ZipInputStream in = new ZipInputStream(file.openStream()); ZipEntry en = in.getNextEntry(); while (en != null) { recursiveUnpack(in, en, dump); en = in.getNextEntry(); in.close(); |
void | downlod(String url, File dest) downlod int retry = 0; while (++retry <= 3) { System.out.println("Downloading " + url + " Retry count: " + retry); try { URLConnection conn = new URL(url).openConnection(); conn.setConnectTimeout(TIMEOUT); conn.setReadTimeout(TIMEOUT); InputStream in = conn.getInputStream(); ... |
String | downNetImg(String filePath, String remotePath, String htmlUrl, String fileName) down Net Img File file = new File(filePath); if (!file.exists()) { file.mkdirs(); URL url = null; OutputStream os = null; try { url = new URL(htmlUrl); ... |
Map | downPicture(String filePath, String imageUrl, String fileName) down Picture Map<String, Object> map = new HashMap<String, Object>(); Integer size = null; String mime = null; try { File files = new File(filePath); if (!files.exists()) { files.mkdirs(); URL url = new URL(imageUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); InputStream is = connection.getInputStream(); if (!filePath.endsWith("/")) { filePath = filePath + "/"; File file = new File(filePath + fileName); FileOutputStream out = new FileOutputStream(file); int i = 0; while ((i = is.read()) != -1) { out.write(i); size = connection.getContentLength(); mime = connection.getContentType(); is.close(); } catch (Exception e) { map.put("size", size); map.put("mime", mime); return map; |
String | fetchUrl(String _url, String charset) fetch Url BufferedReader reader = null; try { URL url = new URL(_url); if (charset == null) reader = new BufferedReader(new InputStreamReader(url.openStream())); else reader = new BufferedReader(new InputStreamReader(url.openStream(), charset)); StringBuilder sb = new StringBuilder(); ... |
String | fetchURL(String url) fetch URL String content = null; URLConnection connection = null; try { connection = new URL(url).openConnection(); Scanner scanner = new Scanner(connection.getInputStream()); scanner.useDelimiter("\\Z"); content = scanner.next(); return content; ... |