com.ibm.wbi.util
Class MimeHeaderAscii

java.lang.Object
  |
  +--com.ibm.wbi.util.MimeHeaderAscii

public class MimeHeaderAscii
extends java.lang.Object

The MimeHeaderAscii class represents an RFC822-like MIME header, and includes several performace considerations, such as ASCII encoding and decoding, and fast case-insensitive header storage and lookup.


Field Summary
protected  boolean cached
           
protected  CIHashtable h
           
protected  java.lang.String header
           
protected  FastTokenizer lineTok
           
 
Constructor Summary
MimeHeaderAscii()
          Generate a new, empty MimeHeaderAscii.
MimeHeaderAscii(byte[] h)
          Generate a new MimeHeaderAscii from a buffer of bytes representing ASCII characters.
MimeHeaderAscii(byte[] h, int offset, int length)
          Generate a new MimeHeaderAscii from a buffer of bytes representing ASCII characters.
MimeHeaderAscii(MimeHeaderAscii old)
          Generate a new MimeHeaderAscii that is a copy of another.
MimeHeaderAscii(java.lang.String s)
          Generate a new MimeHeaderAscii.
 
Method Summary
 void add(java.lang.String key, HeaderField value)
          Set the value for a header field, adding to any previous values.
 void add(java.lang.String key, java.lang.String value)
          Set the value for a header field, adding to any previous values.
 byte[] asciiGetBytes()
          Return an ASCII-encoded byte-array representation of this MimeHeaderAscii.
static byte[] asciiGetBytes(java.lang.String s)
          Return an ASCII-encoded byte-array representation of the specified string.
 java.lang.Object clone()
          Return a clone of this MimeHeaderAscii.
 java.lang.String get(java.lang.String key)
          Get the value for a header field.
 java.util.Vector getAll(java.lang.String key)
          Get all values for a header field.
 java.lang.Object getRaw(java.lang.String key)
          Get the value for a header field.
protected  void internalParseHeader()
          Parse the Header and initialize values.
protected  void internalParseLine(java.lang.String line)
          Parse a header line and store its value.
 java.util.Enumeration keys()
          Return a list of all the header keys in this header.
static void main(java.lang.String[] argv)
          Test driver
 java.util.Vector parseAllHeaderFields(java.lang.String key)
          Like parseHeader(String), but returns a Vector of HeaderFields, one per instance of the named header field, even if the header field occurs zero or one times.
 java.util.Vector parseAllSplitHeaderFields(java.lang.String key)
          Calls parseAllSplitHeaderFields(String key, char delim) using the delimiter ",".
 java.util.Vector parseAllSplitHeaderFields(java.lang.String key, char delim)
          Like parseAllHeaderFields(String key)
 HeaderField parseHeaderField(java.lang.String key)
          Return the first value of the header field named by key as a parsed HeaderField object.
 boolean remove(java.lang.String key)
          Remove all value(s) for a header field.
 void set(java.lang.String key, HeaderField value)
          Set the value for a header field, replacing any previous value(s).
 void set(java.lang.String key, java.lang.String value)
          Set the value for a header field, replacing any previous value(s).
 java.lang.String toString()
          Return a String representation of this header, which is a valid MIME header, including empty-line termination.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

header

protected java.lang.String header

cached

protected boolean cached

h

protected CIHashtable h

lineTok

protected FastTokenizer lineTok
Constructor Detail

MimeHeaderAscii

public MimeHeaderAscii()
Generate a new, empty MimeHeaderAscii.

MimeHeaderAscii

public MimeHeaderAscii(byte[] h)
                throws MalformedHeaderException
Generate a new MimeHeaderAscii from a buffer of bytes representing ASCII characters.
Parameters:
h - The ASCII-encoded bytes of the header

MimeHeaderAscii

public MimeHeaderAscii(byte[] h,
                       int offset,
                       int length)
                throws MalformedHeaderException
Generate a new MimeHeaderAscii from a buffer of bytes representing ASCII characters.
Parameters:
h - The ASCII-encoded bytes of the header
offset - The offset within h at which the header begins
length - The length of the header in h

MimeHeaderAscii

public MimeHeaderAscii(java.lang.String s)
                throws MalformedHeaderException
Generate a new MimeHeaderAscii.
Parameters:
s - The header text

MimeHeaderAscii

public MimeHeaderAscii(MimeHeaderAscii old)
Generate a new MimeHeaderAscii that is a copy of another.
Parameters:
old - The header to copy.
Method Detail

clone

public java.lang.Object clone()
Return a clone of this MimeHeaderAscii.
Overrides:
clone in class java.lang.Object
Returns:
The cloned object

keys

public java.util.Enumeration keys()
Return a list of all the header keys in this header.
Returns:
The Enumeration

get

public java.lang.String get(java.lang.String key)
Get the value for a header field.
Parameters:
key - The case-insensitive name of the header field
Returns:
The single String value to which key is mapped, null if key is unmapped, or the first value if key is mapped to multiple values.

getAll

public java.util.Vector getAll(java.lang.String key)
Get all values for a header field.
Parameters:
key - The case-insensitive name of the header field
Returns:
A Vector containing all String values to which the key is mapped, even if zero or one.

getRaw

public java.lang.Object getRaw(java.lang.String key)
Get the value for a header field.
Parameters:
key - The case-insensitive name of the header field
Returns:
null if key is unmapped, or a HeaderField representing the single value to which key is mapped, or the Vector containing the one or more values to which key is mapped.

parseHeaderField

public HeaderField parseHeaderField(java.lang.String key)
Return the first value of the header field named by key as a parsed HeaderField object. If that HeaderField object is modified, then set() must be used to update the header itself: the HeaderField object is a copy, not a reference.
Parameters:
key - The name of the header field.
Returns:
The parsed HeaderField.
See Also:
set(String, HeaderField), HeaderField

parseAllHeaderFields

public java.util.Vector parseAllHeaderFields(java.lang.String key)
Like parseHeader(String), but returns a Vector of HeaderFields, one per instance of the named header field, even if the header field occurs zero or one times.
Parameters:
key - The name of the header field.
Returns:
The Vector of parsed HeaderFields
See Also:
parseHeaderField(String)

parseAllSplitHeaderFields

public java.util.Vector parseAllSplitHeaderFields(java.lang.String key,
                                                  char delim)
Like parseAllHeaderFields(String key)Accept: a/b, c/d would produce a vector of two HeaderField objects, one representing a/b, the other representing c/d.
Parameters:
key - The name of the header field.
Returns:
A Vector of HeaderField objects.
See Also:
parseHeaderField(String), parseAllHeaderFields(String key)

parseAllSplitHeaderFields

public java.util.Vector parseAllSplitHeaderFields(java.lang.String key)
Calls parseAllSplitHeaderFields(String key, char delim) using the delimiter ",".
Parameters:
key - the name of the header field.
Returns:
A Vector of HeaderField objects.
See Also:
parseHeaderField(String), parseAllSplitHeaderFields(String, char)

set

public void set(java.lang.String key,
                java.lang.String value)
Set the value for a header field, replacing any previous value(s).
Parameters:
key - The case-insensitive name of the header field.
value - The new value for the field.

set

public void set(java.lang.String key,
                HeaderField value)
Set the value for a header field, replacing any previous value(s).
Parameters:
key - The case-insensitive name of the header field.
value - The new value for the field.

add

public void add(java.lang.String key,
                java.lang.String value)
Set the value for a header field, adding to any previous values.
Parameters:
key - The case-insensitive name of the header field.
value - The new value to add.

add

public void add(java.lang.String key,
                HeaderField value)
Set the value for a header field, adding to any previous values.
Parameters:
key - The case-insensitive name of the header field.
value - The new value to add.

remove

public boolean remove(java.lang.String key)
Remove all value(s) for a header field.
Parameters:
key - The case-insensitive name of the header field
Returns:
true if all values were removed, false if key already had no value.

toString

public java.lang.String toString()
Return a String representation of this header, which is a valid MIME header, including empty-line termination.
Overrides:
toString in class java.lang.Object
Returns:
The String

asciiGetBytes

public static byte[] asciiGetBytes(java.lang.String s)
Return an ASCII-encoded byte-array representation of the specified string.
Parameters:
s - The string
Returns:
The byte-array representation

asciiGetBytes

public byte[] asciiGetBytes()
Return an ASCII-encoded byte-array representation of this MimeHeaderAscii.
Returns:
The byte-array representation

internalParseHeader

protected void internalParseHeader()
                            throws MalformedHeaderException
Parse the Header and initialize values. Not synchronized since it is only called from the constructor.

internalParseLine

protected void internalParseLine(java.lang.String line)
                          throws MalformedHeaderException
Parse a header line and store its value. Not synchronized since it is only called from the constructor.

main

public static void main(java.lang.String[] argv)
Test driver