com.croftsoft.core.net
Class Downloader

java.lang.Object
  extended by com.croftsoft.core.net.Downloader

public final class Downloader
extends Object

Downloads the content of a URL to a local File.

Since:
1998-11-30
Version:
2003-11-06
Author:
David Wallace Croft

Method Summary
static void download(InputStream unbufferedInputStream, File destinationFile)
           
static void download(String urlString, String filename)
           
static void download(String urlPrefix, String filenamePrefix, int start, int stop)
          Downloads a sequence of files ending in a number.
static void download(URL url, File dest)
          Downloads the content at a URL to a local destination File.
static InputStream downloadResource(URL codebaseURL, String name)
          Returns null if the codebaseURL is null.
static boolean downloadResourceToDir(URL codebaseURL, String name, File destDir)
           
static boolean isValid(String sourceURLName, String localFilename, boolean compareContentLength, boolean compareLastModified)
          Determines if the local file is valid.
static boolean isValid(URL sourceURL, File localFile, boolean compareContentLength, boolean compareLastModified)
          Determines if the local file is valid.
static void main(String[] args)
          Downloads files.
static String replaceSeparators(String localPath)
          Replaces every instance of File.separator with a forward slash character.
static String replaceSpaces(String remoteFilename)
          Replaces every instance of space (" ") with the x-www-form-urlencoded equivalent ("%20").
static boolean validate(String sourceURLName, String localFilename, boolean checkContentLength, boolean checkLastModified)
          Downloads a file if the local copy is missing or outdated.
static boolean validate(URL sourceURL, File localFile, boolean checkContentLength, boolean checkLastModified)
          Downloads a file if the local copy is missing or outdated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)
                 throws Exception
Downloads files.
 if ( args.length < 4 )
 {
   validate ( args [ 0 ], args [ 1 ], true, true );
 }
 else
 {
   download ( args [ 0 ], args [ 1 ],
     Integer.parseInt ( args [ 2 ] ),
     Integer.parseInt ( args [ 3 ] ) );
 }
 

Throws:
Exception

download

public static void download(String urlPrefix,
                            String filenamePrefix,
                            int start,
                            int stop)
                     throws IOException
Downloads a sequence of files ending in a number.

Throws:
IOException

download

public static void download(String urlString,
                            String filename)
                     throws IOException,
                            MalformedURLException
Throws:
IOException
MalformedURLException

download

public static void download(URL url,
                            File dest)
                     throws IOException
Downloads the content at a URL to a local destination File.

Throws:
IOException

download

public static void download(InputStream unbufferedInputStream,
                            File destinationFile)
                     throws IOException
Throws:
IOException

downloadResourceToDir

public static boolean downloadResourceToDir(URL codebaseURL,
                                            String name,
                                            File destDir)

downloadResource

public static InputStream downloadResource(URL codebaseURL,
                                           String name)
Returns null if the codebaseURL is null. Returns null upon failure.


isValid

public static boolean isValid(URL sourceURL,
                              File localFile,
                              boolean compareContentLength,
                              boolean compareLastModified)
                       throws IOException,
                              ProtocolException
Determines if the local file is valid.

If both compareContentLength and compareLastModified are false, this methods simply checks for the existence of the local file.

Throws:
IOException
ProtocolException

isValid

public static boolean isValid(String sourceURLName,
                              String localFilename,
                              boolean compareContentLength,
                              boolean compareLastModified)
                       throws IOException,
                              ProtocolException
Determines if the local file is valid.

If both compareContentLength and compareLastModified are false, this methods simply checks for the existence of the local file.

Parameters:
sourceURLName - An HTTP URL.
Throws:
IOException
ProtocolException

replaceSeparators

public static String replaceSeparators(String localPath)
Replaces every instance of File.separator with a forward slash character. This is used for converting a local path name to a URL path name.


replaceSpaces

public static String replaceSpaces(String remoteFilename)
Replaces every instance of space (" ") with the x-www-form-urlencoded equivalent ("%20"). This is used for converting a remote filename with spaces so that it can be downloaded via a HTTP request.


validate

public static boolean validate(String sourceURLName,
                               String localFilename,
                               boolean checkContentLength,
                               boolean checkLastModified)
                        throws IOException,
                               MalformedURLException
Downloads a file if the local copy is missing or outdated.

Returns:
True if a new copy needed to be downloaded.
Throws:
IOException
MalformedURLException

validate

public static boolean validate(URL sourceURL,
                               File localFile,
                               boolean checkContentLength,
                               boolean checkLastModified)
                        throws IOException
Downloads a file if the local copy is missing or outdated.

Returns:
True if a new copy needed to be downloaded.
Throws:
IOException

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)