org.jtools.fileup
Class MultipartRequest

java.lang.Object
  extended byorg.jtools.fileup.MultipartRequest

public class MultipartRequest
extends java.lang.Object

 MultipartRequest Class
 

Version:
$Id: MultipartRequest.java,v 1.2 2002/08/08 18:25:48 stfndln Exp $
Author:
yummud

Constructor Summary
MultipartRequest(javax.servlet.http.HttpServletRequest request, java.lang.String saveDirectory)
           
MultipartRequest(javax.servlet.http.HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize)
           
MultipartRequest(javax.servlet.http.HttpServletRequest request, java.lang.String saveDirectory, int maxPostSize, java.lang.String filename)
           
MultipartRequest(javax.servlet.http.HttpServletRequest request, java.lang.String saveDirectory, java.lang.String filename)
           
MultipartRequest(javax.servlet.ServletRequest request, java.lang.String saveDirectory)
           
MultipartRequest(javax.servlet.ServletRequest request, java.lang.String saveDirectory, int maxPostSize)
           
MultipartRequest(javax.servlet.ServletRequest request, java.lang.String saveDirectory, int maxPostSize, java.lang.String filename)
           
MultipartRequest(javax.servlet.ServletRequest request, java.lang.String saveDirectory, java.lang.String filename)
           
 
Method Summary
 java.lang.String getContentType(java.lang.String name)
          Returns the content type of the specified file (as supplied by the client browser), or null if the file was not included in the upload.
 java.io.File getFile(java.lang.String name)
          Returns a File object for the specified file saved on the server's filesystem, or null if the file was not included in the upload.
 java.util.Enumeration getFileNames()
          Returns the names of all the uploaded files as an Enumeration of Strings.
 java.lang.String getFilesystemName(java.lang.String name)
          Returns the filesystem name of the specified file, or null if the file was not included in the upload.
 java.lang.String getParameter(java.lang.String name)
          Returns the value of the named parameter as a String, or null if the parameter was not sent or was sent without a value.
 java.util.Enumeration getParameterNames()
          Returns the names of all the parameters as an Enumeration of Strings.
 java.lang.String[] getParameterValues(java.lang.String name)
          Returns the values of the named parameter as a String array, or null if the parameter was not sent.
protected  void readAndSaveFile(org.jtools.fileup.MultipartInputStreamHandler in, java.lang.String boundary, java.lang.String filename, java.lang.String contentType)
          A utility method that reads a single part of the multipart request that represents a file, and saves the file to the given directory.
protected  boolean readNextPart(org.jtools.fileup.MultipartInputStreamHandler in, java.lang.String boundary)
          A utility method that reads an individual part.
protected  boolean readNextPart(org.jtools.fileup.MultipartInputStreamHandler in, java.lang.String boundary, java.lang.String newFilename)
           
protected  java.lang.String readParameter(org.jtools.fileup.MultipartInputStreamHandler in, java.lang.String boundary)
          A utility method that reads a single part of the multipart request that represents a parameter.
protected  void readRequest()
          The workhorse method that actually parses the request.
protected  void readRequest(java.lang.String filename)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultipartRequest

public MultipartRequest(javax.servlet.http.HttpServletRequest request,
                        java.lang.String saveDirectory)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.http.HttpServletRequest request,
                        java.lang.String saveDirectory,
                        int maxPostSize)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.http.HttpServletRequest request,
                        java.lang.String saveDirectory,
                        java.lang.String filename)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.http.HttpServletRequest request,
                        java.lang.String saveDirectory,
                        int maxPostSize,
                        java.lang.String filename)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.ServletRequest request,
                        java.lang.String saveDirectory)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.ServletRequest request,
                        java.lang.String saveDirectory,
                        java.lang.String filename)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.ServletRequest request,
                        java.lang.String saveDirectory,
                        int maxPostSize)
                 throws java.io.IOException

MultipartRequest

public MultipartRequest(javax.servlet.ServletRequest request,
                        java.lang.String saveDirectory,
                        int maxPostSize,
                        java.lang.String filename)
                 throws java.io.IOException
Method Detail

getParameterNames

public java.util.Enumeration getParameterNames()
Returns the names of all the parameters as an Enumeration of Strings. It returns an empty Enumeration if there are no parameters.

Returns:
the names of all the parameters as an Enumeration of Strings

getFileNames

public java.util.Enumeration getFileNames()
Returns the names of all the uploaded files as an Enumeration of Strings. It returns an empty Enumeration if there are no uploaded files. Each file name is the name specified by the form, not by the user.

Returns:
the names of all the uploaded files as an Enumeration of Strings

getParameter

public java.lang.String getParameter(java.lang.String name)
Returns the value of the named parameter as a String, or null if the parameter was not sent or was sent without a value. The value is guaranteed to be in its normal, decoded form. If the parameter has multiple values, only the last one is returned (for backward compatibility). For parameters with multiple values, it's possible the last "value" may be null.

Parameters:
name - the parameter name
Returns:
the parameter value

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Returns the values of the named parameter as a String array, or null if the parameter was not sent. The array has one entry for each parameter field sent. If any field was sent without a value that entry is stored in the array as a null. The values are guaranteed to be in their normal, decoded form. A single value is returned as a one-element array.

Parameters:
name - the parameter name
Returns:
the parameter values

getFilesystemName

public java.lang.String getFilesystemName(java.lang.String name)
Returns the filesystem name of the specified file, or null if the file was not included in the upload. A filesystem name is the name specified by the user. It is also the name under which the file is actually saved.

Parameters:
name - the file name
Returns:
the filesystem name of the file

getContentType

public java.lang.String getContentType(java.lang.String name)
Returns the content type of the specified file (as supplied by the client browser), or null if the file was not included in the upload.

Parameters:
name - the file name
Returns:
the content type of the file

getFile

public java.io.File getFile(java.lang.String name)
Returns a File object for the specified file saved on the server's filesystem, or null if the file was not included in the upload.

Parameters:
name - the file name
Returns:
a File object for the named file

readRequest

protected void readRequest()
                    throws java.io.IOException
The workhorse method that actually parses the request. A subclass can override this method for a better optimized or differently behaved implementation.

Throws:
java.io.IOException - if the uploaded content is larger than maxSize or there's a problem parsing the request

readRequest

protected void readRequest(java.lang.String filename)
                    throws java.io.IOException
Throws:
java.io.IOException

readNextPart

protected boolean readNextPart(org.jtools.fileup.MultipartInputStreamHandler in,
                               java.lang.String boundary)
                        throws java.io.IOException
A utility method that reads an individual part. Dispatches to readParameter() and readAndSaveFile() to do the actual work. A subclass can override this method for a better optimized or differently behaved implementation.

Parameters:
in - the stream from which to read the part
boundary - the boundary separating parts
Returns:
a flag indicating whether this is the last part
Throws:
java.io.IOException - if there's a problem reading or parsing the request
See Also:
readParameter, readAndSaveFile

readNextPart

protected boolean readNextPart(org.jtools.fileup.MultipartInputStreamHandler in,
                               java.lang.String boundary,
                               java.lang.String newFilename)
                        throws java.io.IOException
Throws:
java.io.IOException

readParameter

protected java.lang.String readParameter(org.jtools.fileup.MultipartInputStreamHandler in,
                                         java.lang.String boundary)
                                  throws java.io.IOException
A utility method that reads a single part of the multipart request that represents a parameter. A subclass can override this method for a better optimized or differently behaved implementation.

Parameters:
in - the stream from which to read the parameter information
boundary - the boundary signifying the end of this part
Returns:
the parameter value
Throws:
java.io.IOException - if there's a problem reading or parsing the request

readAndSaveFile

protected void readAndSaveFile(org.jtools.fileup.MultipartInputStreamHandler in,
                               java.lang.String boundary,
                               java.lang.String filename,
                               java.lang.String contentType)
                        throws java.io.IOException
A utility method that reads a single part of the multipart request that represents a file, and saves the file to the given directory. A subclass can override this method for a better optimized or differently behaved implementation.

Parameters:
in - the stream from which to read the file
boundary - the boundary signifying the end of this part
filename - the name under which to save the uploaded file
Throws:
java.io.IOException - if there's a problem reading or parsing the request