Java Utililty Methods URL Download

List of utility methods to do URL Download

Description

The list of methods to do URL Download are organized into topic(s).

Method

Filedownload(String urlString)
download
StringBuffer sb = new StringBuffer(System.getProperty("java.io.tmpdir")).append(File.separator)
        .append(System.currentTimeMillis()).append(".jpg");
File outFile = new File(sb.toString());
URL url = null;
OutputStream os = null;
InputStream is = null;
try {
    url = new URL(urlString);
...
Filedownload(String urlString, File output)
Download a file from a url to the local file system
return download(urlString, output, false);
voiddownload(URL source, File destination)
Downloads the file which is avaiable under the given source URL to the given destination File .
InputStream inputStream = null;
OutputStream outputStream = null;
try {
    inputStream = source.openStream();
    outputStream = new FileOutputStream(destination);
    outputStream.flush();
    byte[] tempBuffer = new byte[4096];
    int counter;
...
voiddownload(URL sourceUrl, File destinationFile)
This method given a URL sourceURL and file path destinationFile writes the contents of the URL to file.
writeUrlToFile(sourceUrl, destinationFile);
byte[]download(URL url)
download
return download(url.toString(), 60000, 60000);
voiddownload(URL url, File destination)
download
byte[] buffer = new byte[4096];
int read, total = 0;
URLConnection conn = url.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
FileOutputStream out = new FileOutputStream(destination);
while ((read = is.read(buffer)) > 0) {
    out.write(buffer, 0, read);
...
voiddownload(URL url, File file)
Downloads from the given url to the file without spamming the log.
download(null, url, file);
voiddownloadAndExtract(String fileURL, String targetDirectory)
download And Extract
File file = downloadFile(fileURL, targetDirectory);
unzip(file, targetDirectory);
booleandownloadAndSaveImage(URL imageUrl, String path)
download And Save Image
try {
    InputStream in;
    in = new BufferedInputStream(imageUrl.openStream());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    byte[] buf = new byte[1024];
    int n = 0;
    while (-1 != (n = in.read(buf))) {
        out.write(buf, 0, n);
...
voiddownloadAndUnzip(String url, File location)
download And Unzip
InputStream in = null;
FileOutputStream out = null;
File archive = null;
try {
    new File(location.getCanonicalPath()).mkdirs();
    String archivePath = location.getCanonicalPath() + ARCHIVE_DOWNLOAD_NAME;
    archive = new File(archivePath);
    URL website = new URL((String) url);
...