|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
net.rim.device.api.mime.MIMEInputStream
public class MIMEInputStream
Input stream for reading a MIME encoded data stream.
This class implements a stream which reads in a MIME message and formats
and parses the message into its constituent parts according to the MIME
standard.
Sample code
if( inputStream instanceof MIMEInputStream ) { MIMEInputStream mimeStream = (MIMEInputStream) inputStream; String contentType = mimeStream.getContentType(); if( contentType != null ) { if(contentType.startsWith( BodyPart.ContentType.TYPE_MULTIPART_ALTERNATIVE_STRING ) ) { // Could have also used : if(mimeStream.isMultipart()) MIMEInputStream[] innerParts = mimeStream.getParts(); for( int i = 0; i < innerParts.length; i++ ) { String mimeType = innerParts[i].getContentType(); String charset = innerParts[i].getContentTypeParameter( "charset" ); String encoding = innerParts[i].getHeader("Content-Transfer-Encoding"); if(encoding.equalsIgnoreCase("base64")) { SharedInputStream sis = innerParts[i].getRawMIMEInputStream(); .... } .... } } else if( contentType.startsWith( BodyPart.ContentType.TYPE_APPLICATION ) ) { byte[] buffer = new byte[mimeStream.available()]; mimeStream.read(buffer); } else if( contentType.startsWith( BodyPart.ContentType.TYPE_TEXT ) ) { // .... } // .... }
Constructor Summary | ||
---|---|---|
MIMEInputStream(InputStream input)
Creates a new MIMEInputStream instance. |
Method Summary | ||
---|---|---|
int |
available()
Retrieves number of available bytes. |
|
void |
close()
Closes this input stream. |
|
String |
getContentDescription()
Retrieves content description for this part. |
|
String |
getContentEncoding()
Retrieves this part's content encoding. |
|
String |
getContentID()
Retrieves this part's content ID. |
|
String |
getContentType()
Retrieves this part's content type. |
|
String |
getContentTypeParameter(String attribute)
Retrieves content type pararmeter by attribute. |
|
String |
getHeader(String headerFieldName)
Retrieve header content for named header. |
|
Enumeration |
getHeaders()
Retrieves enumeration of MIME headers. |
|
MIMEInputStream[] |
getParts()
Retrieves all parts in this multi-part message. |
|
SharedInputStream |
getRawMIMEInputStream()
Retrieves entire MIME part including headers. |
|
boolean |
isMultiPart()
Determines if this is a multi-part message. |
|
int |
isPartComplete()
Determines whether the entire contents of this MIME Part was read in or whether it was cutoff early. |
|
int |
read()
Reads one byte from this stream. |
|
int |
read(byte[] buffer)
Reads some bytes from this stream. |
|
int |
read(byte[] buffer,
int offset,
int length)
Read specified number of bytes from this stream. |
|
long |
skip(long n)
Skips over some bytes in this stream. |
Methods inherited from class java.io.InputStream |
---|
mark, markSupported, reset |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MIMEInputStream(InputStream input) throws MIMEParsingException
input
- Input stream from which to read MIME encoded data.
MIMEParsingException
- If error encountered parsing input data.Method Detail |
---|
public Enumeration getHeaders()
Invoke this method to retrieve an enumeration of the headers found in this MIME part, including the "Content-Type", "Content-ID", etc. in addition to any extension fields. Also note that
public String getHeader(String headerFieldName)
Invoke this method to retrieve the header content for a particular header. For example, given this header
Content-Type: text/plain; boundary=111invoking this method as
getHeader("Content-Type")
retrieves
the string "text/plain; boundary=111
".
headerFieldName
- Header name for which to retrieve the content.
public SharedInputStream getRawMIMEInputStream()
Invoke this method to retrieve this entire MIME part, including headers, in a shared input stream.
public boolean isMultiPart()
public int isPartComplete()
public MIMEInputStream[] getParts()
Invoke this method on a multi-part message to retrieve each contained part in a MIME input stream of its own.
public String getContentEncoding()
public String getContentType()
public String getContentTypeParameter(String attribute)
attribute
- Content type attribute key to look for.
public String getContentID()
public String getContentDescription()
public int read(byte[] buffer, int offset, int length) throws IOException
Invoke this method to read some bytes from this stream. Note that if this stream contains a multi-part message, this method reads bytes out of the first part.
read
in class InputStream
buffer
- Buffer to contain data; must be large enough to contain
desired number of bytes.offset
- First element in output parameter buffer at which to begin
writing data; if not 0 then output parameter buffer must be at least
offset + len
elements long.length
- Number of bytes to read from this stream.
IOException
- If an I/O error occurs.InputStream.read()
public int read() throws IOException
Invoke this method read one byte from this stream. Note that if this stream contains a multi-part message, this method reads the byte out of the first part.
This method blocks until input data is available, the end of the stream is detected (and then returns -1), or an exception is thrown.
read
in class InputStream
IOException
- If an I/O error occurs.public int read(byte[] buffer) throws IOException
Invoke this method to attempt to fill a provided output parameter byte array with data from this stream. Note that if this stream contains a multi-part message, this method reads bytes out of the first part.
read
in class InputStream
buffer
- Buffer to contain data.
IOException
- If an I/O error occurs.InputStream.read(byte[], int, int)
public long skip(long n) throws IOException
Invoke this method to skip the read position over a specified number of bytes in this stream, discarding the skipped bytes.
skip
in class InputStream
n
- Number of bytes to skip; if negative, an
IllegalArgumentException
is thrown by the underlying SharedInputStream
.
IOException
- Thrown if an I/O error occurs.public int available() throws IOException
Invoke this method to find out the number of bytes you can freely read (or skip over) from this stream (that is, without being blocked by another invocation of one of this stream's methods, on this or another thread).
Note that if this is a multi part message, the amount available is from the first part.
available
in class InputStream
IOException
- If an I/O error occurs.public void close() throws IOException
Invoke this method to close this stream and release any system resources it uses.
Note that if this is a multi part message, then the first part is closed.
close
in class InputStream
IOException
- If an I/O error occurs.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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