com.sun.slamd.misc
Class GetFile

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended bycom.sun.slamd.misc.GetFile
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class GetFile
extends javax.servlet.http.HttpServlet

This class defines a servlet that makes it possible for a client to request a file from the Web server, and have the Web server distribute a different file for each request. The individual files to distribute should exist in a specified location on the filesystem and should be named with the same base name followed by a period and a sequentially-incrmenting number starting at 1. For example, if a request for the file "myfile" should return one of five files, then the files to be retrieved should be named "myfile.1", "myfile.2", "myfile.3", "myfile.4", and "myfile.5".

See Also:
Serialized Form

Field Summary
static java.lang.String ACCESS_MODE_RANDOM
          The access mode that indicates that the files should be retrieved in random order.
static java.lang.String ACCESS_MODE_REMOVE
          The access mode that indicates that information about the specified file should be removed from the file data cache.
static java.lang.String ACCESS_MODE_SEQUENTIAL
          The access mode that indicates that the files should be retrieved in sequential order.
static java.lang.String SERVLET_INIT_PARAM_FILE_DIRECTORY
          The name of the servlet initialization parameter that specifies the directory in which to look for the requested files.
static java.lang.String SERVLET_PARAM_ACCESS_MODE
          The name of the servlet parameter that specifies the access mode that should be used when retrieving the files.
static java.lang.String SERVLET_PARAM_FILENAME
          The name of the servlet parameter that specifies the file to retrieve.
 
Constructor Summary
GetFile()
           
 
Method Summary
 GetFileCacheItem createCacheItem(java.lang.String filename)
          Creates a cache item with information about the specified file.
 void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Processes the servlet request and returns the appropriate file.
 void init()
          Performs the necessary initialization for this servlet.
 void sendFile(javax.servlet.http.HttpServletResponse response, java.lang.String fileToRetrieve)
          Sends the contents of the specified file back to the client.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVLET_INIT_PARAM_FILE_DIRECTORY

public static final java.lang.String SERVLET_INIT_PARAM_FILE_DIRECTORY
The name of the servlet initialization parameter that specifies the directory in which to look for the requested files.

See Also:
Constant Field Values

SERVLET_PARAM_FILENAME

public static final java.lang.String SERVLET_PARAM_FILENAME
The name of the servlet parameter that specifies the file to retrieve.

See Also:
Constant Field Values

SERVLET_PARAM_ACCESS_MODE

public static final java.lang.String SERVLET_PARAM_ACCESS_MODE
The name of the servlet parameter that specifies the access mode that should be used when retrieving the files.

See Also:
Constant Field Values

ACCESS_MODE_SEQUENTIAL

public static final java.lang.String ACCESS_MODE_SEQUENTIAL
The access mode that indicates that the files should be retrieved in sequential order.

See Also:
Constant Field Values

ACCESS_MODE_RANDOM

public static final java.lang.String ACCESS_MODE_RANDOM
The access mode that indicates that the files should be retrieved in random order.

See Also:
Constant Field Values

ACCESS_MODE_REMOVE

public static final java.lang.String ACCESS_MODE_REMOVE
The access mode that indicates that information about the specified file should be removed from the file data cache.

See Also:
Constant Field Values
Constructor Detail

GetFile

public GetFile()
Method Detail

init

public void init()
Performs the necessary initialization for this servlet.


doGet

public void doGet(javax.servlet.http.HttpServletRequest request,
                  javax.servlet.http.HttpServletResponse response)
           throws java.io.IOException
Processes the servlet request and returns the appropriate file.

Parameters:
request - Information about the request received from the client.
response - Information about the response to send back to the client.
Throws:
java.io.IOException - If a problem occurs while sending the response back to the client.

createCacheItem

public GetFileCacheItem createCacheItem(java.lang.String filename)
Creates a cache item with information about the specified file. If the file does not exist, then it will return null.

Parameters:
filename - The name of the file to be cached.
Returns:
The cache item with information about the specified file, or null if the file does not exist.

sendFile

public void sendFile(javax.servlet.http.HttpServletResponse response,
                     java.lang.String fileToRetrieve)
              throws java.io.IOException
Sends the contents of the specified file back to the client.

Parameters:
response - The response object to use to send the data back to the client.
fileToRetrieve - The name of the actual file to retrieve.
Throws:
java.io.IOException - If a problem occurs while trying to send the file data to the client.