Package org.jvnet.mimepull
Class MIMEPart
- java.lang.Object
-
- org.jvnet.mimepull.MIMEPart
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class MIMEPart extends java.lang.Object implements java.io.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.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
closed
private java.lang.String
contentId
private java.lang.String
contentTransferEncoding
private java.lang.String
contentType
private DataHead
dataHead
private InternetHeaders
headers
private java.lang.Object
lock
private static java.util.logging.Logger
LOGGER
(package private) MIMEMessage
msg
(package private) boolean
parsed
-
Constructor Summary
Constructors Constructor Description MIMEPart(MIMEMessage msg)
MIMEPart(MIMEMessage msg, java.lang.String contentId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addBody(java.nio.ByteBuffer buf)
Callback to notify that there is a partial content for the partvoid
close()
Cleans up any resources that are held by this part (for e.g.(package private) void
doneParsing()
Callback to indicate that parsing is done for this part (no more update events for this part)java.util.List<? extends Header>
getAllHeaders()
Return all the headersjava.lang.String
getContentId()
Returns Content-ID MIME header for this attachment partjava.lang.String
getContentTransferEncoding()
Returns Content-Transfer-Encoding MIME header for this attachment partjava.lang.String
getContentType()
Returns Content-Type MIME header for this attachment partjava.util.List<java.lang.String>
getHeader(java.lang.String name)
Return all the values for the specified header.private void
getHeaders()
boolean
isClosed()
Returntrue
if this part has already been closed,false
otherwise.void
moveTo(java.io.File f)
java.io.InputStream
read()
Can get the attachment part's content multiple times.java.io.InputStream
readOnce()
Can get the attachment part's content only once.(package private) void
setContentId(java.lang.String cid)
Callback to set Content-ID for this part(package private) void
setContentTransferEncoding(java.lang.String cte)
Callback to set Content-Transfer-Encoding for this part(package private) void
setHeaders(InternetHeaders headers)
Callback to set headersjava.lang.String
toString()
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
closed
private volatile boolean closed
-
headers
private volatile InternetHeaders headers
-
contentId
private volatile java.lang.String contentId
-
contentType
private java.lang.String contentType
-
contentTransferEncoding
private java.lang.String contentTransferEncoding
-
parsed
volatile boolean parsed
-
msg
final MIMEMessage msg
-
dataHead
private final DataHead dataHead
-
lock
private final java.lang.Object lock
-
-
Constructor Detail
-
MIMEPart
MIMEPart(MIMEMessage msg)
-
MIMEPart
MIMEPart(MIMEMessage msg, java.lang.String contentId)
-
-
Method Detail
-
read
public java.io.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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
readOnce
public java.io.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(java.io.File f)
-
getContentId
public java.lang.String getContentId()
Returns Content-ID MIME header for this attachment part- Returns:
- Content-ID of the part
-
getContentTransferEncoding
public java.lang.String getContentTransferEncoding()
Returns Content-Transfer-Encoding MIME header for this attachment part- Returns:
- Content-Transfer-Encoding of the part
-
getContentType
public java.lang.String getContentType()
Returns Content-Type MIME header for this attachment part- Returns:
- Content-Type of the part
-
getHeaders
private void getHeaders()
-
getHeader
public java.util.List<java.lang.String> getHeader(java.lang.String name)
Return all the values for the specified header. Returnsnull
if no headers with the specified name exist.- Parameters:
name
- header name- Returns:
- list of header values, or null if none
-
getAllHeaders
public java.util.List<? extends Header> getAllHeaders()
Return all the headers- Returns:
- list of Header objects
-
setHeaders
void setHeaders(InternetHeaders headers)
Callback to set headers- Parameters:
headers
- MIME headers for the part
-
addBody
void addBody(java.nio.ByteBuffer buf)
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
void setContentId(java.lang.String cid)
Callback to set Content-ID for this part- Parameters:
cid
- Content-ID of the part
-
setContentTransferEncoding
void setContentTransferEncoding(java.lang.String cte)
Callback to set Content-Transfer-Encoding for this part- Parameters:
cte
- Content-Transfer-Encoding of the part
-
isClosed
public boolean isClosed()
Returntrue
if this part has already been closed,false
otherwise.- Returns:
true
if this part has already been closed,false
otherwise.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-