de.aitools.aq.webdownload
Class Downloader

java.lang.Object
  extended by de.aitools.aq.webdownload.Downloader
Direct Known Subclasses:
WgetDownloader

public abstract class Downloader
extends java.lang.Object

Downloader is the abstract base class for all Downloaders.

Author:
christof.braeutigam@uni-weimar.de

Method Summary
 java.lang.String getContentType(java.lang.String url)
          Returns the data of the Content-Type HTTP response header field for the given url or null if no such field exists.
 java.lang.String getContentType(java.net.URL url)
          Returns the data of the Content-Type HTTP response header field for the given url or null if no such field exists.
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders(java.lang.String url)
          Convenience method to detect the content type of the resource designated by url.
 int getReadTimeout()
           
 java.lang.String getTempFilePrefix()
           
 java.lang.String getTempFileSuffix()
           
abstract  java.io.File load(java.lang.String url)
          Loads the data designated by url and creates and returns a file object which can be used to access the data.
abstract  java.io.File load(java.lang.String url, java.io.File dir)
          Loads the data designated by url to the directory designated by dir.
abstract  java.io.File load(java.net.URL url)
          Loads the data designated by url and creates and returns a file object which can be used to access the data.
abstract  java.io.File load(java.net.URL url, java.io.File dir)
          Loads the data designated by url to the directory designated by dir.
 int setConnectionTimeout()
           
 void setConnectionTimeout(int seconds)
           
 void setReadTimeout(int seconds)
           
 void setTempFilePrefix(java.lang.String tempFilePrefix)
           
 void setTempFileSuffix(java.lang.String tempFileSuffix)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

load

public abstract java.io.File load(java.lang.String url)
                           throws DownloaderException
Loads the data designated by url and creates and returns a file object which can be used to access the data.

Parameters:
url - The resource to download
Returns:
A File to access the downloaded data
Throws:
DownloaderException

load

public abstract java.io.File load(java.net.URL url)
                           throws DownloaderException
Loads the data designated by url and creates and returns a file object which can be used to access the data.

Parameters:
url - The resource to download
Returns:
A File to access the downloaded data
Throws:
DownloaderException

load

public abstract java.io.File load(java.lang.String url,
                                  java.io.File dir)
                           throws DownloaderException
Loads the data designated by url to the directory designated by dir. A file is created in dir and will be returned to provide access to the downloaded data.

Note that the provided dir must denote a directory and this directory must be writable.

Parameters:
url - The resource to download
dir - The directory where the downloaded data should be stored
Returns:
A File to access the downloaded data
Throws:
DownloaderException

load

public abstract java.io.File load(java.net.URL url,
                                  java.io.File dir)
                           throws DownloaderException
Loads the data designated by url to the directory designated by dir. A file is created in dir and will be returned to provide access to the downloaded data.

Note that the provided dir must denote a directory and this directory must be writable.

Parameters:
url - The resource to download
dir - The directory where the downloaded data should be stored
Returns:
A File to access the downloaded data
Throws:
DownloaderException

setConnectionTimeout

public void setConnectionTimeout(int seconds)

setConnectionTimeout

public int setConnectionTimeout()

setReadTimeout

public void setReadTimeout(int seconds)

getReadTimeout

public int getReadTimeout()

setTempFilePrefix

public void setTempFilePrefix(java.lang.String tempFilePrefix)

getTempFilePrefix

public java.lang.String getTempFilePrefix()

setTempFileSuffix

public void setTempFileSuffix(java.lang.String tempFileSuffix)

getTempFileSuffix

public java.lang.String getTempFileSuffix()

getHeaders

public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaders(java.lang.String url)
                                                                            throws DownloaderException
Convenience method to detect the content type of the resource designated by url. In fact this just opens an URLConnection and returns the output of getContentType().

Note that this method will return null in several cases, e.g.:

Parameters:
url - The resource whose content type should be detected
Returns:
A String containing the content type (most likely in the form of a mime-type or null if no content type information is available.
Throws:
DownloaderException

getContentType

public java.lang.String getContentType(java.lang.String url)
                                throws DownloaderException
Returns the data of the Content-Type HTTP response header field for the given url or null if no such field exists. Note that this method doesn't follows HTTP 30X redirects.

Parameters:
url - The url for which the content type should be returned.
Returns:
The content type as it is retrieved from the HTTP response header
Throws:
DownloaderException

getContentType

public java.lang.String getContentType(java.net.URL url)
                                throws DownloaderException
Returns the data of the Content-Type HTTP response header field for the given url or null if no such field exists. Note that this method doesn't follows HTTP 30X redirects.

Parameters:
url - The url for which the content type should be returned.
Returns:
The content type as it is retrieved from the HTTP response header
Throws:
DownloaderException