rabbit.http
Class GeneralHeader

java.lang.Object
  extended by rabbit.http.GeneralHeader
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
HTTPFooter, HTTPHeader

public class GeneralHeader
extends java.lang.Object
implements java.io.Externalizable

A class to handle a general Header.

See Also:
Serialized Form

Nested Class Summary
protected static class GeneralHeader.Header
          This class holds a header value, that is a "type: some text"
 
Field Summary
static java.lang.String CRLF
          The String consisting of \r and \n
protected static java.util.Map<java.lang.String,java.lang.String> headerCache
          A cache of strings to keep the different strings down.
protected  java.util.List<GeneralHeader.Header> headers
          The headers of this Header in order.
protected static boolean strictHTTP
          If we should allow single \n to mean end of header
 
Constructor Summary
GeneralHeader()
          Create a new HTTPHeader from scratch
GeneralHeader(java.io.DataInputStream in)
          Create a new HTTPHeader from scratch
 
Method Summary
 void addHeader(java.lang.String type, java.lang.String value)
          Add a new header.
 void copyHeader(GeneralHeader to)
          Copy all headers in this header to the given header.
protected static java.lang.String getCachedString(java.lang.String s)
           
 java.lang.String getHeader(java.lang.String type)
          get the value of header type
 java.util.List<java.lang.String> getHeaders(java.lang.String type)
          Get all headers of a specified type...
 void readExternal(java.io.ObjectInput in)
           
 void readHeader(java.io.DataInputStream in)
          Read in this header from the given Stream.
 void readHeader(java.io.DataInputStream in, java.lang.String firstline)
          Read in this header from the given Stream.
static java.lang.String readLine(java.io.DataInputStream in)
           
 void removeHeader(java.lang.String type)
          removes a headerline from this header
 void removeValue(java.lang.String value)
          removes a header with the specified value
 void setExistingValue(java.lang.String current, java.lang.String newValue)
          Set a specified header
 void setHeader(java.lang.String type, java.lang.String value)
          Set or replaces a value for given type.
static void setStrictHTTP(boolean b)
          Should headers be parsed with strict HTTP or not?
 java.lang.String toString()
          Get the text value of this header
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

headers

protected java.util.List<GeneralHeader.Header> headers
The headers of this Header in order.


CRLF

public static final java.lang.String CRLF
The String consisting of \r and \n

See Also:
Constant Field Values

strictHTTP

protected static boolean strictHTTP
If we should allow single \n to mean end of header


headerCache

protected static java.util.Map<java.lang.String,java.lang.String> headerCache
A cache of strings to keep the different strings down.

Constructor Detail

GeneralHeader

public GeneralHeader()
Create a new HTTPHeader from scratch


GeneralHeader

public GeneralHeader(java.io.DataInputStream in)
              throws java.io.IOException
Create a new HTTPHeader from scratch

Throws:
java.io.IOException
Method Detail

setStrictHTTP

public static void setStrictHTTP(boolean b)
Should headers be parsed with strict HTTP or not?


getCachedString

protected static java.lang.String getCachedString(java.lang.String s)

readHeader

public void readHeader(java.io.DataInputStream in)
                throws java.io.IOException
Read in this header from the given Stream. This actually merges the current header with the one beeing read.

Parameters:
in - the Stream to read the header from.
Throws:
java.io.IOException

readLine

public static java.lang.String readLine(java.io.DataInputStream in)
                                 throws java.io.IOException
Throws:
java.io.IOException

readHeader

public void readHeader(java.io.DataInputStream in,
                       java.lang.String firstline)
                throws java.io.IOException
Read in this header from the given Stream. This actually merges the current header with the one beeing read. This method is a convinience to have the abbility to read past the initial data before the header is read.

Parameters:
in - the Stream to read the header from.
firstline - the first line of this header.
Throws:
java.io.IOException

toString

public java.lang.String toString()
Get the text value of this header

Overrides:
toString in class java.lang.Object
Returns:
a String describing this GeneralHeader.

getHeader

public java.lang.String getHeader(java.lang.String type)
get the value of header type

Parameters:
type - the Header were intrested in.
Returns:
the value of type or null if no value is set.

setHeader

public void setHeader(java.lang.String type,
                      java.lang.String value)
Set or replaces a value for given type.

Parameters:
type - the type or category that we want to set.
value - the value we want to set

setExistingValue

public void setExistingValue(java.lang.String current,
                             java.lang.String newValue)
Set a specified header

Parameters:
current - the type or category that we want to set.
newValue - the value we want to set

addHeader

public void addHeader(java.lang.String type,
                      java.lang.String value)
Add a new header. Old headers of the same type remain. The new header is placed last.

Parameters:
type - the type or category that we want to set.
value - the value we want to set

removeHeader

public void removeHeader(java.lang.String type)
removes a headerline from this header

Parameters:
type - the type we want to remove

removeValue

public void removeValue(java.lang.String value)
removes a header with the specified value

Parameters:
value - the value of the header we want to remove

getHeaders

public java.util.List<java.lang.String> getHeaders(java.lang.String type)
Get all headers of a specified type...

Parameters:
type - the type of the headers to get, eg. "Cache-Control".

copyHeader

public void copyHeader(GeneralHeader to)
Copy all headers in this header to the given header.

Parameters:
to - the GeneralHeader to add headers to.

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException