Interface Headers

All Superinterfaces:
Iterable<Header>

public interface Headers extends Iterable<Header>
A mutable ordered collection of Header objects. Note that multiple headers may have the same key.

The order of headers is preserved in the order they were added.

  • Method Summary

    Modifier and Type
    Method
    Description
    add(String key, byte[] value)
    Creates and adds a header, to the end, returning if the operation succeeded.
    add(Header header)
    Adds a header (key inside), to the end, returning if the operation succeeded.
    Returns all headers for the given key, in the order they were added in, if present.
    Returns just one (the very last) header for the given key, if present.
    Removes all headers for the given key returning if the operation succeeded, while preserving the insertion order of the remaining headers.
    Returns all headers as an array, in the order they were added in.

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • add

      Headers add(Header header) throws IllegalStateException
      Adds a header (key inside), to the end, returning if the operation succeeded.
      Parameters:
      header - the Header to be added.
      Returns:
      this instance of the Headers, once the header is added.
      Throws:
      IllegalStateException - is thrown if headers are in a read-only state.
    • add

      Headers add(String key, byte[] value) throws IllegalStateException
      Creates and adds a header, to the end, returning if the operation succeeded.
      Parameters:
      key - of the header to be added; must not be null.
      value - of the header to be added; may be null.
      Returns:
      this instance of the Headers, once the header is added.
      Throws:
      IllegalStateException - is thrown if headers are in a read-only state.
    • remove

      Headers remove(String key) throws IllegalStateException
      Removes all headers for the given key returning if the operation succeeded, while preserving the insertion order of the remaining headers.
      Parameters:
      key - to remove all headers for; must not be null.
      Returns:
      this instance of the Headers, once the header is removed.
      Throws:
      IllegalStateException - is thrown if headers are in a read-only state.
    • lastHeader

      Header lastHeader(String key)
      Returns just one (the very last) header for the given key, if present.
      Parameters:
      key - to get the last header for; must not be null.
      Returns:
      this last header matching the given key, returns null if not present.
    • headers

      Iterable<Header> headers(String key)
      Returns all headers for the given key, in the order they were added in, if present. The iterator does not support Iterator.remove().
      Parameters:
      key - to return the headers for; must not be null.
      Returns:
      all headers for the given key, in the order they were added in, if NO headers are present an empty iterable is returned.
    • toArray

      Header[] toArray()
      Returns all headers as an array, in the order they were added in.
      Returns:
      the headers as a Header[], mutating this array will not affect the Headers, if NO headers are present an empty array is returned.