Package sun.net.www
Class MessageHeader
- java.lang.Object
-
- sun.net.www.MessageHeader
-
public class MessageHeader extends Object
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).
-
-
Constructor Summary
Constructors Constructor Description MessageHeader()MessageHeader(InputStream is)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String k, String v)Adds a key value pair to the end of the header.static StringcanonicalID(String id)Convert a message-id string to canonical form (strips off leading and trailing <>s)Map<String,List<String>>filterAndAddHeaders(String[] excludeList, Map<String,List<String>> include)booleanfilterNTLMResponses(String k)Removes bare Negotiate and Kerberos headers when an "NTLM ..." appears.StringfindNextValue(String k, String v)Deprecated: Use multiValueIterator() instead.StringfindValue(String k)Find the value that corresponds to this key.StringgetHeaderNamesInList()Returns list of header names in a comma separated listMap<String,List<String>>getHeaders()Map<String,List<String>>getHeaders(String[] excludeList)StringgetKey(int n)intgetKey(String k)StringgetValue(int n)voidmergeHeader(InputStream is)Parse and merge a MIME header from an input stream.Iterator<String>multiValueIterator(String k)return an Iterator that returns all values of a particular key in sequencevoidparseHeader(InputStream is)Parse a MIME header from an input stream.voidprepend(String k, String v)Prepends a key value pair to the beginning of the header.voidprint(PrintStream p)Prints the key-value pairs represented by this header.voidremove(String k)Remove the key from the header.voidreset()Reset a message header (all key/values removed)voidset(int i, String k, String v)Overwrite the previous key/val pair at location 'i' with the new k/v.voidset(String k, String v)Sets the value of a key.voidsetIfNotSet(String k, String v)Set's the value of a key only if there is no key with that value already.StringtoString()Returns a string representation of the object.
-
-
-
Constructor Detail
-
MessageHeader
public MessageHeader()
-
MessageHeader
public MessageHeader(InputStream is) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getHeaderNamesInList
public String getHeaderNamesInList()
Returns list of header names in a comma separated list
-
reset
public void reset()
Reset a message header (all key/values removed)
-
findValue
@Nullable public String findValue(@Nullable 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.
-
findNextValue
@Nullable public String findNextValue(@Nullable 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)) { ... }
-
filterNTLMResponses
public boolean filterNTLMResponses(String k)
Removes bare Negotiate and Kerberos headers when an "NTLM ..." appears. All Performed on headers with key being k.- Returns:
- true if there is a change
-
multiValueIterator
public Iterator<String> multiValueIterator(String k)
return an Iterator that returns all values of a particular key in sequence
-
filterAndAddHeaders
public Map<String,List<String>> filterAndAddHeaders(@Nullable String[] excludeList, @Nullable Map<String,List<String>> include)
-
print
public 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.
-
add
public void add(String k, String v)
Adds a key value pair to the end of the header. Duplicates are allowed
-
prepend
public void prepend(String k, @Nullable String v)
Prepends a key value pair to the beginning of the header. Duplicates are allowed
-
set
public void set(int i, String k, @Nullable 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.
-
remove
public void remove(@Nullable 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
-
set
public 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.
-
setIfNotSet
public void setIfNotSet(String k, String v)
Set's the value of a key only if there is no key with that value already.
-
canonicalID
public static String canonicalID(@Nullable String id)
Convert a message-id string to canonical form (strips off leading and trailing <>s)
-
parseHeader
public void parseHeader(InputStream is) throws IOException
Parse a MIME header from an input stream.- Throws:
IOException
-
mergeHeader
public void mergeHeader(@Nullable InputStream is) throws IOException
Parse and merge a MIME header from an input stream.- Throws:
IOException
-
toString
public String toString()
Description copied from class:ObjectReturns a string representation of the object. In general, thetoStringmethod 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
toStringmethod for classObjectreturns 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())
-
-