Class Headers


  • public final class Headers
    extends java.lang.Object
    Helper class providing functions to manipulate the Message.headers array. The headers are stored in the array as follows:
     Headers:  hdr-1 | hdr-2 | hdr-3 | ... | hdr-n |
     
    The arrays are populated from left to right, and any empty slot in 'headers' can terminate an interation (e.g. a getHeader())
    It is assumed that we only have a few headers, 3-4 on average. Note that getting a header for a given key and putting a new key/header are operations with O(n) cost, so this implementation is not recommended for a large number of elements.
    This class is synchronized for writes (put(), resize()), but not for reads (size(), get())
    Author:
    Bela Ban
    • Method Detail

      • getHeader

        public static <T extends Header> T getHeader​(Header[] hdrs,
                                                     short id)
        Returns the header associated with an ID
        Parameters:
        id - The ID
        Returns:
      • getHeader

        public static <T extends Header> T getHeader​(Header[] hdrs,
                                                     short... ids)
        Returns the header associated with a set of IDs
        Type Parameters:
        T -
        Parameters:
        hdrs -
        ids - The IDs
        Returns:
      • getHeaders

        public static java.util.Map<java.lang.Short,​Header> getHeaders​(Header[] hdrs)
      • printHeaders

        public static java.lang.String printHeaders​(Header[] hdrs)
      • putHeader

        public static Header[] putHeader​(Header[] headers,
                                         short id,
                                         Header hdr,
                                         boolean replace_if_present)
        Adds hdr at the next available slot. If none is available, the headers array passed in will be copied and the copy returned
        Parameters:
        headers - The headers array
        id - The protocol ID of the header
        hdr - The header
        replace_if_present - Whether or not to overwrite an existing header
        Returns:
        A new copy of headers if the array needed to be expanded, or null otherwise
      • resize

        public static Header[] resize​(Header[] headers)
        Increases the capacity of the array and copies the contents of the old into the new array
      • printObjectHeaders

        public static java.lang.String printObjectHeaders​(Header[] hdrs)
      • marshalledSize

        public static int marshalledSize​(Header[] hdrs)
      • size

        public static int size​(Header[] hdrs)
      • size

        public static int size​(Header[] hdrs,
                               short... excluded_ids)