List of utility methods to do URL Download
void | downloadFileFromWeb(URL resourceURL, String fullPath) fullPath,eg: "D:\\ALL_integrate_patch_v4.2.2.r63143-20110722.zip FileOutputStream fos = null; BufferedInputStream bis = null; HttpURLConnection conn = null; byte[] buf = new byte[BUFFER_SIZE]; int size = 0; File fileTostore = null; try { conn = (HttpURLConnection) resourceURL.openConnection(); ... |
void | downloadFileFromWebserver(String fileUrl, String storageLocation) Downloads a file from the specified URL and stores the file to the specified location URL url = new URL(fileUrl); File file = new File(storageLocation); URLConnection urlConnection = url.openConnection(); InputStream inputStream = urlConnection.getInputStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); FileOutputStream fileOutputStream = new FileOutputStream(file); byte[] buffer = new byte[1024]; int bytesInBuffer = 0; ... |
File | downloadFileIfAvailable(URL url, File destination) download File If Available InputStream uStream = null; InputStream conn = null; try { uStream = url.openStream(); conn = new GZIPInputStream(uStream); } catch (IOException e1) { System.err.println("Problem while downloading file " + url); try { ... |
String | downloadFileToGivenNameElseExtension(URLConnection urlConnection, String fileName) Downloads the file using the given URLConnection and saves it to a temp directory as a file with a supplied name unless it does not have permission to do so, in which case it saves it to the temp directory with whatever name it pleases, but with the extension of the supplied name. return createTempFile(new BufferedInputStream(urlConnection.getInputStream()), fileName); |
String | downloadFromURL(String url) Retrieves a txt document from a URL try { URL oracle = new URL(url); BufferedReader in = new BufferedReader(new InputStreamReader(oracle.openStream())); String inputLine; String txt = ""; while ((inputLine = in.readLine()) != null) txt += inputLine + "\n"; in.close(); ... |
String | downloadFromUrl(String urlString, PrintStream logger) download From Url logger.println("downloadFromUrl: " + urlString); InputStream is = null; FileOutputStream fos = null; long timeStamp = System.currentTimeMillis(); URL url = new URL(urlString); File tempFile = File.createTempFile("instrumented-" + timeStamp, ".apk"); try { URLConnection urlConn = url.openConnection(); ... |
void | downloadFromUrl(URL url, String localFilename) Downloads a file from a URL InputStream is = null; FileOutputStream fos = null; try { URLConnection urlConn = url.openConnection(); is = urlConn.getInputStream(); fos = new FileOutputStream(localFilename); byte[] buffer = new byte[4096]; int len; ... |
void | downloadGzipCompressedFile(URL url, File destination) Download the content provided at URL url and stores the result to a local file InputStream uStream = url.openStream(); InputStream conn = new GZIPInputStream(uStream); File tempFile = File.createTempFile(getFilePrefix(destination), "." + getFileExtension(destination)); try { FileOutputStream outPut = new FileOutputStream(tempFile); GZIPOutputStream gzOutPut = new GZIPOutputStream(outPut); PrintWriter pw = new PrintWriter(gzOutPut); BufferedReader fileBuffer = new BufferedReader(new InputStreamReader(conn)); ... |
File | downloadHttp(String downloadURL, String basePath, String commonPathURL) download Http String urlDecode = URLDecoder.decode(downloadURL, "UTF-8").replaceAll("\\\\", "/"); urlDecode = urlDecode.replace(" ", "%20"); URL url = new URL(urlDecode); HttpURLConnection hurl = (HttpURLConnection) url.openConnection(); hurl.connect(); InputStream is = hurl.getInputStream(); String realPath = URLDecoder.decode(commonPathURL, "UTF-8").replaceAll("\\\\", "/").replace(" ", "%20"); realPath = realPath.replace("%20", " "); ... |
void | downloadImg(String urlPath, File file) download Img URL url = new URL(urlPath); try (InputStream in = new BufferedInputStream(url.openStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); FileOutputStream fos = new FileOutputStream(file);) { byte[] buf = new byte[1024]; int n = 0; while (-1 != (n = in.read(buf))) { out.write(buf, 0, n); ... |