gnu.java.net.protocol.http

Class Headers

Implemented Interfaces:
Cloneable, Map, Serializable

public class Headers
extends LinkedHashMap

A collection of HTTP header names and associated values. Retrieval of values is case insensitive. An iteration over the keys returns the header names in the order they were received.
See Also:
Serialized Form

Constructor Summary

Headers()
The basic constructor.

Method Summary

boolean
containsKey(Object key)
Returns true if this contains a mapping for the given key.
Set
entrySet()
Returns a set view of the mappings in this Map.
Object
get(Object key)
Returns the value mapped by the given key.
Date
getDateValue(String header)
Returns the value of the specified header as a date, or null if the header is not present or not a date.
int
getIntValue(String header)
Returns the value of the specified header as an integer, or -1 if the header is not present or not an integer.
long
getLongValue(String header)
Returns the value of the specified header as a long, or -1 if the header is not present or cannot be parsed as a long.
String
getValue(String header)
Returns the value of the specified header as a string.
Set
keySet()
Returns a set view of the keys in this Map.
void
parse(InputStream in)
Parse the specified input stream, adding headers to this collection.
Object
put(Object key, Object value)
Associates the given key to the given value (optional operation).
void
putAll(Map t)
Copies all entries of the given map to this one (optional operation).
Object
remove(Object key)
Removes the mapping for this key if present (optional operation).

Methods inherited from class java.util.LinkedHashMap

clear, containsValue, get, removeEldestEntry

Methods inherited from class java.util.HashMap

clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values

Methods inherited from class java.util.AbstractMap

clear, clone, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Headers

public Headers()
The basic constructor. Object is special, because it has no superclass, so there is no call to super().

Method Details

containsKey

public boolean containsKey(Object key)
Returns true if this contains a mapping for the given key.
Specified by:
containsKey in interface Map
Overrides:
containsKey in interface HashMap
Parameters:
key - the key to search for
Returns:
true if the map contains the key
Throws:
ClassCastException - if the key is of an inappropriate type
NullPointerException - if key is null but the map does not permit null keys

entrySet

public Set entrySet()
Returns a set view of the mappings in this Map. Each element in the set is a Map.Entry. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this set.
Specified by:
entrySet in interface Map
Overrides:
entrySet in interface HashMap
Returns:
the set view of all mapping entries
See Also:
Map.Entry

get

public Object get(Object key)
Returns the value mapped by the given key. Returns null if there is no mapping. However, in Maps that accept null values, you must rely on containsKey to determine if a mapping exists.
Specified by:
get in interface Map
Overrides:
get in interface LinkedHashMap
Parameters:
key - the key to look up
Returns:
the value associated with the key, or null if key not in map
Throws:
ClassCastException - if the key is an inappropriate type
NullPointerException - if this map does not accept null keys

getDateValue

public Date getDateValue(String header)
Returns the value of the specified header as a date, or null if the header is not present or not a date.

getIntValue

public int getIntValue(String header)
Returns the value of the specified header as an integer, or -1 if the header is not present or not an integer.

getLongValue

public long getLongValue(String header)
Returns the value of the specified header as a long, or -1 if the header is not present or cannot be parsed as a long.

getValue

public String getValue(String header)
Returns the value of the specified header as a string.

keySet

public Set keySet()
Returns a set view of the keys in this Map. The set is backed by the map, so that changes in one show up in the other. Modifications made while an iterator is in progress cause undefined behavior. If the set supports removal, these methods remove the underlying mapping from the map: Iterator.remove, Set.remove, removeAll, retainAll, and clear. Element addition, via add or addAll, is not supported via this set.
Specified by:
keySet in interface Map
Overrides:
keySet in interface HashMap
Returns:
the set view of all keys

parse

public void parse(InputStream in)
            throws IOException
Parse the specified input stream, adding headers to this collection.

put

public Object put(Object key,
                  Object value)
Associates the given key to the given value (optional operation). If the map already contains the key, its value is replaced. Be aware that in a map that permits null values, a null return does not always imply that the mapping was created.
Specified by:
put in interface Map
Overrides:
put in interface HashMap
Parameters:
key - the key to map
value - the value to be mapped
Returns:
the previous value of the key, or null if there was no mapping
Throws:
UnsupportedOperationException - if the operation is not supported
ClassCastException - if the key or value is of the wrong type
IllegalArgumentException - if something about this key or value prevents it from existing in this map
NullPointerException - if either the key or the value is null, and the map forbids null keys or values

putAll

public void putAll(Map t)
Copies all entries of the given map to this one (optional operation). If the map already contains a key, its value is replaced.
Specified by:
putAll in interface Map
Overrides:
putAll in interface HashMap
Parameters:
Throws:
UnsupportedOperationException - if the operation is not supported
ClassCastException - if a key or value is of the wrong type
IllegalArgumentException - if something about a key or value prevents it from existing in this map
NullPointerException - if the map forbids null keys or values, or if m is null.

remove

public Object remove(Object key)
Removes the mapping for this key if present (optional operation). If the key is not present, this returns null. Note that maps which permit null values may also return null if the key was removed.
Specified by:
remove in interface Map
Overrides:
remove in interface HashMap
Parameters:
key - the key to remove
Returns:
the value the key mapped to, or null if not present.
Throws:
UnsupportedOperationException - if deletion is unsupported
NullPointerException - if the key is null and this map doesn't support null keys.
ClassCastException - if the type of the key is not a valid type for this map.

Headers.java -- Copyright (C) 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.