org.apache.commons.pipeline.stage
Class HttpFileDownloadStage

java.lang.Object
  extended by org.apache.commons.pipeline.stage.BaseStage
      extended by org.apache.commons.pipeline.stage.HttpFileDownloadStage
All Implemented Interfaces:
Stage

public class HttpFileDownloadStage
extends BaseStage

This Stage provides the functionality needed to retrieve data from an HTTP URL. Multipart responses are not yet supported.


Field Summary
 
Fields inherited from class org.apache.commons.pipeline.stage.BaseStage
context
 
Constructor Summary
HttpFileDownloadStage()
           
HttpFileDownloadStage(String workDir)
          Creates a new HttpFileDownloadStage which will download files to the specified work directory.
 
Method Summary
 String getWorkDir()
          Returns the name of the file download directory.
 URL handleRedirects(URL url)
          Follows redirects from the specified URL and recursively returns the destination URL.
 void process(Object obj)
          Removes a java.net.URL (an HTTP URL) or string representing a URL from the input queue, and then retrieves the data at that URL and stores it in a temporary file.
 void setWorkDir(String workDir)
          Sets the working directory for the file download.
 
Methods inherited from class org.apache.commons.pipeline.stage.BaseStage
emit, emit, init, postprocess, preprocess, release
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpFileDownloadStage

public HttpFileDownloadStage()

HttpFileDownloadStage

public HttpFileDownloadStage(String workDir)
Creates a new HttpFileDownloadStage which will download files to the specified work directory.

Parameters:
workDir - the path to which files will be downloaded.
Method Detail

process

public void process(Object obj)
             throws StageException
Removes a java.net.URL (an HTTP URL) or string representing a URL from the input queue, and then retrieves the data at that URL and stores it in a temporary file. The file is stored in the directory specified by setWorkDir(), or to the system default temporary directory if no work directory is set.

Specified by:
process in interface Stage
Overrides:
process in class BaseStage
Parameters:
obj - The URL from which to download data.
Throws:
IllegalArgumentException - if the parameter obj is not a string or an instance of URL.
StageException - if there is an error retrieving data from the URL specified.

setWorkDir

public void setWorkDir(String workDir)
Sets the working directory for the file download. If the directory does not already exist, it will be created during the preprocess() step. If you do not set this directory, the work directory will be the default temporary directory for your machine type.


getWorkDir

public String getWorkDir()
Returns the name of the file download directory.


handleRedirects

public URL handleRedirects(URL url)
                    throws IOException,
                           MalformedURLException
Follows redirects from the specified URL and recursively returns the destination URL. This method does not check for circular redirects, so it is possible that a malicious site could force this method into infinite recursion. TODO: Add a max_hops parameterized version

Throws:
IOException
MalformedURLException


Copyright © 2004-2009 The Apache Software Foundation. All Rights Reserved.