public interface Attachment
There are two different ways of obtaining raw data from an Attachment. The first
one, IncomingAttachment.getInputStream(), allows the reading of a stream-based
representation of the attachment's bytes, whereas the second one, IncomingAttachment.getBytes(), returns them within a byte array. While in some cases being
faster (depending on the actual Attachment implementation), the later approach is
subject to certain limitations resulting from the finite amount of memory available within the
current runtime.
Most methods of this interface are indicated to throw AttachmentExceptions if
obtaining the requested attachment data or property failed for any reason. This could be the
result e.g. of a network failure while reading the attachment or an unexpected or erroneous
attachment format, or it could mean that attachment support is not available within the current
JMEDS framework configuration.
The actual type of attachment can be queried by means of method getType(). Depending
on the value returned (see STREAM_ATTACHMENT, FILE_ATTACHMENT, MEMORY_ATTACHMENT and OUTPUTSTREAM_ATTACHMENT), some methods like IncomingAttachment.getInputStream(), IncomingAttachment.getBytes() and size()
may behave differently. Additionally, other methods like IncomingFileAttachment.save(String), IncomingFileAttachment.move(String) or IncomingFileAttachment.getAbsoluteFilename() may not work at all.
| Modifier and Type | Field and Description |
|---|---|
static int |
FILE_ATTACHMENT
This attachment will behave like a FileAttachment.
|
static int |
MEMORY_ATTACHMENT
This attachment will behave like a MemoryAttachment.
|
static int |
OUTPUTSTREAM_ATTACHMENT
Mostly a InputStreamAttachment.
|
static int |
STREAM_ATTACHMENT
This attachment will behave like a InputStreamAttachment.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canDetermineSize()
Use this method to check if this attachment is able to determine its size.
|
void |
dispose()
Disposes of the attachment and - if possible - frees any resources such as volatile and/or non
volatile memory it uses.
|
java.lang.String |
getContentId()
Return the content ID of this attachment.
|
ContentType |
getContentType()
The content type for this attachment.
|
int |
getType()
Returns this attachment's type.
|
long |
size()
Returns the size of this attachment in bytes.
|
static final int STREAM_ATTACHMENT
IncomingFileAttachment.save(String), IncomingFileAttachment.move(String) and IncomingFileAttachment.getAbsoluteFilename()
operations. Note that checking that an attachment is of this type is
not sufficient in order to safely cast it to a InputStreamAttachment. Use an
instanceof expression instead.static final int MEMORY_ATTACHMENT
IncomingFileAttachment.save(String), IncomingFileAttachment.move(String) and IncomingFileAttachment.getAbsoluteFilename()
operations. Note that checking that an attachment is of this type is
not sufficient to safely cast it to a MemoryAttachment. Use an
instanceof expression instead.static final int FILE_ATTACHMENT
IncomingFileAttachment.save(String) , IncomingFileAttachment.move(String) and IncomingFileAttachment.getAbsoluteFilename() operations. Note that checking
that an attachment is of this type is not sufficient to safely cast it to a
FileAttachment. Use an instanceof expression instead.static final int OUTPUTSTREAM_ATTACHMENT
int getType()
throws AttachmentException
The value returned distinguishes between different implementations and thereby different
storage models for the attachment's raw data, such as in-memory, on file system or as (opaque)
input stream. It further determines which ways of obtaining the raw data are suitable/possible
for this instance (e.g. by means of IncomingAttachment.getBytes() or IncomingAttachment.getInputStream()). Also, usage/availability of some operations like IncomingFileAttachment.save(String), IncomingFileAttachment.move(String) and IncomingFileAttachment.getAbsoluteFilename() depends on the type of attachment. On some types,
these operations will not be supported at all and will always throw an AttachmentException.
AttachmentExceptionSTREAM_ATTACHMENT,
FILE_ATTACHMENT,
MEMORY_ATTACHMENT,
OUTPUTSTREAM_ATTACHMENTjava.lang.String getContentId()
ParameterValue instances.void dispose()
ContentType getContentType() throws AttachmentException
AttachmentExceptionAttachmentException - if attachment processing is not supported within the current runtime or obtaining the attachment failed
for any reasonboolean canDetermineSize()
Some types of attachment (e.g. InputStreamAttachment) may not be aware of their actual size; in such cases, this method will return false.
long size() throws AttachmentException
Some types of attachment (e.g. InputStreamAttachment) may not be aware of their actual size; in such cases, this method will return -1.
AttachmentException