Package org.apache.james.mime4j.message
Class AbstractHeader
- java.lang.Object
-
- org.apache.james.mime4j.message.AbstractHeader
-
- Direct Known Subclasses:
HeaderImpl
public abstract class AbstractHeader extends java.lang.Object implements Header
Abstract MIME header.
-
-
Constructor Summary
Constructors Constructor Description AbstractHeader()Creates a new emptyHeader.AbstractHeader(Header other)Creates a newHeaderfrom the specifiedHeader.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddField(Field field)Adds a field to the end of the list of fields.FieldgetField(java.lang.String name)Gets aFieldgiven a field name.<F extends Field>
FgetField(java.lang.String name, java.lang.Class<F> clazz)Gets aFieldgiven a field name and of the given type.java.util.List<Field>getFields()Gets the fields of this header.java.util.List<Field>getFields(java.lang.String name)Gets allFields having the specified field name.<F extends Field>
java.util.List<F>getFields(java.lang.String name, java.lang.Class<F> clazz)Gets allFields having the specified field name and of the given type.java.util.Map<java.lang.String,java.util.List<Field>>getFieldsAsMap()Gets the fields of this header.java.util.Iterator<Field>iterator()Returns an iterator over the list of fields of this header.intremoveFields(java.lang.String name)Removes allFields having the specified field name.voidsetField(Field field)Sets or replaces a field.java.lang.StringtoString()Return Header Object as String representation.
-
-
-
Constructor Detail
-
AbstractHeader
public AbstractHeader()
Creates a new emptyHeader.
-
AbstractHeader
public AbstractHeader(Header other)
Creates a newHeaderfrom the specifiedHeader. TheHeaderinstance is initialized with a copy of the list ofFields of the specifiedHeader. TheFieldobjects are not copied because they are immutable and can safely be shared between headers.- Parameters:
other- header to copy.
-
-
Method Detail
-
addField
public void addField(Field field)
Adds a field to the end of the list of fields.
-
getFields
public java.util.List<Field> getFields()
Gets the fields of this header. The returned list will not be modifiable.
-
getFieldsAsMap
public java.util.Map<java.lang.String,java.util.List<Field>> getFieldsAsMap()
Gets the fields of this header. The returned map will not be modifiable. For each header name, values are ordered by which they appear in the underlying entity.- Specified by:
getFieldsAsMapin interfaceHeader- Returns:
- the map of
Fieldobjects indexed by names.
-
getField
public Field getField(java.lang.String name)
Gets aFieldgiven a field name. If there are multiple such fields defined in this header the first one will be returned.
-
getField
public <F extends Field> F getField(java.lang.String name, java.lang.Class<F> clazz)
Gets aFieldgiven a field name and of the given type. If there are multiple such fields defined in this header the first one will be returned.
-
getFields
public java.util.List<Field> getFields(java.lang.String name)
Gets allFields having the specified field name.
-
getFields
public <F extends Field> java.util.List<F> getFields(java.lang.String name, java.lang.Class<F> clazz)
Gets allFields having the specified field name and of the given type.
-
iterator
public java.util.Iterator<Field> iterator()
Returns an iterator over the list of fields of this header.
-
removeFields
public int removeFields(java.lang.String name)
Removes allFields having the specified field name.- Specified by:
removeFieldsin interfaceHeader- Parameters:
name- the field name (e.g. From, Subject).- Returns:
- number of fields removed.
-
setField
public void setField(Field field)
Sets or replaces a field. This method is useful for header fields such as Subject or Message-ID that should not occur more than once in a message. If thisHeaderdoes not already contain a header field of the same name as the given field then it is added to the end of the list of fields (same behavior asaddField(Field)). Otherwise the first occurrence of a field with the same name is replaced by the given field and all further occurrences are removed.
-
toString
public java.lang.String toString()
Return Header Object as String representation. Each headerline is seperated by "\r\n"- Overrides:
toStringin classjava.lang.Object- Returns:
- headers
-
-