APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.net.www

public final Class MessageHeader

extends Object
Class Inheritance
Imports
java.io.*, java.lang.reflect.Array, java.net.ProtocolException, java.util.Collections, java.util.*

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).

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private String[]
private final int
private int
private long
private String[]

Constructor Summary

AccessConstructor and Description
public
public
MessageHeader(int maxHeaderSize)

public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
add(String k, String v)

Adds a key value pair to the end of the header.

public static String
canonicalID(String id)

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

private void
private long
checkNewSize(long size, int name, int value)

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

public boolean

Returns:

true if there is a change
filterNTLMResponses
(String k)

Removes bare Negotiate and Kerberos headers when an "NTLM ..." appears.

public synchronized String
findNextValue(String k, String v)

Deprecated: Use multiValueIterator() instead.

public synchronized String

Returns:

null if not found.
findValue
(String
the key to find.
k
)

Find the value that corresponds to this key.

public synchronized String
getHeaderNamesInList()

Returns list of header names in a comma separated list

public synchronized Map<String, List<String>>
public synchronized Map<String, List<String>>
getHeaders(String[] excludeList)

public synchronized int
public synchronized String
getKey(int n)

public synchronized String
getValue(int n)

private void
grow()

grow the key/value arrays as needed

private static boolean

Returns:

true if the line might be a request line.
isRequestline
(String
the line to check.
line
)

Check if a line of message header looks like a request line.

public void
mergeHeader(InputStream is)

Parse and merge a MIME header from an input stream.

public Iterator<String>
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.

public synchronized void
prepend(String k, String v)

Prepends a key value pair to the beginning of the header.

public synchronized void
remove(String
the key to remove
k
)

Remove the key from the header.

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.

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()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

keysback to summary
private String[] keys
maxHeaderSizeback to summary
private final int maxHeaderSize
nkeysback to summary
private int nkeys
sizeback to summary
private long size
valuesback to summary
private String[] values

Constructor Detail

MessageHeaderback to summary
public MessageHeader()
MessageHeaderback to summary
public MessageHeader(int maxHeaderSize)
MessageHeaderback to summary
public MessageHeader(InputStream is) throws IOException

Method Detail

addback to summary
public synchronized void add(String k, String v)

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

canonicalIDback to summary
public static String canonicalID(String id)

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

checkMaxHeaderSizeback to summary
private void checkMaxHeaderSize(int sz) throws ProtocolException
checkNewSizeback to summary
private long checkNewSize(long size, int name, int value) throws ProtocolException
filterAndAddHeadersback to summary
public synchronized Map<String, List<String>> filterAndAddHeaders(String[] excludeList, Map<String, List<String>> include)
filterNTLMResponsesback to summary
public boolean filterNTLMResponses(String k)

Removes bare Negotiate and Kerberos headers when an "NTLM ..." appears. All Performed on headers with key being k.

Returns:boolean

true if there is a change

findNextValueback to summary
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)) {
            ...
        }
findValueback to summary
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:String

the key to find.

Returns:String

null if not found.

getHeaderNamesInListback to summary
public synchronized String getHeaderNamesInList()

Returns list of header names in a comma separated list

getHeadersback to summary
public synchronized Map<String, List<String>> getHeaders()
getHeadersback to summary
public synchronized Map<String, List<String>> getHeaders(String[] excludeList)
getKeyback to summary
public synchronized int getKey(String k)
getKeyback to summary
public synchronized String getKey(int n)
getValueback to summary
public synchronized String getValue(int n)
growback to summary
private void grow()

grow the key/value arrays as needed

isRequestlineback to summary
private static boolean isRequestline(String line)

Check if a line of message header looks like a request line. This method does not perform a full validation but simply returns false if the line does not end with 'HTTP/[1-9].[0-9]'

Parameters
line:String

the line to check.

Returns:boolean

true if the line might be a request line.

mergeHeaderback to summary
public void mergeHeader(InputStream is) throws IOException

Parse and merge a MIME header from an input stream.

Annotations
@SuppressWarnings:fallthrough
multiValueIteratorback to summary
public Iterator<String> multiValueIterator(String k)

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

parseHeaderback to summary
public void parseHeader(InputStream is) throws IOException

Parse a MIME header from an input stream.

prependback to summary
public synchronized void prepend(String k, String v)

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

removeback to summary
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:String

the key to remove

resetback to summary
public synchronized void reset()

Reset a message header (all key/values removed)

setback to summary
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.

setback to summary
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.

setIfNotSetback to summary
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.

toStringback to summary
public synchronized String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

sun.net.www back to summary

pack-priv Class MessageHeader.HeaderIterator

extends Object
implements Iterator<String>
Class Inheritance
All Implemented Interfaces
java.util.Iterator

Field Summary

Modifier and TypeField and Description
pack-priv boolean
pack-priv int
pack-priv String
pack-priv Object
pack-priv int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public String
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

haveNextback to summary
pack-priv boolean haveNext
indexback to summary
pack-priv int index
keyback to summary
pack-priv String key
lockback to summary
pack-priv Object lock
nextback to summary
pack-priv int next

Constructor Detail

HeaderIteratorback to summary
public HeaderIterator(String k, Object lock)

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

nextback to summary
public String next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.