jCookie v0.8b

com.sonalb.net.http
Class Header

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--com.sonalb.net.http.Header
All Implemented Interfaces:
Cloneable, Collection, Serializable

public class Header
extends AbstractCollection
implements Serializable, 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(Collection c)
          Creates a Header, and populates it with HeaderEntries from input Collection.
Header(String topLine, Collection c)
          Creates a Header with given top-line, and populates it with HeaderEntries from input Collection.
 
Method Summary
 boolean add(Object entry)
          Ensures that this collection contains the specified element (optional operation).
 boolean add(String key, String value)
          Adds the specified key-value pair to this Header.
 Object clone()
           
 boolean containsKey(String s)
          Checks whether any header entry exists with given key.
 boolean containsValue(String s)
          Checks whether any header entry exists with given value.
 Header getEntriesForKey(String s)
          Returns a Header consisting of all HeaderEntries having given key.
 Header getEntriesForValue(String s)
          Returns a Header consisting of all HeaderEntries having given value.
 HeaderEntry getEntryAt(int index)
          Returns the entry at specified index.
 HeaderEntry getEntryForKey(String s, int j)
          Returns the HeaderEntry corresponding to the first occurrence of the given key, after specified index (non-inclusive).
 HeaderEntry getEntryForValue(String s, int j)
          Returns the HeaderEntry corresponding to the first occurrence of the given value, after specified index (non-inclusive).
 HeaderEntry getFirstEntryForKey(String s)
          Returns the HeaderEntry corresponding to the first occurrence of the given key.
 HeaderEntry getFirstEntryForValue(String s)
          Returns the HeaderEntry corresponding to the first occurrence of the given value.
 String getHeaderField(int i)
          Returns the header value for entry at specified index.
 String getHeaderFieldKey(int i)
          Returns the header key for entry at specified index.
 String getTopLine()
          Gets the top-line of this Header.
 boolean isEmpty()
          Returns true if this collection contains no elements.
 Iterator iterator()
          Returns an iterator over the elements contained in this collection.
 void setTopLine(String topLine)
          Sets the top-line of this Header.
 int size()
          Returns the number of elements in this collection.
 String toString()
          Returns a string representation of this collection.
 
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(Collection c)
Creates a Header, and populates it with HeaderEntries from input Collection.
Parameters:
c - the Collection containing HeaderEntry objects

Header

public Header(String topLine,
              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(String topLine)
Sets the top-line of this Header.
Parameters:
topLine - the top-most line in an HTTP Header

getTopLine

public String getTopLine()
Gets the top-line of this Header.
Returns:
the top-most line in an HTTP Header

add

public boolean add(String key,
                   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 String getHeaderFieldKey(int i)
Returns the header key for entry at specified index.

getHeaderField

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

containsKey

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

containsValue

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

getFirstEntryForKey

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

getFirstEntryForValue

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

getEntryForKey

public HeaderEntry getEntryForKey(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(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(String s)
Returns a Header consisting of all HeaderEntries having given key.

getEntriesForValue

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

add

public boolean add(Object entry)
Description copied from class: AbstractCollection
Ensures that this collection contains the specified element (optional operation). Returns true if the collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.) Collections that support this operation may place limitations on what elements may be added to the collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

This implementation always throws an UnsupportedOperationException.

Overrides:
add in class AbstractCollection
Following copied from class: java.util.AbstractCollection
Parameters:
o - element whose presence in this collection is to be ensured.
Returns:
true if the collection changed as a result of the call.
Throws:
UnsupportedOperationException - if the add method is not supported by this collection.
NullPointerException - if this collection does not permit null elements, and the specified element is null.
ClassCastException - if the class of the specified element prevents it from being added to this collection.
IllegalArgumentException - if some aspect of this element prevents it from being added to this collection.

iterator

public Iterator iterator()
Description copied from class: AbstractCollection
Returns an iterator over the elements contained in this collection.
Overrides:
iterator in class AbstractCollection
Following copied from class: java.util.AbstractCollection
Returns:
an iterator over the elements contained in this collection.

size

public int size()
Description copied from class: AbstractCollection
Returns the number of elements in this collection. If the collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.
Overrides:
size in class AbstractCollection
Following copied from class: java.util.AbstractCollection
Returns:
the number of elements in this collection.

toString

public String toString()
Description copied from class: AbstractCollection
Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (comma and space). Elements are converted to strings as by String.valueOf(Object).

This implementation creates an empty string buffer, appends a left square bracket, and iterates over the collection appending the string representation of each element in turn. After appending each element except the last, the string ", " is appended. Finally a right bracket is appended. A string is obtained from the string buffer, and returned.

Overrides:
toString in class AbstractCollection
Following copied from class: java.util.AbstractCollection
Returns:
a string representation of this collection.

isEmpty

public boolean isEmpty()
Description copied from class: AbstractCollection
Returns true if this collection contains no elements.

This implementation returns size() == 0.

Overrides:
isEmpty in class AbstractCollection
Following copied from class: java.util.AbstractCollection
Returns:
true if this collection contains no elements.

clone

public Object clone()
             throws CloneNotSupportedException

Copyright (c) 2001-2002 Sonal Bansal