Package helma.util

# Class MimePart

java.lang.Object
helma.util.MimePart

All Implemented Interfaces:
  `Serializable`

public class MimePart extends Object implements Serializable
This represents a MIME part of a HTTP file upload

See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`MimePart(String name, byte[] content, String contentType)`
Creates a new MimePart object.
`MimePart(org.apache.commons.fileupload.FileItem fileItem)`
Creates a new MimePart object from a file upload.

## Method Summary

Modifier and Type
Method
Description
`byte[]`
`getContent()`
Return the content of the mime part as byte array.
`int`
`getContentLength()`
Get the number of bytes in the mime part's content
`String`
`getContentType()`
`String`
`getETag()`
Get the ETag of the mime part
`InputStream`
`getInputStream()`
Return an InputStream to read the content of the mime part
`Date`
`getLastModified()`
Get the last modified date
`String`
`getName()`
Get the mime part's name
`static String`
`getSubHeader(String header, String subHeaderName)`
Get a sub-header from a header, e.g.
`String`
`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`
`setETag(String eTag)`
Set the ETag for the mime part
`void`
`setLastModified(Date lastModified)`
Set the last modified date
`String`
`writeToFile(String dir)`
Write the mimepart to a directory, using its name as file name.
`String`
`writeToFile(String dir, String fname)`
Write the mimepart to a file.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### MimePart

public MimePart(String name, byte[] content, String contentType)
Creates a new MimePart object.

Parameters:
  `name` - the file name
  `content` - the mime part content
  `contentType` - 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

public String 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

public String 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

public InputStream getInputStream() throws IOException
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

public String 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

public Date getLastModified()
Get the last modified date

Returns:
  the last modified date

### setLastModified

public void setLastModified(Date lastModified)
Set the last modified date

Parameters:
  `lastModified` - the last modified date

### getETag

public String getETag()
Get the ETag of the mime part

Returns:
  the ETag

### setETag

public void setETag(String eTag)
Set the ETag for the mime part

Parameters:
  `eTag` - the ETag

### writeToFile

public String writeToFile(String dir)
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

public String writeToFile(String dir, String fname)
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

public static String getSubHeader(String header, String subHeaderName)
Get a sub-header from a header, e.g. the charset from `Content-Type: text/plain; charset="UTF-8"`

### normalizeFilename

public static String normalizeFilename(String filename)
Normalize a upload file name. Internet Explorer on Windows sends the whole path, so we cut off everything before the actual name.