de.opus5.servlet
Class HttpMultipartRequest

java.lang.Object
  |
  +--de.opus5.servlet.HttpMultipartRequest

public class HttpMultipartRequest
extends java.lang.Object
implements javax.servlet.http.HttpServletRequest

A class for handling multipart form uploads. Unlike com.oreilly.servlet.MultipartRequest this class returns a InputStream for reading the file's content, so you can also write the data into magic crystals instead of writing it to the file system. ;) There is also the option to save files to disk and return a java.io.File object. You can also access the file data via the getUploadedFile() method, which returns an file object implementing the de.opus5.servlet.UploadedFile interface. The class can decide based on the total request size if the file data is temporary stored in memory or in the file system.

Example:

 MulipartRequest req;
 ..
 try {
    req = new MultipartRequest(servletRequest,maxMemoryStoredRequestSize,
			tmpdir,fileprefix);
 } catch (Exception e) {
   ...
 }

 ....
 filename = req.getUploadedFile("Document").getName();
 is = req.getInputStreamForFile("Document");
 while (is.read()...) {
 ...
 }
 login = req.getParameter("Login");
 ...
 UploadedFile adressFile = mReq.getUploadedFile(Global.MPADRESSF_KEY);
 UploadedFile docFile = mReq.getUploadedFile(Global.MPDOCFILE_KEY);
 myObject.setAdressFile(adressFile); 
 ....
 ....
 


Inner Class Summary
 class HttpMultipartRequest.BucketHash
          Simple class for storing parameters
 
Constructor Summary
HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR, int maxMemStoredReqSiz, int maxReqSiz, java.lang.String tmpDir, java.lang.String uniquePrefix)
          Create a MultipartRequest, temporary files will be deleted.
HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR, int maxMemStoredReqSiz, java.lang.String tmpDir, java.lang.String uniquePrefix)
          Create a MultipartRequest, temporary files will be deleted, the maximum request size is set to 1MB.
HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR, int maxReqSiz, java.lang.String tmpDir, java.lang.String uniquePrefix, boolean keep)
          Create a MultipartRequest, files will be saved to disk allways.
HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR, java.lang.String tmpDir, java.lang.String uniquePrefix)
          Create a MultipartRequest using the ServletRequest object, temporary files will be deleted.
 
Method Summary
 void copyFile(java.lang.String fieldname, java.lang.String filename)
          Copies an uploaded file into the specified file.
 java.lang.Object getAttribute(java.lang.String name)
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getAuthType()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getCharacterEncoding()
          Calls the corresponding method in ServletRequest-object.
 int getContentLength()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getContentType()
          Calls the corresponding method in ServletRequest-object.
 javax.servlet.http.Cookie[] getCookies()
          Calls the corresponding method in ServletRequest-object.
 long getDateHeader(java.lang.String name)
          Calls the corresponding method in ServletRequest-object.
 java.io.File getFile(java.lang.String fieldname)
          returns a java.io.File object if the file was saved on disk, null otherwise.
 java.lang.String getHeader(java.lang.String name)
          Calls the corresponding method in ServletRequest-object.
 java.util.Enumeration getHeaderNames()
          Calls the corresponding method in ServletRequest-object.
 javax.servlet.ServletInputStream getInputStream()
          Calls the corresponding method in ServletRequest-object.
 java.io.InputStream getInputStreamForFile(java.lang.String fieldname)
          return an InputStream for reading an uploaded file.
 int getIntHeader(java.lang.String name)
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getMethod()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getParameter(java.lang.String name)
          return the value of parameter with specified name
 java.util.Enumeration getParameterNames()
          return the names of all parameters as Enumeration
 java.lang.String[] getParameterValues(java.lang.String name)
          return the value of the specified parameter as an array of strings.
 java.lang.String getPathInfo()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getPathTranslated()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getProtocol()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getQueryString()
          Calls the corresponding method in ServletRequest-object.
 java.io.BufferedReader getReader()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getRealPath(java.lang.String path)
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getRemoteAddr()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getRemoteHost()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getRemoteUser()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getRequestedSessionId()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getRequestURI()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getScheme()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getServerName()
          Calls the corresponding method in ServletRequest-object.
 int getServerPort()
          Calls the corresponding method in ServletRequest-object.
 java.lang.String getServletPath()
          Calls the corresponding method in ServletRequest-object.
 javax.servlet.http.HttpSession getSession(boolean create)
          Calls the corresponding method in ServletRequest-object.
 UploadedFile getUploadedFile(java.lang.String fieldname)
          Get the UploadedFile object for the uploaded file with given name.
 boolean isRequestedSessionIdFromCookie()
          Calls the corresponding method in ServletRequest-object.
 boolean isRequestedSessionIdFromUrl()
          Calls the corresponding method in ServletRequest-object.
 boolean isRequestedSessionIdValid()
          Calls the corresponding method in ServletRequest-object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpMultipartRequest

public HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR,
                            int maxMemStoredReqSiz,
                            int maxReqSiz,
                            java.lang.String tmpDir,
                            java.lang.String uniquePrefix)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
Create a MultipartRequest, temporary files will be deleted.
Parameters:
sR - the ServletRequest
maxMemStoredReqSiz - If the request size in bytes exceeds this value, the uploaded files will be stored on disk.
maxReqSiz - Maximum size of request.
tmpDir - Directory where temporary files are saved.
uniquePrefix - Prefix added to the filenames to prevent overwriting of files with the same name.

HttpMultipartRequest

public HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR,
                            int maxMemStoredReqSiz,
                            java.lang.String tmpDir,
                            java.lang.String uniquePrefix)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
Create a MultipartRequest, temporary files will be deleted, the maximum request size is set to 1MB.
Parameters:
sR - the ServletRequest
maxMemStoredReqSiz - If the request size in bytes exceeds this value, the uploaded files will be stored on disk.
tmpDir - Directory where temporary files are saved.
uniquePrefix - Prefix added to the filenames to prevent overwriting of files with the same name.

HttpMultipartRequest

public HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR,
                            int maxReqSiz,
                            java.lang.String tmpDir,
                            java.lang.String uniquePrefix,
                            boolean keep)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
Create a MultipartRequest, files will be saved to disk allways.
Parameters:
sR - the ServletRequest
maxReqSiz - Maximum size of request.
tmpDir - Directory where temporary files are saved.
uniquePrefix - Prefix added to the filenames to prevent overwriting of files with the same name.
keep - If set, the uploaded files will not be deleted.

HttpMultipartRequest

public HttpMultipartRequest(javax.servlet.http.HttpServletRequest sR,
                            java.lang.String tmpDir,
                            java.lang.String uniquePrefix)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
Create a MultipartRequest using the ServletRequest object, temporary files will be deleted. Maximum request size is 1MB, files will be saved to disk.
Parameters:
sR - the ServletRequest
tmpDir - Directory where temporary files are saved.
uniquePrefix - Prefix added to the filenames to prevent overwriting of files with the same name.
Method Detail

getFile

public java.io.File getFile(java.lang.String fieldname)
returns a java.io.File object if the file was saved on disk, null otherwise. This this method should only be called, if keepFiles is set to true.
Parameters:
fieldname - the form parameter field name
Returns:
the java.io.File object

getInputStreamForFile

public java.io.InputStream getInputStreamForFile(java.lang.String fieldname)
                                          throws java.io.IOException
return an InputStream for reading an uploaded file.
Parameters:
filename - the form parameter field name
Returns:
InputStream for reading the filedata.

copyFile

public void copyFile(java.lang.String fieldname,
                     java.lang.String filename)
              throws java.io.IOException
Copies an uploaded file into the specified file.
Parameters:
fieldname - the form parameter field name
filename - the name of the target

getParameterNames

public java.util.Enumeration getParameterNames()
return the names of all parameters as Enumeration
Returns:
Enumeration of parameter names

getParameter

public java.lang.String getParameter(java.lang.String name)
return the value of parameter with specified name
Parameters:
name - the parameter name
Returns:
the parameter value

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
return the value of the specified parameter as an array of strings.

getUploadedFile

public UploadedFile getUploadedFile(java.lang.String fieldname)
Get the UploadedFile object for the uploaded file with given name.
Parameters:
fieldname - the form parameter field name

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Calls the corresponding method in ServletRequest-object.

getContentLength

public int getContentLength()
Calls the corresponding method in ServletRequest-object.

getContentType

public java.lang.String getContentType()
Calls the corresponding method in ServletRequest-object.

getProtocol

public java.lang.String getProtocol()
Calls the corresponding method in ServletRequest-object.

getScheme

public java.lang.String getScheme()
Calls the corresponding method in ServletRequest-object.

getServerName

public java.lang.String getServerName()
Calls the corresponding method in ServletRequest-object.

getServerPort

public int getServerPort()
Calls the corresponding method in ServletRequest-object.

getRemoteAddr

public java.lang.String getRemoteAddr()
Calls the corresponding method in ServletRequest-object.

getRemoteHost

public java.lang.String getRemoteHost()
Calls the corresponding method in ServletRequest-object.

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Calls the corresponding method in ServletRequest-object.

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws java.io.IOException
Calls the corresponding method in ServletRequest-object.

getReader

public java.io.BufferedReader getReader()
                                 throws java.io.IOException
Calls the corresponding method in ServletRequest-object.

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Calls the corresponding method in ServletRequest-object.

getCookies

public javax.servlet.http.Cookie[] getCookies()
Calls the corresponding method in ServletRequest-object.
Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getMethod

public java.lang.String getMethod()
Calls the corresponding method in ServletRequest-object.
Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getRequestURI

public java.lang.String getRequestURI()
Calls the corresponding method in ServletRequest-object.
Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getServletPath

public java.lang.String getServletPath()
Calls the corresponding method in ServletRequest-object.
Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getPathInfo

public java.lang.String getPathInfo()
Calls the corresponding method in ServletRequest-object.
Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getQueryString

public java.lang.String getQueryString()
Calls the corresponding method in ServletRequest-object.
Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public java.lang.String getPathTranslated()
Calls the corresponding method in ServletRequest-object.
Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public java.lang.String getRemoteUser()
Calls the corresponding method in ServletRequest-object.
Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getAuthType

public java.lang.String getAuthType()
Calls the corresponding method in ServletRequest-object.
Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getHeader

public java.lang.String getHeader(java.lang.String name)
Calls the corresponding method in ServletRequest-object.
Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(java.lang.String name)
Calls the corresponding method in ServletRequest-object.
Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(java.lang.String name)
Calls the corresponding method in ServletRequest-object.
Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest

getHeaderNames

public java.util.Enumeration getHeaderNames()
Calls the corresponding method in ServletRequest-object.
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Calls the corresponding method in ServletRequest-object.
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Calls the corresponding method in ServletRequest-object.
Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Calls the corresponding method in ServletRequest-object.
Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Calls the corresponding method in ServletRequest-object.
Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Calls the corresponding method in ServletRequest-object.
Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest