JXTA

net.jxta.endpoint
Class TextMessageElement

java.lang.Object
  extended by net.jxta.endpoint.MessageElement
      extended by net.jxta.endpoint.TextMessageElement
All Implemented Interfaces:
Document, DocumentStreamIO, TextDocument, TextDocumentReaderIO
Direct Known Subclasses:
StringMessageElement, TextDocumentMessageElement

public abstract class TextMessageElement
extends MessageElement
implements TextDocument

An extension of MessageElement for managing elements that are composed of character text. (as opposed to raw bytes).

The data contained within a TextMessageElement is accessible in three additional ways to those provided by MessageElement :


Field Summary
protected  long cachedGetCharLength
          cached result of getCharLength() operation.
protected  SoftReference<char[]> cachedGetChars
          cached result of MessageElement.getBytes(boolean) operation.
 
Fields inherited from class net.jxta.endpoint.MessageElement
cachedGetByteLength, cachedGetBytes, cachedToString, name, sig, type
 
Constructor Summary
protected TextMessageElement(String name, MimeMediaType type, MessageElement sig)
          Internal constructor for initializaing everything but the data.
 
Method Summary
 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.
 String getFileExtension()
          Returns the file extension type used by this Document.
 void sendToWriter(Writer sendTo)
          Send the contents of this TextDocument to the specified Writer.
 String toString()
          

Returns a String representation of the element data.

 
Methods inherited from class net.jxta.endpoint.MessageElement
clone, copyInputStreamToOutputStream, equals, getByteLength, getBytes, getElementName, getElementProperty, getMimeType, getSequentialName, getSignature, getUniqueName, hashCode, sendToStream, setElementProperty
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.jxta.document.Document
getMimeType
 
Methods inherited from interface net.jxta.document.DocumentStreamIO
getStream, sendToStream
 
Methods inherited from interface net.jxta.document.TextDocumentReaderIO
getReader
 

Field Detail

cachedGetCharLength

protected transient long cachedGetCharLength
cached result of getCharLength() operation.


cachedGetChars

protected transient SoftReference<char[]> cachedGetChars
cached result of MessageElement.getBytes(boolean) operation.

Constructor Detail

TextMessageElement

protected TextMessageElement(String name,
                             MimeMediaType type,
                             MessageElement sig)
Internal constructor for initializaing everything but the data.

Parameters:
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

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.

synchronized for caching purposes.

Overrides:
toString 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 MessageElement
Returns:
An appropriate file extension for this Document.

getCharLength

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

synchronized for caching purposes.

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.

Parameters:
copy - return a copy if true
Returns:
char[] Contents of message element.

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 TextDocumentReaderIO
Parameters:
sendTo - The Writer to which the characters of the TextDocument will be written.
Throws:
IOException - If an I/O error occurs.

JXSE