public class HeaderCollection
extends java.lang.Object
implements java.io.Serializable
HeaderCollection
- Represents a collection of RFC822
headers.Modifier and Type | Field and Description |
---|---|
static HeaderCollection |
EMPTY_COLLECTION
Read-only constant for an empty header collection
|
Constructor and Description |
---|
HeaderCollection()
Initializes a new
HeaderCollection with a default initial capacity of 40 . |
HeaderCollection(HeaderCollection headers)
Copy constructor for
HeaderCollection |
HeaderCollection(java.io.InputStream inputStream)
Initializes a new
HeaderCollection from specified headers' RFC822 input stream |
HeaderCollection(int initialCapacity)
Initializes a new
HeaderCollection |
HeaderCollection(java.lang.String headerSrc)
Initializes a new
HeaderCollection from specified headers' RFC822 source |
Modifier and Type | Method and Description |
---|---|
HeaderCollection |
addHeader(java.lang.String name,
java.lang.String value)
Adds a header with the specified name and value
The current implementation knows about the preferred order of most well-known headers and will insert headers in that order.
|
void |
addHeaders(HeaderCollection headers)
Adds the specified header collection to this header collection.
|
static java.lang.String |
caseSensitiveHeadreNameFor(java.lang.String name)
Gets the case-sensitive header name as per RFC2822.
|
void |
clear()
Clears this header collection.
|
boolean |
containsHeader(java.lang.String name)
Checks if this header collection contains a header entry for specified header
|
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getAllHeaders()
Gets an instance of
Iterator to iterate all headers. |
java.lang.String[] |
getHeader(java.lang.String name)
Return all the values for the specified header.
|
java.lang.String |
getHeader(java.lang.String name,
char delimiter)
Get all the headers for this header name, returned as a single String, with headers separated by the delimiter.
|
java.lang.String |
getHeader(java.lang.String name,
java.lang.String delimiter)
Get all the headers for this header name, returned as a single String, with headers separated by the delimiter.
|
java.util.Iterator<java.lang.String> |
getHeaderNames()
Gets an instance of
Iterator to iterate all header names. |
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getMatchingHeaders(java.lang.String[] matchingHeaders)
Gets the matching headers
|
java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> |
getNonMatchingHeaders(java.lang.String[] nonMatchingHeaders)
Gets the non-matching headers
|
HeaderCollection |
getReadOnlyCollection()
Gets a read-only
collection constructed from this collection's current content |
int |
hashCode() |
boolean |
isEmpty()
Returns
true if no headers are contained in this collection |
void |
load(java.io.InputStream inputStream)
Read and parse the given headers' RFC822 input stream till the
blank line separating the header from the body.
|
void |
load(java.lang.String headerSrc)
Read and parse the given headers' RFC822 source till the blank
line separating the header from the body.
|
HeaderCollection |
removeHeader(java.lang.String name)
Remove all header entries that match the given name
|
HeaderCollection |
setHeader(java.lang.String name,
java.lang.String value)
Change the first header that matches name to have value, adding a new header if no existing header matches.
|
int |
size()
Gets the number of headers contained in this collection.
|
static void |
test()
Simple test method
|
java.lang.String |
toString() |
public static final HeaderCollection EMPTY_COLLECTION
public HeaderCollection()
HeaderCollection
with a default initial capacity of 40
.public HeaderCollection(int initialCapacity)
HeaderCollection
initialCapacity
- The collection's initial capacitypublic HeaderCollection(HeaderCollection headers)
HeaderCollection
headers
- The source headerspublic HeaderCollection(java.lang.String headerSrc)
HeaderCollection
from specified headers' RFC822 sourceheaderSrc
- The headers' RFC822 sourcepublic HeaderCollection(java.io.InputStream inputStream) throws com.openexchange.exception.OXException
HeaderCollection
from specified headers' RFC822 input streaminputStream
- The headers' RFC822 input streamcom.openexchange.exception.OXException
- If parsing the header input stream failspublic static java.lang.String caseSensitiveHeadreNameFor(java.lang.String name)
name
- The header name to checkpublic HeaderCollection getReadOnlyCollection()
collection
constructed from this collection's current contentcollection
public void load(java.io.InputStream inputStream) throws com.openexchange.exception.OXException
Note that the header lines are added, so any existing headers in this object will not be affected. Headers are added to the end of the existing list of headers, in order.
Provided input stream is not going to be closed but is read until EOF
or two subsequent CRLF
s occur.
public void load(java.lang.String headerSrc)
Note that the header lines are added, so any existing headers in this object will not be affected. Headers are added to the end of the existing list of headers, in order.
headerSrc
- The headers' RFC822 sourcepublic void clear()
public boolean isEmpty()
true
if no headers are contained in this collectiontrue
if no headers are contained in this collectionpublic int size()
This method is a constant-time operation.
public void addHeaders(HeaderCollection headers)
Note that the header lines are added, so any existing headers in this object will not be affected. Headers are added to the end of the existing list of headers, in order.
headers
- The header collection to addpublic HeaderCollection addHeader(java.lang.String name, java.lang.String value)
The current implementation knows about the preferred order of most well-known headers and will insert headers in that order. In
addition, it knows that Received
headers should be inserted in reverse order (newest before oldest), and that they
should appear at the beginning of the headers, preceded only by a possible Return-Path
header.
Note that RFC822 headers can only contain US-ASCII characters.
name
- The header namevalue
- The header valuejava.lang.IllegalArgumentException
- If name or value is invalidpublic HeaderCollection setHeader(java.lang.String name, java.lang.String value)
Note that RFC822 headers can only contain US-ASCII characters.
name
- The header namevalue
- The header valuejava.lang.IllegalArgumentException
- If name or value is invalidpublic boolean containsHeader(java.lang.String name)
name
- The header nametrue
if this header collection contains a header entry for specified header; otherwise false
public java.lang.String[] getHeader(java.lang.String name)
null
if no headers with the specified name exist.name
- The header namenull
if none existsjava.lang.IllegalArgumentException
- If name is invalidpublic java.lang.String getHeader(java.lang.String name, java.lang.String delimiter)
null
, only the first header is returned. Returns null
if no headers with the specified name exist.name
- The header namedelimiter
- The delimiternull
if nonepublic java.lang.String getHeader(java.lang.String name, char delimiter)
'\0'
, only the first header is returned. Returns null
if no headers with the specified name exist.name
- The header namedelimiter
- The delimiter characternull
if nonepublic HeaderCollection removeHeader(java.lang.String name)
name
- The header namepublic java.util.Iterator<java.lang.String> getHeaderNames()
Iterator
to iterate all header names.Iterator
to iterate all header namespublic java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> getAllHeaders()
Iterator
to iterate all headers.Iterator
to iterate all headerspublic java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> getMatchingHeaders(java.lang.String[] matchingHeaders)
matchingHeaders
- The matching headerspublic java.util.Iterator<java.util.Map.Entry<java.lang.String,java.lang.String>> getNonMatchingHeaders(java.lang.String[] nonMatchingHeaders)
nonMatchingHeaders
- The non-matching headerspublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equal
method.equals
in class java.lang.Object
obj
- The reference object with which to compare.true
if this object is the same as the object argument; false
otherwise.public int hashCode()
hashCode
in class java.lang.Object
public static final void test()