com.sonalb.net.http
Class Header

java.lang.Object
  extended by java.util.AbstractCollection
      extended by com.sonalb.net.http.Header
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection

public class Header
extends java.util.AbstractCollection
implements java.io.Serializable, java.lang.Cloneable

Represents the Header of an HTTP Message. An HTTP header usually consists of two major components:

This Header class does not consider the first line as a name-value pair as the HttpURLConnection class does.
NULL name fields in a pair are not permitted.

Author:
Sonal Bansal
See Also:
Serialized Form

Constructor Summary
Header()
          Creates an empty Header.
Header(java.util.Collection c)
          Creates a Header, and populates it with HeaderEntries from input Collection.
Header(java.lang.String topLine, java.util.Collection c)
          Creates a Header with given top-line, and populates it with HeaderEntries from input Collection.
 
Method Summary
 boolean add(java.lang.Object entry)
           
 boolean add(java.lang.String key, java.lang.String value)
          Adds the specified key-value pair to this Header.
 java.lang.Object clone()
           
 boolean containsKey(java.lang.String s)
          Checks whether any header entry exists with given key.
 boolean containsValue(java.lang.String s)
          Checks whether any header entry exists with given value.
 Header getEntriesForKey(java.lang.String s)
          Returns a Header consisting of all HeaderEntries having given key.
 Header getEntriesForValue(java.lang.String s)
          Returns a Header consisting of all HeaderEntries having given value.
 HeaderEntry getEntryAt(int index)
          Returns the entry at specified index.
 HeaderEntry getEntryForKey(java.lang.String s, int j)
          Returns the HeaderEntry corresponding to the first occurrence of the given key, after specified index (non-inclusive).
 HeaderEntry getEntryForValue(java.lang.String s, int j)
          Returns the HeaderEntry corresponding to the first occurrence of the given value, after specified index (non-inclusive).
 HeaderEntry getFirstEntryForKey(java.lang.String s)
          Returns the HeaderEntry corresponding to the first occurrence of the given key.
 HeaderEntry getFirstEntryForValue(java.lang.String s)
          Returns the HeaderEntry corresponding to the first occurrence of the given value.
 java.lang.String getHeaderField(int i)
          Returns the header value for entry at specified index.
 java.lang.String getHeaderFieldKey(int i)
          Returns the header key for entry at specified index.
 java.lang.String getTopLine()
          Gets the top-line of this Header.
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 void setTopLine(java.lang.String topLine)
          Sets the top-line of this Header.
 int size()
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
equals, hashCode
 

Constructor Detail

Header

public Header()
Creates an empty Header.


Header

public Header(java.util.Collection c)
Creates a Header, and populates it with HeaderEntries from input Collection.

Parameters:
c - the Collection containing HeaderEntry objects

Header

public Header(java.lang.String topLine,
              java.util.Collection c)
Creates a Header with given top-line, and populates it with HeaderEntries from input Collection.

Parameters:
c - the Collection containing HeaderEntry objects
topLine - the top-most line in an HTTP Header
Method Detail

setTopLine

public void setTopLine(java.lang.String topLine)
Sets the top-line of this Header.

Parameters:
topLine - the top-most line in an HTTP Header

getTopLine

public java.lang.String getTopLine()
Gets the top-line of this Header.

Returns:
the top-most line in an HTTP Header

add

public boolean add(java.lang.String key,
                   java.lang.String value)
Adds the specified key-value pair to this Header.


getEntryAt

public HeaderEntry getEntryAt(int index)
Returns the entry at specified index.


getHeaderFieldKey

public java.lang.String getHeaderFieldKey(int i)
Returns the header key for entry at specified index.


getHeaderField

public java.lang.String getHeaderField(int i)
Returns the header value for entry at specified index.


containsKey

public boolean containsKey(java.lang.String s)
Checks whether any header entry exists with given key.


containsValue

public boolean containsValue(java.lang.String s)
Checks whether any header entry exists with given value.


getFirstEntryForKey

public HeaderEntry getFirstEntryForKey(java.lang.String s)
Returns the HeaderEntry corresponding to the first occurrence of the given key.


getFirstEntryForValue

public HeaderEntry getFirstEntryForValue(java.lang.String s)
Returns the HeaderEntry corresponding to the first occurrence of the given value.


getEntryForKey

public HeaderEntry getEntryForKey(java.lang.String s,
                                  int j)
Returns the HeaderEntry corresponding to the first occurrence of the given key, after specified index (non-inclusive).


getEntryForValue

public HeaderEntry getEntryForValue(java.lang.String s,
                                    int j)
Returns the HeaderEntry corresponding to the first occurrence of the given value, after specified index (non-inclusive).


getEntriesForKey

public Header getEntriesForKey(java.lang.String s)
Returns a Header consisting of all HeaderEntries having given key.


getEntriesForValue

public Header getEntriesForValue(java.lang.String s)
Returns a Header consisting of all HeaderEntries having given value.


add

public boolean add(java.lang.Object entry)
Specified by:
add in interface java.util.Collection
Overrides:
add in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in class java.util.AbstractCollection

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in class java.util.AbstractCollection

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection
Overrides:
isEmpty in class java.util.AbstractCollection

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException