Package org.jvnet.mimepull
Class MIMEPart
- java.lang.Object
-
- org.jvnet.mimepull.MIMEPart
-
- All Implemented Interfaces:
Closeable,AutoCloseable
public class MIMEPart extends Object implements Closeable
Represents an attachment part in a MIME message. MIME message parsing is done lazily using a pull parser, so the part may not have all the data.read()andreadOnce()may trigger the actual parsing the message. In fact, parsing of an attachment part may be triggered by callingread()methods on some other attachment parts. All this happens behind the scenes so the application developer need not worry about these details.- Author:
- Jitendra Kotamraju, Martin Grebac
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Cleans up any resources that are held by this part (for e.g.List<? extends Header>getAllHeaders()Return all the headersStringgetContentId()Returns Content-ID MIME header for this attachment partStringgetContentTransferEncoding()Returns Content-Transfer-Encoding MIME header for this attachment partStringgetContentType()Returns Content-Type MIME header for this attachment partList<String>getHeader(String name)Return all the values for the specified header.booleanisClosed()Returntrueif this part has already been closed,falseotherwise.voidmoveTo(File f)InputStreamread()Can get the attachment part's content multiple times.InputStreamreadOnce()Can get the attachment part's content only once.StringtoString()
-
-
-
Method Detail
-
read
public InputStream read()
Can get the attachment part's content multiple times. That means the full content needs to be there in memory or on the file system. Calling this method would trigger parsing for the part's data. So do not call this unless it is required(otherwise, just wrap MIMEPart into a object that returns InputStream for e.g DataHandler)- Returns:
- data for the part's content
-
close
public void close()
Cleans up any resources that are held by this part (for e.g. deletes the temp file that is used to serve this part's content). After calling this, one shouldn't callread()orreadOnce()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
readOnce
public InputStream readOnce()
Can get the attachment part's content only once. The content will be lost after the method. Content data is not be stored on the file system or is not kept in the memory for the following case: - Attachement parts contents are accessed sequentially In general, take advantage of this when the data is used only once.- Returns:
- data for the part's content
-
moveTo
public void moveTo(File f)
-
getContentId
public String getContentId()
Returns Content-ID MIME header for this attachment part- Returns:
- Content-ID of the part
-
getContentTransferEncoding
public String getContentTransferEncoding()
Returns Content-Transfer-Encoding MIME header for this attachment part- Returns:
- Content-Transfer-Encoding of the part
-
getContentType
public String getContentType()
Returns Content-Type MIME header for this attachment part- Returns:
- Content-Type of the part
-
getHeader
public List<String> getHeader(String name)
Return all the values for the specified header. Returnsnullif no headers with the specified name exist.- Parameters:
name- header name- Returns:
- list of header values, or null if none
-
getAllHeaders
public List<? extends Header> getAllHeaders()
Return all the headers- Returns:
- list of Header objects
-
isClosed
public boolean isClosed()
Returntrueif this part has already been closed,falseotherwise.- Returns:
trueif this part has already been closed,falseotherwise.
-
-