|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.wireless.messaging.MessagePart
public class MessagePart
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
| 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 |
|---|
public MessagePart(byte[] contents,
int offset,
int length,
String mimeType,
String contentId,
String contentLocation,
String enc)
throws SizeExceededException
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.
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.
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.
public MessagePart(byte[] contents,
String mimeType,
String contentId,
String contentLocation,
String enc)
throws SizeExceededException
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.
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.
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.
public MessagePart(InputStream is,
String mimeType,
String contentId,
String contentLocation,
String enc)
throws IOException,
SizeExceededException
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.
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.
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.| Method Detail |
|---|
public byte[] getContent()
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.
MessagePart data as byte array.
OutOfMemoryError - if the data of this MessagePart is too large to fit in
a byte array.public InputStream getContentAsStream()
InputStream for reading the contents of the MessagePart.
Returns an empty stream if no content is available.
InputStream that can be used for reading the contents of this
MessagePart; never returns null.public String getContentID()
MessagePart.
String, or null if the
content-id is not set, which may happen if the message was sent from a non-JSR205-compliant
client.public String getContentLocation()
MessagePart.
null.public String getEncoding()
String. For example, “US-ASCII”,
“UTF-8”, “UTF-16”.
MessagePart content or null if the encoding
scheme of the MessagePart cannot be determined.public int getLength()
MessagePart.
MessagePart or 0 (zero) if
the MessagePart is empty.public String getMIMEType()
MessagePart.
MessagePart; never returns null.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.