public class AttachmentStub extends java.lang.Object implements IncomingFileAttachment
FILE_ATTACHMENT, MEMORY_ATTACHMENT, OUTPUTSTREAM_ATTACHMENT, STREAM_ATTACHMENT| Constructor and Description |
|---|
AttachmentStub(java.lang.String contentId)
Constructor for an AttachmentStub with given contentId.
|
| 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 |
getAbsoluteFilename()
Returns the path to the file encapsulated by this attachment.
|
byte[] |
getBytes()
Returns the raw data from this attachment as array of bytes.
|
java.lang.String |
getContentId()
Return the content ID of this attachment.
|
ContentType |
getContentType()
The content type for this attachment.
|
java.io.InputStream |
getInputStream()
Returns the input stream which contains the data.
|
long |
getTimeToWait() |
int |
getType()
Returns this attachment's type.
|
java.lang.String |
getUniqueId() |
boolean |
isAvailable()
Returns
true if this attachment is ready to be processed. |
boolean |
isLocal()
Returns
true, if this attachment was created locally. |
boolean |
move(java.lang.String newFilePath)
This method moves the file containing the attachment's raw data to the given target file path
(e.g.
|
void |
save(java.lang.String targetFilePath)
Copies the attachment's raw data to the target file path (e.g.
|
void |
setTimeToWait(long timeToWait) |
void |
setUniqueId(java.lang.String connectionId) |
long |
size()
Returns the size of this attachment in bytes.
|
public AttachmentStub(java.lang.String contentId)
contentId - public java.lang.String getUniqueId()
public void setUniqueId(java.lang.String connectionId)
public long getTimeToWait()
public void setTimeToWait(long timeToWait)
public void dispose()
Attachmentdispose in interface Attachmentpublic byte[] getBytes()
throws AttachmentException,
java.io.IOException
IncomingAttachment
WARNING: The result can potentially use a large amount of memory.
Furthermore, some environments or some types of attachments (see e.g. InputStreamAttachment or
FileAttachment) may not support representing the attachment's raw data as a byte array. In
these cases, a call to this method will cause an AttachmentException to get thrown (see
Attachment.getType().
getBytes in interface IncomingAttachmentAttachmentException - if attachment processing is not supported within the current runtime or obtaining the attachment failed
for any reason or in particular, when this attachment type doesn't support byte array access to its raw
datajava.io.IOException - if reading raw attachment data failedAttachment.getType(),
IncomingAttachment.getInputStream()public ContentType getContentType() throws AttachmentException
AttachmentgetContentType in interface AttachmentAttachmentExceptionpublic java.lang.String getContentId()
AttachmentParameterValue instances.getContentId in interface Attachmentpublic java.io.InputStream getInputStream()
throws AttachmentException,
java.io.IOException
IncomingAttachment
Depending on the actual attachment implementation, this method may either always return the
same java.io.InputStream instance, or it could create a new one on each call. In
the first case, it is important to note that reading the attachment data might be possible only
once, as the returned stream is not guaranteed to support resetting (see Attachment.getType().
getInputStream in interface IncomingAttachmentAttachmentException - if attachment processing is not supported within the current runtime or obtaining the attachment failed
for any reasonjava.io.IOException - if reading raw attachment data failedAttachment.getType(),
Attachment.size(),
IncomingAttachment.getBytes()public int getType()
throws AttachmentException
Attachment
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.
getType in interface AttachmentAttachmentExceptionAttachment.STREAM_ATTACHMENT,
Attachment.FILE_ATTACHMENT,
Attachment.MEMORY_ATTACHMENT,
Attachment.OUTPUTSTREAM_ATTACHMENTpublic boolean isAvailable()
IncomingAttachmenttrue if this attachment is ready to be processed.
Because the JMEDS framework handles attachments asynchronously, it is possible (and will
most likely occur frequently) for an attachement's raw data to still be being transmitted over
the network while a caller's business logic (e.g. the Operation.invoke(ParameterValue)
method) gets called providing access to the attachment by means of its ParameterValue.get(String). Using methods other than Attachment.getContentId() or IncomingAttachment.isAvailable() on this attachment would block the caller until the entire attachment is read
out. Thus, this method allows to check whether further examination of this attachment would
block it or not.
isAvailable in interface IncomingAttachmenttrue, if this attachment is already available, false if it is still not
received (entirely)public boolean canDetermineSize()
Attachment
Some types of attachment (e.g. InputStreamAttachment) may not be aware of their actual size; in such cases, this method will return false.
canDetermineSize in interface Attachmentpublic long size()
throws AttachmentException
Attachment
Some types of attachment (e.g. InputStreamAttachment) may not be aware of their actual size; in such cases, this method will return -1.
size in interface AttachmentAttachmentExceptionpublic boolean isLocal()
IncomingFileAttachmenttrue, if this attachment was created locally. This is synonymous to the
sender/originator of this attachment instance residing within the same Java virtual machine as
its receiver.
This method is especially important for attachments of type Attachment.FILE_ATTACHMENT, as - if it returns true - this denotes that the file the attachment points to is the original one. That is, when
attempting to IncomingFileAttachment.move(String) a file attachment, this allows to distinguish whether the
original file would be moved to a new location or whether simply the attachment file will be
moved out of the local attachment store (used for caching incoming attachments) to a place
outside of it.
isLocal in interface IncomingFileAttachmenttrue only if this attachment was originally created locally (within the same JVM)public java.lang.String getAbsoluteFilename()
throws AttachmentException
IncomingFileAttachmenttype Attachment.FILE_ATTACHMENT. For any other types, it will
throw an AttachmentException.getAbsoluteFilename in interface IncomingFileAttachmentAttachmentExceptionpublic void save(java.lang.String targetFilePath)
throws AttachmentException,
java.io.IOException
IncomingFileAttachmenttype Attachment.FILE_ATTACHMENT. In
any other cases it will throw an AttachmentException.save in interface IncomingFileAttachmenttargetFilePath - the new path within the local file system to store the file toAttachmentException - if attachment processing is not supported within the current runtime or obtaining the attachment failed
for any reasonjava.io.IOException - in case writing to the local file system failed for any reasonpublic boolean move(java.lang.String newFilePath)
throws AttachmentException
IncomingFileAttachmenttype
Attachment.FILE_ATTACHMENT. In any other cases it will throw an AttachmentException.move in interface IncomingFileAttachmentnewFilePath - the new path within the local file system to move the file totrue, if the file was moved/renamed successfully, false otherwiseAttachmentException - if attachment processing is not supported within the current runtime or obtaining the attachment failed
for any reason