com.ibm.etill.framework.io
Class MimeOutputStream

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

public final class MimeOutputStream
extends Object
implements MimeConst

This class defines a Mime wrapped OutputStream. It has methods to fill in fields of a MimeHeader, then it takes all the fields filled in and composes a Mime header, adds the message if any and sends everything trought a DataOutput stream.
This implementation is based on the SET book appendix E. It is able to handle the Mime fields describe in that book. But this implementation can easely be extended to handle new fields.
HOW TO USE
- connect this class to a DataOutputStream (done in the constructor)
- set the Mime fields using the setters writeXxxx()
- call writeMime() to really build the Mime header and write it to the DataOutputStream followed by a message
The message is a byte array.
BEWARE this class doesn't reset the fields if it is used to send a second message, it is up to the user to do so or to and a reset method.


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
MimeOutputStream(DataOutputStream dos)
          Creates a new MimeOutput stream to write data to a DataOutputStream.
 
Method Summary
 void setContentType(String content)
          Stores the content-type field to be used then the writeMime() method is called.
 void setContentTypeClass(String ctClass)
          Stores the content-type class field to be used then the writeMime() method is called.
 void setContentTypeControl(String ctControl)
          Stores the content-type control field to be used then the writeMime() method is called.
 void setContentTypeDelay(int ctDelay)
          Stores the content-type delay field to be used then the writeMime() method is called.
 void setContentTypeMsgTag(String ctMsgTag)
          Stores the content-type message tag field to be used then the writeMime() method is called.
 void setEncoding(String encoding)
          Stores the Encoding field to be used then the writeMime() method is called.
 void setLength(int length)
          Stores the Length field to be used then the writeMime() method is called.
 void setMessage(byte[] baMsg)
          Stores the byte array containing the message to be used then the writeMime() method is called.
 void writeMime()
          This method takes Mime fields and converts them into an OutputStream At least the content-type field has to be filled in.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MimeOutputStream

public MimeOutputStream(DataOutputStream dos)
Creates a new MimeOutput stream to write data to a DataOutputStream.
Parameters:
dos - the DataOutput stream
Method Detail

writeMime

public void writeMime()
               throws IOException
This method takes Mime fields and converts them into an OutputStream At least the content-type field has to be filled in. This method must be called after all the desired fields have been filled in. An IOException is thrown if the "content-type" is missing or if an error occured when writing to the DataOutputStream.

setContentType

public void setContentType(String content)
Stores the content-type field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
content - The content-type field

setContentTypeMsgTag

public void setContentTypeMsgTag(String ctMsgTag)
Stores the content-type message tag field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
ctMsgTag - The content-type message tag field

setContentTypeControl

public void setContentTypeControl(String ctControl)
Stores the content-type control field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
ctControl - The content-type control field

setContentTypeClass

public void setContentTypeClass(String ctClass)
Stores the content-type class field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
ctClass - The content-type class field

setContentTypeDelay

public void setContentTypeDelay(int ctDelay)
Stores the content-type delay field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
ctDelay - The content-type delay field

setEncoding

public void setEncoding(String encoding)
Stores the Encoding field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
encoding - The Encoding field

setLength

public void setLength(int length)
Stores the Length field to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
length - The Length field

setMessage

public void setMessage(byte[] baMsg)
Stores the byte array containing the message to be used then the writeMime() method is called. Call it before writeMime().
Parameters:
baMsg - The byte array