|
JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jxta.endpoint.MessageElement
public abstract class MessageElement
JXTA Message Elements are used to add data to a JXTA Message. Message Elements are immutable objects. A Message Element may be shared amongst as many messages as is desired.
Several Message Element sub-classes are provided for handling various types of data. All Message Elements are internally converted to raw bytes when sent as part of a Message. The various Message Element flavors are provided for convenience and efficiency. They enable the simplest creation and most efficient conversion from the individual data types to the appropriate binary data. Because Message Elements are merely a convenient representation for binary data the object type of Message Element received by a peer may not be the same as was sent by the sending peer. Even though the Message Element container may change during transmission the data contained in the Message Element is faithfully preserved. A Message Element is composed of four components:String
. Unnamed
elements are assumed to have the name "" (the empty string).MimeMediaType
. If not specified
the Mime Media Type is assumed to be "Application/Octet-Stream".InputStream
from DocumentStreamIO.getStream()
OutputStream
via sendToStream(OutputStream)
String
from toString()
getBytes(boolean)
Message
Field Summary | |
---|---|
protected long |
cachedGetByteLength
cached result of getByteLength() operation. |
protected SoftReference<byte[]> |
cachedGetBytes
cached result of getBytes(boolean) operation. |
protected SoftReference<String> |
cachedToString
cached result of toString() operation. |
protected String |
name
The name of this element. |
protected MessageElement |
sig
The optional element which digitally signs or digests this element. |
protected MimeMediaType |
type
The type of this element. |
Constructor Summary | |
---|---|
protected |
MessageElement(String name,
MimeMediaType type,
MessageElement sig)
Internal constructor for initializing everything but the data. |
Method Summary | |
---|---|
MessageElement |
clone()
Deprecated. Since Message Elements are immutable this method does nothing useful. |
protected static void |
copyInputStreamToOutputStream(InputStream source,
OutputStream sink)
Copies an input stream to an output stream with buffering. |
boolean |
equals(Object target)
Elements are considered equal if they have the same name, type and signatures. |
long |
getByteLength()
Returns the size of the element data in bytes. |
byte[] |
getBytes(boolean copy)
Returns a byte array which contains the element data. |
String |
getElementName()
Returns the name of the MessageElement. |
Object |
getElementProperty(Object key)
Retrieves a transient property from the set for this element. |
String |
getFileExtension()
Returns the file extension type used by this Document . |
MimeMediaType |
getMimeType()
Returns the MIME Media type of this Document per
IETF RFC 2046 MIME : Media Types. |
static String |
getSequentialName()
Returns a string containing a pseudo-random unique string. |
MessageElement |
getSignature()
Returns the element containing the digest/digital signature for this element |
static String |
getUniqueName()
Returns a pseudo-random unique string which can be used as an element name. |
int |
hashCode()
|
void |
sendToStream(OutputStream sendTo)
Send the contents of this Document to the specified stream. |
Object |
setElementProperty(Object key,
Object value)
Associate a transient property with this element. |
String |
toString()
Returns a String representation of the element data. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface net.jxta.document.DocumentStreamIO |
---|
getStream |
Field Detail |
---|
protected final String name
protected final MimeMediaType type
protected final MessageElement sig
protected transient long cachedGetByteLength
getByteLength()
operation.
protected transient SoftReference<byte[]> cachedGetBytes
getBytes(boolean)
operation.
protected transient SoftReference<String> cachedToString
toString()
operation.
Constructor Detail |
---|
protected MessageElement(String name, MimeMediaType type, MessageElement sig)
name
- Name of the Element. May be the empty string ("") if
the Element is not named.type
- Type of the Element. null is equivalent to specifying
the type "Application/Octet-stream"sig
- optional message digest/digital signature element. If
no signature is to be specified, pass null.Method Detail |
---|
public static String getUniqueName()
public static String getSequentialName()
String.compare()
will be consistent with the order in which
results were returned from this function.
Security Consideration : Be aware that the pseudo random portion of
the names generated by this string are shared amongst all peer groups
running in the same classloader. You may be at a risk for loss of
anonymity if you use the element names produced in more than one peer
group.
String.compare()
will be consistent with the order in
which results were returned from this function.@Deprecated public final MessageElement clone()
clone
in class Object
public boolean equals(Object target)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
'charset'
parameter of the message element's mimetype, if
any, is used to determine encoding. If the charset specified is
unsupported then the default encoding will be used.
synchronized for caching purposes.
toString
in class Object
public String getElementName()
public MimeMediaType getMimeType()
Document
per
IETF RFC 2046 MIME : Media Types.
JXTA does not currently support the 'Multipart
' or
'Message
' media types.
Will return "Application/Octet-Stream" if no type was originally
specified.
getMimeType
in interface Document
Document
.public String getFileExtension()
Document
. This
value is usually chosen based upon the MIME Media Type.
We use the "unknown" extension and leave it to sub-classes to
extend this. If we had a mailcap facility we could do better
classification based on mimetype.
getFileExtension
in interface Document
Document
.public long getByteLength()
public byte[] getBytes(boolean copy)
copy
parameter allows you to request a
private, modifiable copy of the element data.
This implementation builds the byte array from the stream.
copy
- If true then the result can be modified without damaging the state of this
MessageElement. If false, then the result may be a shared copy of the data and
should be considered read-only.
public void sendToStream(OutputStream sendTo) throws IOException
Document
to the specified stream.
This version probably has sub-optimal performance. Sub-classes
should override this implementation.
sendToStream
in interface DocumentStreamIO
sendTo
- The OutputStream to which the Document
will
be written.
IOException
- For errors while writing the Document
.public MessageElement getSignature()
public Object setElementProperty(Object key, Object value)
key
- the property keyvalue
- the value for the property
public Object getElementProperty(Object key)
key
- the property key.
protected static void copyInputStreamToOutputStream(InputStream source, OutputStream sink) throws IOException
source
- The stream to copy from.sink
- The stream to send the data to.
IOException
- if there is a problem copying the data
|
JXSE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |