Package org.jvnet.mimepull
Class DataHead
- java.lang.Object
-
- org.jvnet.mimepull.DataHead
-
final class DataHead extends java.lang.Object
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
DataHead.ReadMultiStream
(package private) class
DataHead.ReadOnceStream
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Throwable
consumedAt
Used only for debugging.(package private) DataFile
dataFile
If the part is stored in a file, non-null.(package private) Chunk
head
Linked list to keep the part's content(package private) long
inMemory
private MIMEPart
part
(package private) boolean
readOnce
(package private) Chunk
tail
Linked list to keep the part's content
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
addBody(java.nio.ByteBuffer buf)
(package private) void
close()
(package private) void
doneParsing()
(package private) 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.private boolean
unconsumed()
Used for an assertion.
-
-
-
Field Detail
-
head
volatile Chunk head
Linked list to keep the part's content
-
tail
volatile Chunk tail
Linked list to keep the part's content
-
dataFile
DataFile dataFile
If the part is stored in a file, non-null.
-
part
private final MIMEPart part
-
readOnce
boolean readOnce
-
inMemory
volatile long inMemory
-
consumedAt
private java.lang.Throwable consumedAt
Used only for debugging. This records where readOnce() is called.
-
-
Constructor Detail
-
DataHead
DataHead(MIMEPart part)
-
-
Method Detail
-
addBody
void addBody(java.nio.ByteBuffer buf)
-
doneParsing
void doneParsing()
-
moveTo
void moveTo(java.io.File f)
-
close
void close()
-
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
-
unconsumed
private boolean unconsumed()
Used for an assertion. Returns true when readOnce() is not already called. or otherwise throw an exception.Calling this method also marks the stream as 'consumed'
- Returns:
- true if readOnce() is not called before
-
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
-
-