javax.wireless.messaging
Class MessagePart

java.lang.Object
  extended by javax.wireless.messaging.MessagePart

public class MessagePart
extends 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 is possible to specify the content location and the encoding scheme.

This class is defined in JSR 205: Wireless Messaging API 2.0, which extends and enhances JSR 120: Wireless Messaging API

Since:
BlackBerry API 4.3.0, WMA 2.0

Constructor Summary
MessagePart(byte[] contents, int offset, int length, String mimeType, String contentId, String contentLocation, String enc)
          Constructs a MessagePart object from a subset of a byte array.
MessagePart(byte[] contents, String mimeType, String contentId, String contentLocation, String enc)
          Constructs a MessagePart object from a byte array.
MessagePart(InputStream is, String mimeType, String contentId, String contentLocation, String enc)
          Constructs a MessagePart object from an InputStream.
 
Method Summary
 byte[] getContent()
          Returns the content of the MessagePart as an array of bytes.
 InputStream getContentAsStream()
          Returns an InputStream for reading the contents of the MessagePart.
 String getContentID()
          Returns the content-id value of the MessagePart.
 String getContentLocation()
          Returns content location of the MessagePart.
 String getEncoding()
          Returns the encoding of the content as a String.
 int getLength()
          Returns the content size of this MessagePart.
 String getMIMEType()
          Returns the mime type of the MessagePart.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

MessagePart

public MessagePart(byte[] contents,
                   int offset,
                   int length,
                   String mimeType,
                   String contentId,
                   String contentLocation,
                   String enc)
            throws SizeExceededException
Constructs a MessagePart object from a subset of 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.
offset - the index in contents at which the data for this MessagePart begins.
length - the number of bytes from contents to be included in the MessagePart, starting at offset.
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:
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 (zero), offset+length exceeds the length of contents, offset is less than 0 (zero), 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.
Since:
BlackBerry API 4.3.0

MessagePart

public MessagePart(byte[] contents,
                   String mimeType,
                   String contentId,
                   String contentLocation,
                   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:
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 the specified encoding scheme is unknown.
SizeExceededException - if the contents is larger than the available memory or supported size for the message part.
Since:
BlackBerry API 4.3.0

MessagePart

public MessagePart(InputStream is,
                   String mimeType,
                   String contentId,
                   String contentLocation,
                   String enc)
            throws 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:
IOException - if the reading of the InputStream causes an exception other than EOFException
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 the specified encoding scheme is unknown.
SizeExceededException - if the contents is larger than the available memory or supported size for the message part.
Since:
BlackBerry API 4.3.0


Method Detail

getContent

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

Returns:
MessagePart data as byte array.
Throws:
OutOfMemoryError - if the data of this MessagePart is too large to fit in a byte array.
Since:
BlackBerry API 4.3.0

getContentAsStream

public 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; never returns null.
Since:
BlackBerry API 4.3.0

getContentID

public 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, which may happen if the message was sent from a non-JSR205-compliant client.
Since:
BlackBerry API 4.3.0

getContentLocation

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

Returns:
content location; may be null.
Since:
BlackBerry API 4.3.0

getEncoding

public String getEncoding()
Returns the encoding of the content as a String. For example, “US-ASCII”, “UTF-8”, “UTF-16”.

Returns:
encoding of the MessagePart content or null if the encoding scheme of the MessagePart cannot be determined.
Since:
BlackBerry API 4.3.0

getLength

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

Returns:
Content size (in bytes) of this MessagePart or 0 (zero) if the MessagePart is empty.
Since:
BlackBerry API 4.3.0

getMIMEType

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

Returns:
MIME type of the MessagePart; never returns null.
Since:
BlackBerry API 4.3.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal