Package helma.util
Class MimePart
java.lang.Object
helma.util.MimePart
- All Implemented Interfaces:
Serializable
This represents a MIME part of a HTTP file upload
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Return the content of the mime part as byte array.int
Get the number of bytes in the mime part's contentgetETag()
Get the ETag of the mime partReturn an InputStream to read the content of the mime partGet the last modified dategetName()
Get the mime part's namestatic String
getSubHeader
(String header, String subHeaderName) Get a sub-header from a header, e.g.getText()
Return the content of the mime part as string, if its content type is null, text/* or application/text.static String
normalizeFilename
(String filename) Normalize a upload file name.void
Set the ETag for the mime partvoid
setLastModified
(Date lastModified) Set the last modified datewriteToFile
(String dir) Write the mimepart to a directory, using its name as file name.writeToFile
(String dir, String fname) Write the mimepart to a file.
-
Constructor Details
-
MimePart
Creates a new MimePart object.- Parameters:
name
- the file namecontent
- the mime part contentcontentType
- the content type
-
MimePart
public MimePart(org.apache.commons.fileupload.FileItem fileItem) Creates a new MimePart object from a file upload.- Parameters:
fileItem
- a commons fileupload file item
-
-
Method Details
-
getContentType
- Returns:
- the content type
-
getContentLength
public int getContentLength()Get the number of bytes in the mime part's content- Returns:
- the content length
-
getName
Get the mime part's name- Returns:
- the file name
-
getContent
public byte[] getContent()Return the content of the mime part as byte array.- Returns:
- the mime part content as byte array
-
getInputStream
Return an InputStream to read the content of the mime part- Returns:
- an InputStream for the mime part content
- Throws:
IOException
- an I/O related error occurred
-
getText
Return the content of the mime part as string, if its content type is null, text/* or application/text. Otherwise, return null.- Returns:
- the content of the mime part as string
-
getLastModified
Get the last modified date- Returns:
- the last modified date
-
setLastModified
Set the last modified date- Parameters:
lastModified
- the last modified date
-
getETag
Get the ETag of the mime part- Returns:
- the ETag
-
setETag
Set the ETag for the mime part- Parameters:
eTag
- the ETag
-
writeToFile
Write the mimepart to a directory, using its name as file name.- Parameters:
dir
- the directory to write the file to- Returns:
- the absolute path name of the file written, or null if an error occurred
-
writeToFile
Write the mimepart to a file.- Parameters:
dir
- the directory to write the file to- Returns:
- the name of the file written, or null if an error occurred
-
getSubHeader
Get a sub-header from a header, e.g. the charset fromContent-Type: text/plain; charset="UTF-8"
-
normalizeFilename
Normalize a upload file name. Internet Explorer on Windows sends the whole path, so we cut off everything before the actual name.
-