|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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();
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 |
---|
void setContentType(java.lang.String type, java.lang.String subtype)
type
- the typesubtype
- the subtypevoid setCharsetName(java.lang.String charset)
charset
- the charsetvoid addHeader(java.lang.String name, java.lang.String value)
name
- the name of the headervalue
- the valuejava.io.OutputStream getOutputStream()
java.io.Writer getWriter()
java.nio.ByteBuffer getContentBuffer(int size)
size
- the size of the ByteBuffer
Message getMessage()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |