SPT Core API

com.sptci.echo2
Class FileDownloadProvider

java.lang.Object
  extended by com.sptci.echo2.FileDownloadProvider
All Implemented Interfaces:
nextapp.echo2.app.filetransfer.DownloadProvider

public class FileDownloadProvider
extends Object
implements nextapp.echo2.app.filetransfer.DownloadProvider

A download provider for streaming contents of a file to the client browser.

The following shows sample usage of this class:

   import nextapp.echo2.app.filetransfer.Download;
   import com.sptci.echo2.FileDownloadProvider;

     ...
     File file = new File( "/tmp/test.java" );
     FileDownloadProvider provider =
         new FileDownloadProvider( file, "application/x-download" );
     Download download = new Download();
     download.setProvider( provider );
     download.setActive( true );
     Application.getActive().enqueueCommand( download );
 

Copyright 2006 Sans Pareil Technologies, Inc.

Version:
$Id: FileDownloadProvider.java 4553 2008-12-24 10:34:16Z rakesh $
Author:
Rakesh Vidyadharan 2006-02-17

Constructor Summary
FileDownloadProvider(File file, String contentType)
          Create a new instance of the provider for the specified file.
FileDownloadProvider(String file, String contentType)
          Create a new instance of the provider for the specified file.
 
Method Summary
 boolean fileExists()
          Return true if the file points to a valid file.
 String getContentDisposition()
          Returns the content-disposition for the file.
 String getContentType()
          Returns the content type of the file.
 String getFileName()
          Returns the file's name.
 String getPath()
          Returns the file's fully qualified path.
 int getSize()
          Returns the size of the file.
 void writeFile(OutputStream out)
          Writes the file to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDownloadProvider

public FileDownloadProvider(String file,
                            String contentType)
Create a new instance of the provider for the specified file.

Parameters:
file - The file to use.
contentType - The contentType to use.

FileDownloadProvider

public FileDownloadProvider(File file,
                            String contentType)
Create a new instance of the provider for the specified file.

Parameters:
file - The file to use.
contentType - The contentType to use.
Method Detail

getContentType

public String getContentType()
Returns the content type of the file.

Specified by:
getContentType in interface nextapp.echo2.app.filetransfer.DownloadProvider
Returns:
The content type of the file.

getContentDisposition

public String getContentDisposition()
Returns the content-disposition for the file. Mandatory method introduced in patched version of file transfer library. Sets to inline to force browser to display if possible.

Specified by:
getContentDisposition in interface nextapp.echo2.app.filetransfer.DownloadProvider
Returns:
The content disposition of the file.

getFileName

public String getFileName()
Returns the file's name. Returning null is allowed.

Specified by:
getFileName in interface nextapp.echo2.app.filetransfer.DownloadProvider
Returns:
The file's name.

getPath

public String getPath()
Returns the file's fully qualified path. Returning null is allowed.

Returns:
The file's fully qualified path.

getSize

public int getSize()
Returns the size of the file. If the size is unknown, -1 may be returned.

Specified by:
getSize in interface nextapp.echo2.app.filetransfer.DownloadProvider
Returns:
The size of the file.

fileExists

public boolean fileExists()
Return true if the file points to a valid file.

Returns:
boolean Return true if the file exists.

writeFile

public void writeFile(OutputStream out)
               throws IOException
Writes the file to the specified output stream.

Specified by:
writeFile in interface nextapp.echo2.app.filetransfer.DownloadProvider
Parameters:
out - The output stream to which the file should be written.
Throws:
IOException - If the provider is unable to perform this operation.

SPT Core API