JXTA

net.jxta.impl.endpoint
Class JxtaMessageMessageElement

java.lang.Object
  extended by net.jxta.endpoint.MessageElement
      extended by net.jxta.impl.endpoint.JxtaMessageMessageElement
All Implemented Interfaces:
Document, DocumentStreamIO

public class JxtaMessageMessageElement
extends MessageElement

A Message Element using a JXTA Message as the element data

See Also:
Message, MessageElement

Field Summary
protected  Message msg
          The Message which is the data for this message element.
protected  WireFormatMessage serial
          A serialized form of the message.
 
Fields inherited from class net.jxta.endpoint.MessageElement
cachedGetByteLength, cachedGetBytes, cachedToString, name, sig, type
 
Constructor Summary
JxtaMessageMessageElement(String name, MimeMediaType type, Message msg, MessageElement sig)
          Create a new Message Element.
 
Method Summary
 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.
 Message getMessage()
          Returns a copy of the message which backs this element.
 InputStream getStream()
          Returns the stream of bytes which represents the content of this Document.
 int hashCode()
          
 void sendToStream(OutputStream sendTo)
          Send the contents of this Document to the specified stream.
 String toString()
          

Returns a String representation of the element data.

 
Methods inherited from class net.jxta.endpoint.MessageElement
clone, copyInputStreamToOutputStream, getElementName, getElementProperty, getFileExtension, getMimeType, getSequentialName, getSignature, getUniqueName, setElementProperty
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

msg

protected final Message msg
The Message which is the data for this message element.


serial

protected transient WireFormatMessage serial
A serialized form of the message.

Constructor Detail

JxtaMessageMessageElement

public JxtaMessageMessageElement(String name,
                                 MimeMediaType type,
                                 Message msg,
                                 MessageElement sig)
Create a new Message Element. The contents of the provided message are not copied during construction.

Parameters:
name - Name of the MessageElement. May be the empty string ("") if the MessageElement is not named.
type - Type of the MessageElement. null is the same as specifying the type "Application/Octet-stream".
msg - A message which will be used as the element content for this message.
sig - optional message digest/digital signature element or null if no signature is desired.
Method Detail

equals

public boolean equals(Object target)

Elements are considered equal if they have the same name, type and signatures. Element data is not considered by this implementation as it is mostly intended for subclass use.

Overrides:
equals in class MessageElement

hashCode

public int hashCode()

Overrides:
hashCode in class MessageElement

toString

public String toString()

Returns a String representation of the element data. The '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.

Overrides:
toString in class MessageElement

getByteLength

public long getByteLength()
Returns the size of the element data in bytes.

Overrides:
getByteLength in class MessageElement
Returns:
long containing the size of the element data.

getBytes

public byte[] getBytes(boolean copy)
Returns a byte array which contains the element data. The byte array returned may be shared amongst all copies of the element, do not modify it. The copy parameter allows you to request a private, modifiable copy of the element data.

This implementation builds the byte array from the stream.

Overrides:
getBytes in class MessageElement
Parameters:
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.
Returns:
byte[] Contents of message element.

getStream

public InputStream getStream()
                      throws IOException
Returns the stream of bytes which represents the content of this Document.

Returns:
An InputStream containing the bytes of this Document.
Throws:
IOException - For errors while writing the Document.

sendToStream

public void sendToStream(OutputStream sendTo)
                  throws IOException
Send the contents of this Document to the specified stream.

This version probably has sub-optimal performance. Sub-classes should override this implementation.

Specified by:
sendToStream in interface DocumentStreamIO
Overrides:
sendToStream in class MessageElement
Parameters:
sendTo - The OutputStream to which the Document will be written.
Throws:
IOException - For errors while writing the Document.

getMessage

public Message getMessage()
Returns a copy of the message which backs this element.

Returns:
Returns a copy of the message which backs this element.

JXSE