net.sf.beep4j
Interface MessageBuilder

All Known Implementing Classes:
DefaultMessageBuilder

public interface MessageBuilder

A MessageBuilder allows to easily create Message objects. It has methods to set MIME headers. The content type and character encoding can be set with convenience methods.

To write something into the message you can either get the output stream or a writer. If you want to write binary data you should use the output stream. Otherwise, use the writer as it uses the correct charset encoder.

Finally, you can retrieve the completed message with the getMessage() method.

An example of a common use case is given below:

   MessageBuilder builder = ...;
   builder.setContentType("application", "beep+xml");
   builder.setCharacterEncoding("UTF-8");
   PrintWriter writer = new PrintWriter(builder.getWriter());
   writer.println("");
   Message message = writer.getMessage();
 

Author:
Simon Raess

Method Summary
 void addHeader(java.lang.String name, java.lang.String value)
          Adds an arbitrary header field.
 java.nio.ByteBuffer getContentBuffer(int size)
          Allocates a ByteBuffer into which the message content can be written.
 Message getMessage()
          Retrieves the resulting message object.
 java.io.OutputStream getOutputStream()
          Gets the underlying OutputStream that can be used to write binary messages.
 java.io.Writer getWriter()
          Gets the underlying Writer that can be used to write textual messages.
 void setCharsetName(java.lang.String charset)
          Sets the character encoding used by the message.
 void setContentType(java.lang.String type, java.lang.String subtype)
          Sets the content type of the message.
 

Method Detail

setContentType

void setContentType(java.lang.String type,
                    java.lang.String subtype)
Sets the content type of the message.

Parameters:
type - the type
subtype - the subtype

setCharsetName

void setCharsetName(java.lang.String charset)
Sets the character encoding used by the message.

Parameters:
charset - the charset

addHeader

void addHeader(java.lang.String name,
               java.lang.String value)
Adds an arbitrary header field.

Parameters:
name - the name of the header
value - the value

getOutputStream

java.io.OutputStream getOutputStream()
Gets the underlying OutputStream that can be used to write binary messages.

Returns:
the OutputStream

getWriter

java.io.Writer getWriter()
Gets the underlying Writer that can be used to write textual messages.

Returns:
the Writer

getContentBuffer

java.nio.ByteBuffer getContentBuffer(int size)
Allocates a ByteBuffer into which the message content can be written.

Parameters:
size - the size of the ByteBuffer
Returns:
an allocated ByteBuffer

getMessage

Message getMessage()
Retrieves the resulting message object.

Returns:
the Message object


Copyright © 2007 null. All Rights Reserved.