Class MIMEPart
java.lang.Object
org.jvnet.mimepull.MIMEPart
- All Implemented Interfaces:
Closeable, AutoCloseable
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()
and readOnce() may trigger the actual parsing the message. In fact,
parsing of an attachment part may be triggered by calling read() methods
on some other attachment parts. All this happens behind the scenes so the
application developer need not worry about these details.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate Stringprivate Stringprivate Stringprivate final DataHeadprivate InternetHeadersprivate final Objectprivate static final Logger(package private) final MIMEMessage(package private) boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddBody(ByteBuffer buf) Callback to notify that there is a partial content for the partvoidclose()Cleans up any resources that are held by this part (for e.g.(package private) voidCallback to indicate that parsing is done for this part (no more update events for this part)Return all the headersReturns Content-ID MIME header for this attachment partReturns Content-Transfer-Encoding MIME header for this attachment partReturns Content-Type MIME header for this attachment partReturn all the values for the specified header.private voidbooleanisClosed()Returntrueif this part has already been closed,falseotherwise.voidSend the content to the Fileread()Can get the attachment part's content multiple times.readOnce()Can get the attachment part's content only once.(package private) voidsetContentId(String cid) Callback to set Content-ID for this part(package private) voidCallback to set Content-Transfer-Encoding for this part(package private) voidsetHeaders(InternetHeaders headers) Callback to set headerstoString()
-
Field Details
-
LOGGER
-
closed
private volatile boolean closed -
headers
-
contentId
-
contentType
-
contentTransferEncoding
-
parsed
volatile boolean parsed -
msg
-
dataHead
-
lock
-
-
Constructor Details
-
MIMEPart
MIMEPart(MIMEMessage msg) -
MIMEPart
MIMEPart(MIMEMessage msg, String contentId)
-
-
Method Details
-
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
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
-
getContentId
Returns Content-ID MIME header for this attachment part- Returns:
- Content-ID of the part
-
getContentTransferEncoding
Returns Content-Transfer-Encoding MIME header for this attachment part- Returns:
- Content-Transfer-Encoding of the part
-
getContentType
Returns Content-Type MIME header for this attachment part- Returns:
- Content-Type of the part
-
getHeaders
private void getHeaders() -
getHeader
-
getAllHeaders
-
setHeaders
Callback to set headers- Parameters:
headers- MIME headers for the part
-
addBody
Callback to notify that there is a partial content for the part- Parameters:
buf- content data for the part
-
doneParsing
void doneParsing()Callback to indicate that parsing is done for this part (no more update events for this part) -
setContentId
Callback to set Content-ID for this part- Parameters:
cid- Content-ID of the part
-
setContentTransferEncoding
Callback to set Content-Transfer-Encoding for this part- Parameters:
cte- Content-Transfer-Encoding of the part
-
isClosed
public boolean isClosed()Returntrueif this part has already been closed,falseotherwise.- Returns:
trueif this part has already been closed,falseotherwise.
-
toString
-