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

voiddownloadFile(String urlString, String filename)
Download the url page content and save it to local file
URL url = new URL(urlString);
URLConnection con = url.openConnection();
con.setRequestProperty("User-Agent",
        "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0");
InputStream is = con.getInputStream();
byte[] bs = new byte[1024];
int len;
OutputStream os = new FileOutputStream(filename);
...
voiddownloadFile(String urlToDownload, File locationToStore)
download File
try {
    URL url = new URL(urlToDownload);
    BufferedInputStream bufferedInputStream = new BufferedInputStream(url.openStream());
    FileOutputStream fileOutputStream = new FileOutputStream(locationToStore);
    byte[] buffer = new byte[1024];
    int count = 0;
    while ((count = bufferedInputStream.read(buffer, 0, 1024)) != -1) {
        fileOutputStream.write(buffer, 0, count);
...
voiddownloadFile(URL fileUrl, File out)
download File
try {
    PrintStream outStream = new PrintStream(out);
    Scanner connectionScanner = new Scanner(fileUrl.openStream());
    while (connectionScanner.hasNextByte()) {
        outStream.println(connectionScanner.nextByte());
} catch (IOException e) {
    e.printStackTrace();
...
voiddownloadFile(URL theURL, String filePath)
download File
URLConnection con = theURL.openConnection();
String urlPath = con.getURL().getFile();
String fileFullName = urlPath.substring(urlPath.lastIndexOf("/") + 1);
if (fileFullName != null) {
    byte[] buffer = new byte[4 * 1024];
    int read;
    String path = filePath + "/" + fileFullName;
    File fileFolder = new File(filePath);
...
voiddownloadFile(URL url, File toFile)
Downloads a remote file given by an URL to the given local file
OutputStream out = null;
URLConnection conn = null;
InputStream in = null;
out = new BufferedOutputStream(new FileOutputStream(toFile));
conn = url.openConnection();
conn.setUseCaches(false);
in = conn.getInputStream();
byte[] buffer = new byte[1024];
...
FiledownloadFile(URL url, String name)
Downloads an URL into a temporary file that is removed the next time the tempFileManager class is called, which means the next time gvSIG is launched.
File f = null;
try {
    if ((f = getPreviousDownloadedURL(url)) == null) {
        File tempDirectory = new File(TEMPDIRECTORYPATH);
        if (!tempDirectory.exists())
            tempDirectory.mkdir();
        f = new File(TEMPDIRECTORYPATH + "/" + name + System.currentTimeMillis());
        System.out.println("downloading '" + url.toString() + "' to: " + f.getAbsolutePath());
...
booleandownloadFile(URL url, String path, String fileName)
download File
int byteread = 0;
boolean result = false;
try {
    URLConnection conn = url.openConnection();
    InputStream inStream = conn.getInputStream();
    FileOutputStream fs = new FileOutputStream(
            new StringBuilder(path).append("/").append(fileName).toString());
    byte[] buffer = new byte[1204];
...
voiddownloadFileAndRetry(final File file, final URL url, final int retry)
download File And Retry
final FileOutputStream fos = new FileOutputStream(file);
try {
    final byte[] buffer = new byte[8192];
    final InputStream stream = new BufferedInputStream(url.openConnection().getInputStream());
    try {
        int len;
        while ((len = stream.read(buffer)) != -1) {
            fos.write(buffer, 0, len);
...
FiledownloadFileFromInternet(String remoteUrl)
download File From Internet
BufferedInputStream inputStream = null;
BufferedOutputStream outputStream = null;
try {
    URL url = new URL(remoteUrl);
    File tempFile = File.createTempFile("temp", "zip");
    inputStream = new BufferedInputStream(url.openStream());
    outputStream = new BufferedOutputStream(new FileOutputStream(tempFile));
    int read = 0;
...
longdownloadFileFromUrl(String urlPath, File file)
download File From Url
long size = 0;
try {
    URL url = new URL(urlPath);
    HttpURLConnection httpurlconnection = (HttpURLConnection) url.openConnection();
    BufferedInputStream bufferedinputstream = new BufferedInputStream(httpurlconnection.getInputStream());
    BufferedOutputStream bufferedoutputstream = new BufferedOutputStream(new FileOutputStream(file));
    int i;
    while ((i = bufferedinputstream.read()) != -1) {
...