Project JXTA

net.jxta.endpoint
Class TextDocumentMessageElement

java.lang.Object
  extended bynet.jxta.endpoint.MessageElement
      extended bynet.jxta.endpoint.TextMessageElement
          extended bynet.jxta.endpoint.TextDocumentMessageElement
All Implemented Interfaces:
Document, TextDocument

public class TextDocumentMessageElement
extends TextMessageElement

A Message Element using JXTA TextDocument for the element data.


Field Summary
protected  TextDocument doc
          The data for this element.
 
Fields inherited from class net.jxta.endpoint.TextMessageElement
cachedGetCharLength, cachedGetChars
 
Fields inherited from class net.jxta.endpoint.MessageElement
cachedGetByteLength, cachedGetBytes, cachedToString, name, properties, sig, type
 
Constructor Summary
TextDocumentMessageElement(String name, TextDocument doc, MessageElement sig)
          Create a new Message Element from the provided Document.
 
Method Summary
 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.

 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.

 long getCharLength()
          Returns the size of the element data in characters

synchronized for caching purposes.

 char[] getChars(boolean copy)
          Returns a char array which contains the element data. The char 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.

synchronized for caching purposes.

 String getFileExtension()
          Returns the file extension type used by this 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.

We use the "text" 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.

JXTA does not currently support the 'Multipart' or 'Message' media types.

Will return "Application/Octet-Stream" if no type was originally specified.

 Reader getReader()
          Returns the sequence of characters which represents the content of this TextDocument.
 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.

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

 void sendToWriter(Writer sendTo)
          Send the contents of this TextDocument to the specified Writer.

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

 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 enconding will be used.

synchronized for caching purposes.

synchronized for caching purposes.

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

Field Detail

doc

protected TextDocument doc
The data for this element.

Constructor Detail

TextDocumentMessageElement

public TextDocumentMessageElement(String name,
                                  TextDocument doc,
                                  MessageElement sig)
Create a new Message Element from the provided Document.

Parameters:
name - Name of the Element. May be the empty string ("") or null if the Element is not named.
doc - A Document containing the contents of this element.
sig - optional message digest/digital signature elemnent. If no signature is to be specified, pass null.
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 enconding will be used.

synchronized for caching purposes.

synchronized for caching purposes.

Specified by:
toString in interface TextDocument
Overrides:
toString in class TextMessageElement

getMimeType

public MimeMediaType getMimeType()
Returns the MIME Media type of this 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.

Specified by:
getMimeType in interface Document
Overrides:
getMimeType in class MessageElement

getFileExtension

public String getFileExtension()
Returns the file extension type used by this 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.

We use the "text" extension and leave it to sub-classes to extend this.

Specified by:
getFileExtension in interface Document
Overrides:
getFileExtension in class TextMessageElement

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 - if an I/O error occurs.

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 Document
Overrides:
sendToStream in class MessageElement
Throws:
IOException

getReader

public Reader getReader()
                 throws IOException
Returns the sequence of characters which represents the content of this TextDocument.

Specified by:
getReader in interface TextDocument
Specified by:
getReader in class TextMessageElement
Throws:
IOException

sendToWriter

public void sendToWriter(Writer sendTo)
                  throws IOException
Send the contents of this TextDocument to the specified Writer.

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

Specified by:
sendToWriter in interface TextDocument
Overrides:
sendToWriter in class TextMessageElement
Throws:
IOException

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.

getCharLength

public long getCharLength()
Returns the size of the element data in characters

synchronized for caching purposes.

Overrides:
getCharLength in class TextMessageElement
Returns:
long containing the size of the element data.

getChars

public char[] getChars(boolean copy)
Returns a char array which contains the element data. The char 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.

synchronized for caching purposes.

Overrides:
getChars in class TextMessageElement
Returns:
char[] Contents of message element.

JXTA J2SE