|
Project 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 Message. Message Elements are immutable objects. A Message Element may be shared amongst as many messages as is desired. 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
OutputStream
String
.
Message
Field Summary | |
---|---|
protected long |
cachedGetByteLength
cached result of getByteLength() operation. |
protected SoftReference |
cachedGetBytes
cached result of getBytes(boolean) operation. |
protected SoftReference |
cachedToString
cached result of toString() operation. |
protected String |
name
The name of this element. |
protected Map |
properties
message properties hashmap |
protected MessageElement |
sig
The optional element which digitially 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 initializaing everything but the data. |
Method Summary | |
---|---|
Object |
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 .
We use the "unknown" extension and leave it to sub-classes to
extend this. |
MimeMediaType |
getMimeType()
Returns the MIME Media type of this Document per
IETF RFC 2046 MIME : Media Types.
Will return "Application/Octet-Stream" if no type was originally
specified. |
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.
This version probably has sub-optimal performance. |
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.Document |
---|
getStream |
Field Detail |
---|
protected final String name
protected final MimeMediaType type
protected final MessageElement sig
protected Map properties
protected transient long cachedGetByteLength
getByteLength()
operation.
protected transient SoftReference cachedGetBytes
getBytes(boolean)
operation.
protected transient SoftReference 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 elemnent. 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
annonimity 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.public final Object 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 enconding 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 Document
sendTo
- The OutputStream to which the Document
will
be written.
IOException
- if an I/O error occurs.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
|
JXTA J2SE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |