javax.wireless.messaging
Class MessagePart

java.lang.Object
  extended byjavax.wireless.messaging.MessagePart

public class MessagePart
extends java.lang.Object

Instances of the MessagePart class can be added to a MultipartMessage. Each MessagePart consists of the content element, MIME type and content-id. The Content can be of any type. Additionally it's possible to specify the content location and the encoding scheme.

Since:
WMA 2.0

Constructor Summary
MessagePart(byte[] contents, int offset, int length, java.lang.String mimeType, java.lang.String contentId, java.lang.String contentLocation, java.lang.String enc)
          Constructs a MessagePart object from a subset of the byte array.
MessagePart(byte[] contents, java.lang.String mimeType, java.lang.String contentId, java.lang.String contentLocation, java.lang.String enc)
          Constructs a MessagePart object from a byte array.
MessagePart(java.io.InputStream is, java.lang.String mimeType, java.lang.String contentId, java.lang.String contentLocation, java.lang.String enc)
          Constructs a MessagePart object from an InputStream.
 
Method Summary
 boolean equals(java.lang.Object o)
          Compares two message parts for equality.
 byte[] getContent()
          Returns the content of the MessagePart as an array of bytes.
 java.io.InputStream getContentAsStream()
          Returns an InputStream for reading the contents of the MessagePart.
 java.lang.String getContentID()
          Returns the content-id value of the MessagePart
 java.lang.String getContentLocation()
          Returns content location of the MessagePart
 java.lang.String getEncoding()
          Returns the encoding of the content, e.g.
 int getLength()
          Returns the content size of this MessagePart
 java.lang.String getMIMEType()
          Returns the mime type of the MessagePart
 int hashCode()
          Returns the hash code of this message part.
 java.lang.String toString()
          Returns a string representation of this message part.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessagePart

public MessagePart(java.io.InputStream is,
                   java.lang.String mimeType,
                   java.lang.String contentId,
                   java.lang.String contentLocation,
                   java.lang.String enc)
            throws java.io.IOException,
                   SizeExceededException
Constructs a MessagePart object from an InputStream. The contents of the MessagePart are loaded from the InputStream during the constructor call until the end of stream is reached.

Parameters:
is - InputStream from which the contents of the MessagePart are read
mimeType - the MIME Content-Type for the MessagePart [RFC 2046]
contentId - the content-id header field value for the MessagePart [RFC 2045]. The content-id is unique over all MessageParts of a MultipartMessage and must always be set for each message part
contentLocation - the content location which specifies the file name of the file that is attached. If the content location is set to null no content location will be set for this MessagePart.
enc - the encoding scheme for the MessagePart. If enc is set to null no encoding will be used for this MessagePart.
Throws:
java.io.IOException - if the reading of the InputStream causes an exception other than EOFException
java.lang.IllegalArgumentException - if mimeType or contentId is null. This exception will be thrown if contentID or contentLocation contains other characters than specified in US-ASCII format or if the specified encoding scheme is unknown.
SizeExceededException - if the content from the InputStream is larger than the available memory or supported size for the message part.

MessagePart

public MessagePart(byte[] contents,
                   java.lang.String mimeType,
                   java.lang.String contentId,
                   java.lang.String contentLocation,
                   java.lang.String enc)
            throws SizeExceededException
Constructs a MessagePart object from a byte array. This constructor is only useful, if the data size is small (roughly less than 10K). For larger content the InputStream based constructor should be used.

Parameters:
contents - byte array containing the contents for the MessagePart. The contents of the array will be copied into the MessagePart.
mimeType - the MIME Content-Type for the MessagePart [RFC 2046]
contentId - the content-id header field value for the MessagePart [RFC 2045]. The content-id is unique over all MessageParts of a MultipartMessage and must always be set for each message part
contentLocation - the content location which specifies the file name of the file that is attached. If the content location is set to null no content location will be set for this MessagePart.
enc - the encoding scheme for the MessagePart. If enc is set to null no encoding will be used for this MessagePart.
Throws:
java.lang.IllegalArgumentException - if mimeType or contentId is null. This exception will be thrown if contentID or contentLocation contains other characters than specified in US-ASCII format or if the specified encoding scheme is unknown
SizeExceededException - if the contents is larger than the available memory or supported size for the message part.

MessagePart

public MessagePart(byte[] contents,
                   int offset,
                   int length,
                   java.lang.String mimeType,
                   java.lang.String contentId,
                   java.lang.String contentLocation,
                   java.lang.String enc)
            throws SizeExceededException
Constructs a MessagePart object from a subset of the byte array. This constructor is only useful, if the data size is small (roughly less than 10K). For larger content the InputStream based constructor should be used.

Parameters:
contents - byte array containing the contents for the MessagePart
offset - start position
length - the number of bytes to be included in the MessagePart
mimeType - the MIME Content-Type for the MessagePart [RFC 2046]
contentId - the content-id header field value for the MessagePart [RFC 2045]. The content-id is unique over all MessageParts of a MultipartMessage and must always be set for each message part
contentLocation - the content location which specifies the file name of the file that is attached. If the content location is set to null no content location will be set for this MessagePart.
enc - the encoding scheme for the MessagePart. If enc is set to null no encoding will be used for this MessagePart.
Throws:
java.lang.IllegalArgumentException - if mimeType or contentId is null. This exception will be thrown if contentID or contentLocation contains other characters than specified in US-ASCII format This exception will be thrown if either length is less than 0 or offset + length exceeds the length of the content or if offset is less than 0 or if the specified encoding scheme is unknown.
SizeExceededException - if the contents is larger than the available memory or supported size for the message part.
Method Detail

getContent

public byte[] getContent()
Returns the content of the MessagePart as an array of bytes. If it's not possible to create an array, which can contain all data, this method must throw an OutOfMemoryError.

Returns:
MessagePart data as byte array

getContentAsStream

public java.io.InputStream getContentAsStream()
Returns an InputStream for reading the contents of the MessagePart. Returns an empty stream if no content is available.

Returns:
an InputStream that can be used for reading the contents of this MessagePart

getContentID

public java.lang.String getContentID()
Returns the content-id value of the MessagePart

Returns:
the value of content-id as a String, or null if the content-id is not set It might happen if the message was sent from a not JSR 205 compliant client.

getMIMEType

public java.lang.String getMIMEType()
Returns the mime type of the MessagePart

Returns:
MIME type of the MessagePart

getEncoding

public java.lang.String getEncoding()
Returns the encoding of the content, e.g. "US-ASCII", "UTF-8", "UTF-16", ... as a String

Returns:
encoding of the MessagePart content or null if the encoding scheme of the MessagePart cannot be determined

getContentLocation

public java.lang.String getContentLocation()
Returns content location of the MessagePart

Returns:
content location

getLength

public int getLength()
Returns the content size of this MessagePart

Returns:
Content size (in bytes) of this MessagePart or 0 if the MessagePart is empty.

equals

public boolean equals(java.lang.Object o)
Compares two message parts for equality.


hashCode

public int hashCode()
Returns the hash code of this message part.

Returns:
hash code of message part

toString

public java.lang.String toString()
Returns a string representation of this message part.

Returns:
string representation


Copyright (C) 2004 Siemens AG, Germany. All rights reserved. Use is subject to license terms.