MessagePartpublic class MessagePart extends Object This class is defined by the JSR-205 specification
Wireless Messaging API (WMA)
Version 2.0. |
Fields Summary |
---|
static int | MAX_PART_SIZE_BYTESMaximum size for message part. | static final int | BUFFER_SIZEBuffer size 2048. | byte[] | contentContent byte array. | String | contentIDMIME Content ID. | String | contentLocationContent location. | String | encodingContent encoding. | String | mimeTypeMIME type. | static final char | US_ASCII_LOWEST_VALID_CHARLowest valid ASCII character. | static final char | US_ASCII_VALID_BIT_MASKMask for ASCII character checks. |
Constructors Summary |
---|
public MessagePart(byte[] contents, int offset, int length, String mimeType, String contentId, String contentLocation, String enc)
construct(contents, offset, length, mimeType, contentId,
contentLocation, enc);
| public MessagePart(byte[] contents, String mimeType, String contentId, String contentLocation, String enc)
construct(contents, 0, (contents == null ? 0 : contents.length),
mimeType, contentId, contentLocation, enc);
| public MessagePart(InputStream is, String mimeType, String contentId, String contentLocation, String enc)
// JAVADOC COMMENT ELIDED
byte[] bytes = {};
if (is != null) {
ByteArrayOutputStream accumulator = new ByteArrayOutputStream();
byte[] buffer = new byte[BUFFER_SIZE];
int readBytes = 0;
while ((readBytes = is.read(buffer)) != -1) {
accumulator.write(buffer, 0, readBytes);
}
bytes = accumulator.toByteArray();
}
construct(bytes, 0, bytes.length, mimeType, contentId,
contentLocation, enc);
|
Methods Summary |
---|
static void | checkContentID(java.lang.String contentId)Verifies the content identifier.
if (contentId == null) {
throw new IllegalArgumentException("contentId must be specified");
}
if (contentId.length() > 100) { // MMS Conformance limit
throw new IllegalArgumentException(
"contentId exceeds 100 char limit");
}
if (containsNonUSASCII(contentId)) {
throw new IllegalArgumentException(
"contentId must not contain non-US-ASCII characters");
}
| static void | checkContentLocation(java.lang.String contentLoc)Verifies the content location.
if (contentLoc != null) {
if (containsNonUSASCII(contentLoc)) {
throw new IllegalArgumentException(
"contentLocation must not contain non-US-ASCII characters");
}
if (contentLoc.length() > 100) { // MMS Conformance limit
throw new IllegalArgumentException(
"contentLocation exceeds 100 char limit");
}
}
| static void | checkEncodingScheme(java.lang.String encoding)Verifies the content encoding.
// IMPL_NOTE: check for a valid encoding scheme
| void | construct(byte[] contents, int offset, int length, java.lang.String mimeType, java.lang.String contentId, java.lang.String contentLocation, java.lang.String enc) // 30K
// JAVADOC COMMENT ELIDED
if (length > MAX_PART_SIZE_BYTES) {
throw new SizeExceededException(
"InputStream data exceeds " +
"MessagePart size limit");
}
if (mimeType == null) {
throw new IllegalArgumentException("mimeType must be specified");
}
checkContentID(contentId);
checkContentLocation(contentLocation);
if (length < 0) {
throw new IllegalArgumentException("length must be >= 0");
}
if (contents != null && offset + length > contents.length) {
throw new IllegalArgumentException(
"offset + length exceeds contents length");
}
if (offset < 0) {
throw new IllegalArgumentException("offset must be >= 0");
}
checkEncodingScheme(enc);
if (contents != null) {
this.content = new byte[length];
System.arraycopy(contents, offset, this.content, 0, length);
}
this.mimeType = mimeType;
this.contentID = contentId;
this.contentLocation = contentLocation;
this.encoding = enc;
| static boolean | containsNonUSASCII(java.lang.String str)Checks if a string contains non-ASCII characters.
int numChars = str.length();
for (int i = 0; i < numChars; ++i) {
char thisChar = str.charAt(i);
if (thisChar < US_ASCII_LOWEST_VALID_CHAR ||
thisChar != (thisChar & US_ASCII_VALID_BIT_MASK))
return true;
}
return false;
| public byte[] | getContent()
if (content == null) {
return null;
}
byte[] copyOfContent = new byte[content.length];
System.arraycopy(content, 0, copyOfContent, 0, content.length);
return copyOfContent;
| public java.io.InputStream | getContentAsStream()
if (content == null) {
return new ByteArrayInputStream(new byte[0]);
} else {
return new ByteArrayInputStream(content);
}
| public java.lang.String | getContentID()
return contentID;
| public java.lang.String | getContentLocation()
return contentLocation;
| public java.lang.String | getEncoding()
return encoding;
| public int | getLength()
return content == null ? 0 : content.length;
| public java.lang.String | getMIMEType()
return mimeType;
|
|