ikrs.httpd
Class HTTPHeaderLine

java.lang.Object
  extended by ikrs.util.KeyValuePair<java.lang.String,java.lang.String>
      extended by ikrs.util.KeyValueStringPair
          extended by ikrs.httpd.HTTPHeaderLine
All Implemented Interfaces:
java.lang.Comparable<HTTPHeaderLine>

public final class HTTPHeaderLine
extends KeyValueStringPair
implements java.lang.Comparable<HTTPHeaderLine>

The HTTPHeaderLine class is very simple datastructure to hold single HTTP header lines (each line represents a key/value pair). It can also be used to parse one header line after the other. Note: instances of this class are and have to be immutable!


Constructor Summary
HTTPHeaderLine(java.lang.String key, java.lang.String value)
          This is a private constructor and not meant to be public.
 
Method Summary
 int compareTo(HTTPHeaderLine element)
          This method implements Comparable.compareTo(...).
 boolean equals(HTTPHeaderLine element)
          This method returns true if (and only if) this and 'element' are equal.
 boolean equals(java.lang.Object element)
          This method returns true if (and only if) this and the passed element are equal.
 byte[] getRawBytes(java.nio.charset.Charset charset)
          Get the raw byte data for this header line.
 boolean isResponseStatus()
          Get the value of this header line.
static HTTPHeaderLine parse(java.lang.String line)
          This method parses header lines.
static HTTPHeaderLine read(java.io.InputStream in)
          Read the next header line from the input stream.
 java.lang.String toString()
          Converts this key-value-pair into a human readable form.
 
Methods inherited from class ikrs.util.KeyValueStringPair
main, split, split, split
 
Methods inherited from class ikrs.util.KeyValuePair
getKey, getValue, splitLine
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HTTPHeaderLine

public HTTPHeaderLine(java.lang.String key,
                      java.lang.String value)
This is a private constructor and not meant to be public.

Method Detail

isResponseStatus

public boolean isResponseStatus()
Get the value of this header line.


compareTo

public int compareTo(HTTPHeaderLine element)
This method implements Comparable.compareTo(...). It returns zero if this and 'element' are equal. It returns a negative value if this is smaller than 'element'. It returns a positive value if this is larger than 'element'.

Specified by:
compareTo in interface java.lang.Comparable<HTTPHeaderLine>
Parameters:
element - The HTTPHeaderLine to compare with.

getRawBytes

public byte[] getRawBytes(java.nio.charset.Charset charset)
Get the raw byte data for this header line.


equals

public boolean equals(HTTPHeaderLine element)
This method returns true if (and only if) this and 'element' are equal. Equal means that both keys and both values are equal.


equals

public boolean equals(java.lang.Object element)
This method returns true if (and only if) this and the passed element are equal. If 'element' is not a HTTPHeaderLine instance the method returns false.

Overrides:
equals in class java.lang.Object

read

public static HTTPHeaderLine read(java.io.InputStream in)
                           throws java.io.EOFException,
                                  java.io.IOException
Read the next header line from the input stream. Note that only CR-LF is accepted as a HTTP entity line break! Single CR single LF will _not_ instruct the reader to stop! If the read line is empty this method will return null! You should use it to read the whole set of http headers from a given input: InputStream in = ...; HTTPHeaderLine hl; while( (hl = read(in)) != null ) { // Handle header line } // End of headers reached

Parameters:
in - The InputStream to read from.
Throws:
java.io.EOFException
java.io.IOException

parse

public static HTTPHeaderLine parse(java.lang.String line)
This method parses header lines. Usually a header line consists of a key- and a value-part, separated by a colon (':'). As the value part may contain colons itself, the first appearance of ':' is taken as the separator. If null is passed, the method returns a null header line! If the key and/or value are empty, a header line with the empty string "" as key and/or value is returned. Keys and values are trimmed (whitespace at beginning and end are cut off).

Parameters:
line - The header line from the HTTP headers.
Returns:
The parsed HTTPHeaderLine.

toString

public java.lang.String toString()
Description copied from class: KeyValuePair
Converts this key-value-pair into a human readable form.

Overrides:
toString in class KeyValuePair<java.lang.String,java.lang.String>