com.ibm.etill.framework.io
Class MimeInputStream

java.lang.Object
  |
  +--com.ibm.etill.framework.io.MimeInputStream
All Implemented Interfaces:
MimeConst

public final class MimeInputStream
extends Object
implements MimeConst

This class defines a Mime wrapped InputStream. It reads data from an Input stream, looks for the Mime header, processes it to extract the known fields. When the length is found, it reads the message that is Mime wrapped.
This implementation is based on the SET book appendix E. It is able to recognize the Mime fields describe in that book. If other Mime fields are present in the header they will be ignored.
This implementation can easely be extended to recognize new fields.
HOW TO USE IT
- connect this class to a TimeOutInputStream (done in the constructor)
- call readMime() to process the stream. If the TimeOutInputStream doesn't contain any MimeHeader an IOException is thrown.
- if the TimeOutInputStream does contain a Mime Header the getters readXxxx() can be called to retrieved the values of the fields.


Fields inherited from interface com.ibm.etill.framework.io.MimeConst
MAX_SIZE_MIMEHEADER, MHL_CTENCODING, MHL_CTENCODING_7BIT, MHL_CTENCODING_BIN, MHL_CTYPE, MHL_CTYPE_APP_PAYMENT, MHL_CTYPE_APP_REGISTRATION, MHL_CTYPE_CLASS, MHL_CTYPE_CLASS_CLOSING, MHL_CTYPE_CLASS_FAILED, MHL_CTYPE_CLASS_INFO, MHL_CTYPE_CLASS_RETRY, MHL_CTYPE_CONTROL, MHL_CTYPE_CONTROL_CLOSE, MHL_CTYPE_CONTROL_CLOSER, MHL_CTYPE_CONTROL_ECHO, MHL_CTYPE_CONTROL_ECHOR, MHL_CTYPE_CONTROL_STATUS, MHL_CTYPE_DELAY, MHL_CTYPE_MSGTAG, MHL_CTYPE_SEP, MHL_CTYPE_TXT, MHL_EOHEADER, MHL_EOL, MHL_EQUAL, MHL_LENGTH, MHL_MVERSION, MHL_SEP, MHL_SPACE, MHL_VERSION
 
Constructor Summary
MimeInputStream(TimeOutInputStream tois)
          Creates a new Mime input stream to read data from the specified TimeOut input stream.
 
Method Summary
 String getContentType()
          Returns the content-type field found after calling the readMime() method.
 String getContentTypeClass()
          Returns the content-type class field found after calling the readMime() method.
 String getContentTypeControl()
          Returns the content-type control field found after calling the readMime() method.
 int getContentTypeDelay()
          Returns the content-type delay field found after calling the readMime() method.
 String getContentTypeMsgTag()
          Returns the content-type message tag field found after calling the readMime() method.
 String getEncoding()
          Returns the encoding field found after calling the readMime() method.
 int getLength()
          Returns the Length field found after calling the readMime() method.
 byte[] getMessage()
          Returns the byte array containing the message found after calling the readMime() method.
 String getMimeVersion()
          Returns the Mime version field found after calling the readMime() method.
 void readMime()
          This method reads and parses a Mime wrapped TimeOutInputStream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeInputStream

public MimeInputStream(TimeOutInputStream tois)
Creates a new Mime input stream to read data from the specified TimeOut input stream.
Parameters:
tois - the TimeOut input stream
Method Detail

readMime

public void readMime()
              throws IOException
This method reads and parses a Mime wrapped TimeOutInputStream. This method must be called before any other method of this class because it reads the input Stream, processes it and fills in the fields. An IOException is thrown if no Mime header is found before MAX_SIZE_MIMEHEADER bytes are read.

getMimeVersion

public String getMimeVersion()
Returns the Mime version field found after calling the readMime() method.
Returns:
The Mime Version field

getContentType

public String getContentType()
Returns the content-type field found after calling the readMime() method.
Returns:
The content-type field

getContentTypeMsgTag

public String getContentTypeMsgTag()
Returns the content-type message tag field found after calling the readMime() method.
Returns:
The content-type message tag field

getContentTypeControl

public String getContentTypeControl()
Returns the content-type control field found after calling the readMime() method.
Returns:
The content-type control tag field

getContentTypeClass

public String getContentTypeClass()
Returns the content-type class field found after calling the readMime() method.
Returns:
The content-type class tag field

getContentTypeDelay

public int getContentTypeDelay()
Returns the content-type delay field found after calling the readMime() method.
Returns:
The content-type delay tag field

getEncoding

public String getEncoding()
Returns the encoding field found after calling the readMime() method.
Returns:
The encoding field

getLength

public int getLength()
Returns the Length field found after calling the readMime() method.
Returns:
The length field

getMessage

public byte[] getMessage()
Returns the byte array containing the message found after calling the readMime() method.
Returns:
a reference to the byte array