public class

MessageHeader

extends Object
java.lang.Object
   ↳ sun.net.www.MessageHeader

Class Overview

An RFC 844 or MIME message header. Includes methods for parsing headers from incoming streams, fetching values, setting values, and printing headers. Key values of null are legal: they indicate lines in the header that don't have a valid key, but do have a value (this isn't legal according to the standard, but lines like this are everywhere).

Summary

Public Constructors
MessageHeader()
MessageHeader(InputStream is)
Public Methods
synchronized void add(String k, String v)
Adds a key value pair to the end of the header.
static String canonicalID(String id)
Convert a message-id string to canonical form (strips off leading and trailing <>s)
synchronized Map filterAndAddHeaders(String[] excludeList, Map include)
synchronized String findNextValue(String k, String v)
Deprecated: Use multiValueIterator() instead.
synchronized String findValue(String k)
Find the value that corresponds to this key.
synchronized Map getHeaders()
synchronized Map getHeaders(String[] excludeList)
synchronized String getKey(int n)
synchronized int getKey(String k)
synchronized String getValue(int n)
void mergeHeader(InputStream is)
Parse and merge a MIME header from an input stream.
Iterator multiValueIterator(String k)
return an Iterator that returns all values of a particular key in sequence
void parseHeader(InputStream is)
Parse a MIME header from an input stream.
synchronized void prepend(String k, String v)
Prepends a key value pair to the beginning of the header.
synchronized void print(PrintStream p)
Prints the key-value pairs represented by this header.
synchronized void remove(String k)
Remove the key from the header.
synchronized void reset()
Reset a message header (all key/values removed)
synchronized void set(int i, String k, String v)
Overwrite the previous key/val pair at location 'i' with the new k/v.
synchronized void set(String k, String v)
Sets the value of a key.
synchronized void setIfNotSet(String k, String v)
Set's the value of a key only if there is no key with that value already.
synchronized String toString()
Returns a string representation of the object.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public MessageHeader ()

public MessageHeader (InputStream is)

Throws
IOException

Public Methods

public synchronized void add (String k, String v)

Adds a key value pair to the end of the header. Duplicates are allowed

public static String canonicalID (String id)

Convert a message-id string to canonical form (strips off leading and trailing <>s)

public synchronized Map filterAndAddHeaders (String[] excludeList, Map include)

public synchronized String findNextValue (String k, String v)

Deprecated: Use multiValueIterator() instead. Find the next value that corresponds to this key. It finds the first value that follows v. To iterate over all the values of a key use:

          for(String v=h.findValue(k); v!=null; v=h.findNextValue(k, v)) {
              ...
          }
  

public synchronized String findValue (String k)

Find the value that corresponds to this key. It finds only the first occurrence of the key.

Parameters
k the key to find.
Returns
  • null if not found.

public synchronized Map getHeaders ()

public synchronized Map getHeaders (String[] excludeList)

public synchronized String getKey (int n)

public synchronized int getKey (String k)

public synchronized String getValue (int n)

public void mergeHeader (InputStream is)

Parse and merge a MIME header from an input stream.

Throws
IOException

public Iterator multiValueIterator (String k)

return an Iterator that returns all values of a particular key in sequence

public void parseHeader (InputStream is)

Parse a MIME header from an input stream.

Throws
IOException

public synchronized void prepend (String k, String v)

Prepends a key value pair to the beginning of the header. Duplicates are allowed

public synchronized void print (PrintStream p)

Prints the key-value pairs represented by this header. Also prints the RFC required blank line at the end. Omits pairs with a null key.

public synchronized void remove (String k)

Remove the key from the header. If there are multiple values under the same key, they are all removed. Nothing is done if the key doesn't exist. After a remove, the other pairs' order are not changed.

Parameters
k the key to remove

public synchronized void reset ()

Reset a message header (all key/values removed)

public synchronized void set (int i, String k, String v)

Overwrite the previous key/val pair at location 'i' with the new k/v. If the index didn't exist before the key/val is simply tacked onto the end.

public synchronized void set (String k, String v)

Sets the value of a key. If the key already exists in the header, it's value will be changed. Otherwise a new key/value pair will be added to the end of the header.

public synchronized void setIfNotSet (String k, String v)

Set's the value of a key only if there is no key with that value already.

public synchronized String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.