Project JXTA

net.jxta.endpoint
Class TextMessageElement

java.lang.Object
  extended bynet.jxta.endpoint.MessageElement
      extended bynet.jxta.endpoint.TextMessageElement
All Implemented Interfaces:
Document, TextDocument
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).


Field Summary
protected  long cachedGetCharLength
          cached result of getCharLength() operation.
protected  SoftReference cachedGetChars
          cached result of MessageElement.getBytes(boolean) operation.
 
Fields inherited from class net.jxta.endpoint.MessageElement
cachedGetByteLength, cachedGetBytes, cachedToString, name, properties, 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. 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.

abstract  Reader getReader()
          Returns the sequence of characters which represents the content of this TextDocument.
 void sendToWriter(Writer sendTo)
          Send the contents of this TextDocument to the specified Writer.

This version probably has sub-optimal performance.

 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, 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, getStream, sendToStream
 

Field Detail

cachedGetCharLength

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


cachedGetChars

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

synchronized for caching purposes.

synchronized for caching purposes.

Specified by:
toString in interface TextDocument
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

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.

Returns:
char[] Contents of message element.

getReader

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

Specified by:
getReader in interface TextDocument
Returns:
An Reader containing the characters of this TextDocument.
Throws:
IOException - if an I/O error occurs.

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
Parameters:
sendTo - The OutputStream to which the Document will be written.
Throws:
IOException - if an I/O error occurs.

JXTA J2SE