|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.Dictionary
sunlabs.brazil.util.StringMap
sunlabs.brazil.util.http.MimeHeaders (view source)
public class MimeHeaders
This class is build on top of the StringMap
class and
provides added methods that are of help when manipulating MIME headers.
By creating an instance of this class, the user can conveniently read,
write, and modify MIME headers.
Field Summary | |
---|---|
static int |
MAX_LINE
|
static int |
MAX_LINES
|
Constructor Summary | |
---|---|
MimeHeaders()
Creates a new, empty MimeHeaders object. |
|
MimeHeaders(HttpInputStream in)
Creates a new MimeHeaders object and then initializes
it by reading MIME headers from the specified input stream. |
Method Summary | |
---|---|
void |
add(String key,
int value)
Adds a mapping for the given case-insensitive key to the specified value in this MimeHeaders object. |
void |
copyTo(MimeHeaders other)
Copies the contents of this MimeHeaders object,
adding all the other's keys and values to the other. |
void |
print(OutputStream out)
Writes this MimeHeaders object to the given output
stream. |
void |
print(PrintStream out)
Writes this MimeHeaders object to the given output
stream. |
void |
put(String key,
int value)
Maps the given case-insensitive key to the specified value in this MimeHeaders object, replacing the old value. |
void |
putIfNotPresent(String key,
String value)
Maps the given case-insensitive key to the specified value if the key does not already exist in this MimeHeaders object. |
void |
read(HttpInputStream in)
Reads MIME headers from the specified input stream. |
void |
read(HttpInputStream in,
boolean shouldReplace)
Reads MIME headers from the specified input stream. |
Methods inherited from class sunlabs.brazil.util.StringMap |
---|
add, append, clear, elements, get, get, get, get, getKey, isEmpty, keys, put, put, put, remove, remove, remove, size, toString, toString |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int MAX_LINE
public static final int MAX_LINES
Constructor Detail |
---|
public MimeHeaders()
MimeHeaders
object.
public MimeHeaders(HttpInputStream in) throws IOException
MimeHeaders
object and then initializes
it by reading MIME headers from the specified input stream.
in
- The input stream to read.
IOException
Method Detail |
---|
public void read(HttpInputStream in) throws IOException
The MIME headers read from the input stream are stored in this
MimeHeaders
object. All headers read are added
to the existing headers; the new headers do not replace the
existing ones. The order of the headers in this object will
reflect the order of the headers from the input stream, but
space characters surrounding the keys and values are not preserved.
In a set of MIME headers, the given key may appear multiple times
(that is, on multiple lines, not necessarily consecutively).
In that case, that key will appear multiple times in this
MimeHeaders
object also. The HTTP spec says that
if a given key appears multiple times in a set of MIME headers, the
values can be concatenated together with commas
between them. However, in practice, it appears that some browsers
and HTTP servers get confused when encountering such collapsed
MIME headers, for instance, the Yahoo mail reader program.
MIME headers also support the idea of continuation lines, where
a key (and optionally its value) is followed on subsequent line(s) by
another value without a key. The HTTP spec says that in this case
the values can be concatenated together with space characters
between them. In practice, joining continuation lines together
does not seem to confuse any browsers or HTTP servers. This method
joins continuation lines together by putting the space-equivalent
characters "\r\n\t" between the values so it can be easily parsed
with StringTokenizer
and also easily written to
an output stream in a format that actually preserves its formatting
as a continuation line.
in
- The input stream to read from.
IOException
- if the input stream throws an IOException while being
read.public void read(HttpInputStream in, boolean shouldReplace) throws IOException
in
- The input stream to read from.shouldReplace
- If true, existing keys are replaced instead of
augmented.
IOException
- if the input stream throws an IOException while being
read.read(HttpInputStream in)
public void print(OutputStream out)
MimeHeaders
object to the given output
stream. This method does not
write a blank line after
the headers are written.
out
- The output stream.public void print(PrintStream out)
MimeHeaders
object to the given output
stream. This method does not
write a blank line after
the headers are written.
out
- The output stream.public void putIfNotPresent(String key, String value)
MimeHeaders
object.
Often, when dealing with MIME headers, the user will want to set a header only if that header is not already set.
key
- The new key. May not be null
.value
- The new value. May be null
.public void put(String key, int value)
MimeHeaders
object, replacing the old value.
This is convenience method that automatically converts the
integer value to a string before calling the underlying
put
method.
key
- The new key. May not be null
.value
- The new value.public void add(String key, int value)
MimeHeaders
object. It leaves any existing
key-value mapping alone.
This is convenience method that automatically converts the
integer value to a string before calling the underlying
add
method.
key
- The new key. May not be null
.value
- The new value.public void copyTo(MimeHeaders other)
MimeHeaders
object,
adding
all the other's keys and values to the other.
other
- The MimeHeaders
object to copy to.
|
Version Kenai-svn-r24, Generated 08/18/09 Copyright (c) 2001-2009, Sun Microsystems. |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |