|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ws4d.java.attachment.AttachmentStub
public class AttachmentStub
Field Summary |
---|
Fields inherited from interface org.ws4d.java.attachment.Attachment |
---|
FILE_ATTACHMENT, MEMORY_ATTACHMENT, OUTPUTSTREAM_ATTACHMENT, STREAM_ATTACHMENT |
Constructor Summary | |
---|---|
AttachmentStub(java.lang.String contentId)
|
Method Summary | |
---|---|
void |
dispose()
Disposes of the attachment and - if possible - frees any resources such as volatile and/or non volatile memory it uses. |
ContextID |
getAttachmentScope()
|
byte[] |
getBytes()
Returns the raw data from this attachment as array of bytes. |
java.lang.String |
getContentId()
Return the content ID of this attachment. |
InternetMediaType |
getContentType()
The content type (MIME) for this attachment. |
java.lang.String |
getFilePath()
Returns the path to the file encapsulated by this attachment. |
java.io.InputStream |
getInputStream()
Returns the input stream which contains the data. |
java.lang.String |
getTransferEncoding()
The encoding for this attachment. |
int |
getType()
Returns this attachment's type. |
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 |
serialize(java.io.OutputStream out)
|
void |
setAttachmentScope(ContextID attachmentScope)
|
long |
size()
Returns the size of the attachment in bytes. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AttachmentStub(java.lang.String contentId)
contentId
- Method Detail |
---|
public ContextID getAttachmentScope()
public void setAttachmentScope(ContextID attachmentScope)
public void dispose()
Attachment
dispose
in interface Attachment
public 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 IncomingAttachment
AttachmentException
- 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 data
java.io.IOException
- if reading raw attachment data failedAttachment.getType()
,
IncomingAttachment.getInputStream()
public java.lang.String getContentId()
Attachment
ParameterValue
instances.
getContentId
in interface Attachment
public InternetMediaType getContentType() throws AttachmentException
Attachment
getContentType
in interface Attachment
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reasonpublic 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 IncomingAttachment
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reason
java.io.IOException
- if reading raw attachment data failedAttachment.getType()
,
IncomingAttachment.size()
,
IncomingAttachment.getBytes()
public java.lang.String getTransferEncoding() throws AttachmentException
Attachment
getTransferEncoding
in interface Attachment
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reasonpublic 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 #getBytes()
or
#getInputStream()
). Also, usage/availability of some operations
like #save(String)
, #move(String)
and
#getFilePath()
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 Attachment
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reasonAttachment.STREAM_ATTACHMENT
,
Attachment.FILE_ATTACHMENT
,
Attachment.MEMORY_ATTACHMENT
public boolean isAvailable()
IncomingAttachment
true
if this attachment is ready to be processed.
Because the DPWS 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
parameters
. 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 IncomingAttachment
true
, if this attachment is already available,
false
if it is still not received (entirely)public long size() throws AttachmentException
IncomingAttachment
Some types of attachment (e.g. InputStreamAttachment
) may not be
aware of their actual size; in such cases, this method will either return
zero or a potentially inaccurate estimate (as provided by
java.io.InputStream.available()
).
size
in interface IncomingAttachment
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reasonAttachment.getType()
,
IncomingAttachment.getInputStream()
public boolean isLocal()
IncomingFileAttachment
true
, 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 IncomingFileAttachment
true
only if this attachment was originally created
locally (within the same JVM)public java.lang.String getFilePath() throws AttachmentException
IncomingFileAttachment
type
Attachment.FILE_ATTACHMENT
. For any other types, it will throw an
AttachmentException
.
getFilePath
in interface IncomingFileAttachment
AttachmentException
public void save(java.lang.String targetFilePath) throws AttachmentException, java.io.IOException
IncomingFileAttachment
type
Attachment.FILE_ATTACHMENT
. In any other cases it
will throw an AttachmentException
.
save
in interface IncomingFileAttachment
targetFilePath
- the new path within the local file system to store
the file to
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reason
java.io.IOException
- in case writing to the local file system failed for
any reasonpublic boolean move(java.lang.String newFilePath) throws AttachmentException
IncomingFileAttachment
type
Attachment.FILE_ATTACHMENT
. In
any other cases it will throw an AttachmentException
.
move
in interface IncomingFileAttachment
newFilePath
- the new path within the local file system to move the
file to
true
, if the file was moved/renamed successfully,
false
otherwise
AttachmentException
- if attachment processing is not supported
within the current runtime or obtaining the attachment failed
for any reasonpublic void serialize(java.io.OutputStream out) throws java.io.IOException, AttachmentException
serialize
in interface Attachment
java.io.IOException
AttachmentException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |