1 /*
2 * Copyright 2006 Simon Raess
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.beep4j;
17
18 import java.io.InputStream;
19 import java.io.Reader;
20 import java.nio.ByteBuffer;
21 import java.util.Iterator;
22
23 /**
24 * Interface exposing all necessary methods a Message must have.
25 *
26 * @author Simon Raess
27 */
28 public interface Message {
29
30 /**
31 * Canonical name of the Content-Type header.
32 */
33 String CONTENT_TYPE = "content-type";
34
35 /**
36 * Canonical name of the Content-Transfer-Encoding header.
37 */
38 String CONTENT_TRANSFER_ENCODING = "content-transfer-encoding";
39
40 /**
41 * Value for binary transfer encoding.
42 */
43 String BINARY_TRANSFER_ENCODING = "binary";
44
45 /**
46 * Value for base64 transfer encoding.
47 */
48 String BASE64_TRANSFER_ENCODING = "base64";
49
50 /**
51 * Gets the content type of the message. The format of the
52 * content type is defined in RFC 2045. The returned
53 * value does not contain parameters.
54 *
55 * @return the content type of the message
56 */
57 String getContentType();
58
59 /**
60 * Gets the list of all defined header names. The content type
61 * header is not returned from this method.
62 *
63 * @return the list of header names
64 */
65 Iterator<String> getHeaderNames();
66
67 /**
68 * Gets the value of the header with the given name.
69 * If no such header exists, null is returned. The content type
70 * header is not returned from this method.
71 *
72 * @param name the name of the header
73 * @return the value of the header
74 */
75 String getHeader(String name);
76
77 /**
78 * Gets an InputStream to read the content of the message.
79 * Use this method if you receive binary messages. Otherwise
80 * we recommend using the {@link #getReader()} method, which
81 * returns a fully configured Reader.
82 *
83 * @return the raw InputStream
84 */
85 InputStream getInputStream();
86
87 /**
88 * Gets a Reader to read the content of the message.
89 * Use this method to process textual messages. The
90 * reader is fully configured, e.g. the correct charset is
91 * used to decode the binary content.
92 *
93 * @return a fully configured Reader
94 */
95 Reader getReader();
96
97 /**
98 * Gets a Reader to read the content of the message.
99 * Use this method if the charset has not been specified as
100 * part of the content-type and there is no default charset
101 * for the content type.
102 *
103 * @param charset the name of the charset
104 * @return the fully configured Reader
105 */
106 Reader getReader(String charset);
107
108 /**
109 * Gets the content as a ByteBuffer.
110 *
111 * @return the ByteBuffer of the content
112 */
113 ByteBuffer getContentBuffer();
114
115 /**
116 * Writes the complete message (headers and content) into a
117 * ByteBuffer, which can then be used to send the message over
118 * the network.
119 *
120 * @return the Message written into a ByteBuffer
121 */
122 ByteBuffer asByteBuffer();
123
124 }