Class ReadOnlyHttpHeaders

  • All Implemented Interfaces:
    java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>>

    @UnstableApi
    public final class ReadOnlyHttpHeaders
    extends HttpHeaders
    A variant of HttpHeaders which only supports read-only methods.

    Any array passed to this class may be used directly in the underlying data structures of this class. If these arrays may be modified it is the caller's responsibility to supply this class with a copy of the array.

    This may be a good alternative to DefaultHttpHeaders if your have a fixed set of headers which will not change.

    • Constructor Detail

      • ReadOnlyHttpHeaders

        public ReadOnlyHttpHeaders​(boolean validateHeaders,
                                   java.lang.CharSequence... nameValuePairs)
        Create a new instance.
        Parameters:
        validateHeaders - true to validate the contents of each header name.
        nameValuePairs - An array of the structure [<name,value>,<name,value>,...]. A copy will NOT be made of this array. If the contents of this array may be modified externally you are responsible for passing in a copy.
    • Method Detail

      • getInt

        public java.lang.Integer getInt​(java.lang.CharSequence name)
        Description copied from class: HttpHeaders
        Returns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
        Specified by:
        getInt in class HttpHeaders
        Parameters:
        name - the name of the header to search
        Returns:
        the first header value if the header is found and its value is an integer. null if there's no such header or its value is not an integer.
      • getInt

        public int getInt​(java.lang.CharSequence name,
                          int defaultValue)
        Description copied from class: HttpHeaders
        Returns the integer value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
        Specified by:
        getInt in class HttpHeaders
        Parameters:
        name - the name of the header to search
        defaultValue - the default value
        Returns:
        the first header value if the header is found and its value is an integer. defaultValue if there's no such header or its value is not an integer.
      • getShort

        public java.lang.Short getShort​(java.lang.CharSequence name)
        Description copied from class: HttpHeaders
        Returns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
        Specified by:
        getShort in class HttpHeaders
        Parameters:
        name - the name of the header to search
        Returns:
        the first header value if the header is found and its value is a short. null if there's no such header or its value is not a short.
      • getShort

        public short getShort​(java.lang.CharSequence name,
                              short defaultValue)
        Description copied from class: HttpHeaders
        Returns the short value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
        Specified by:
        getShort in class HttpHeaders
        Parameters:
        name - the name of the header to search
        defaultValue - the default value
        Returns:
        the first header value if the header is found and its value is a short. defaultValue if there's no such header or its value is not a short.
      • getTimeMillis

        public java.lang.Long getTimeMillis​(java.lang.CharSequence name)
        Description copied from class: HttpHeaders
        Returns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
        Specified by:
        getTimeMillis in class HttpHeaders
        Parameters:
        name - the name of the header to search
        Returns:
        the first header value if the header is found and its value is a date. null if there's no such header or its value is not a date.
      • getTimeMillis

        public long getTimeMillis​(java.lang.CharSequence name,
                                  long defaultValue)
        Description copied from class: HttpHeaders
        Returns the date value of a header with the specified name. If there are more than one values for the specified name, the first value is returned.
        Specified by:
        getTimeMillis in class HttpHeaders
        Parameters:
        name - the name of the header to search
        defaultValue - the default value
        Returns:
        the first header value if the header is found and its value is a date. defaultValue if there's no such header or its value is not a date.
      • entries

        public java.util.List<java.util.Map.Entry<java.lang.String,​java.lang.String>> entries()
        Description copied from class: HttpHeaders
        Returns a new List that contains all headers in this object. Note that modifying the returned List will not affect the state of this object. If you intend to enumerate over the header entries only, use HttpHeaders.iterator() instead, which has much less overhead.
        Specified by:
        entries in class HttpHeaders
        See Also:
        HttpHeaders.iteratorCharSequence()
      • containsValue

        public boolean containsValue​(java.lang.CharSequence name,
                                     java.lang.CharSequence value,
                                     boolean ignoreCase)
        Description copied from class: HttpHeaders
        Returns true if a header with the name and value exists, false otherwise. This also handles multiple values that are separated with a ,.

        If ignoreCase is true then a case insensitive compare is done on the value.

        Overrides:
        containsValue in class HttpHeaders
        Parameters:
        name - the name of the header to find
        value - the value of the header to find
        ignoreCase - true then a case insensitive compare is run to compare values. otherwise a case sensitive compare is run to compare values.
      • valueStringIterator

        public java.util.Iterator<java.lang.String> valueStringIterator​(java.lang.CharSequence name)
        Description copied from class: HttpHeaders
        Equivalent to HttpHeaders.getAll(String) but it is possible that no intermediate list is generated.
        Overrides:
        valueStringIterator in class HttpHeaders
        Parameters:
        name - the name of the header to retrieve
        Returns:
        an Iterator of header values corresponding to name.
      • valueCharSequenceIterator

        public java.util.Iterator<java.lang.CharSequence> valueCharSequenceIterator​(java.lang.CharSequence name)
        Description copied from class: HttpHeaders
        Equivalent to HttpHeaders.getAll(String) but it is possible that no intermediate list is generated.
        Overrides:
        valueCharSequenceIterator in class HttpHeaders
        Parameters:
        name - the name of the header to retrieve
        Returns:
        an Iterator of header values corresponding to name.
      • iterator

        public java.util.Iterator<java.util.Map.Entry<java.lang.String,​java.lang.String>> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.util.Map.Entry<java.lang.String,​java.lang.String>>
        Specified by:
        iterator in class HttpHeaders
      • iteratorCharSequence

        public java.util.Iterator<java.util.Map.Entry<java.lang.CharSequence,​java.lang.CharSequence>> iteratorCharSequence()
        Specified by:
        iteratorCharSequence in class HttpHeaders
        Returns:
        Iterator over the name/value header pairs.
      • isEmpty

        public boolean isEmpty()
        Description copied from class: HttpHeaders
        Checks if no header exists.
        Specified by:
        isEmpty in class HttpHeaders
      • size

        public int size()
        Description copied from class: HttpHeaders
        Returns the number of headers in this object.
        Specified by:
        size in class HttpHeaders
      • names

        public java.util.Set<java.lang.String> names()
        Description copied from class: HttpHeaders
        Returns a new Set that contains the names of all headers in this object. Note that modifying the returned Set will not affect the state of this object. If you intend to enumerate over the header entries only, use HttpHeaders.iterator() instead, which has much less overhead.
        Specified by:
        names in class HttpHeaders
      • addInt

        public HttpHeaders addInt​(java.lang.CharSequence name,
                                  int value)
        Description copied from class: HttpHeaders
        Add the name to value.
        Specified by:
        addInt in class HttpHeaders
        Parameters:
        name - The name to modify
        value - The value
        Returns:
        this
      • addShort

        public HttpHeaders addShort​(java.lang.CharSequence name,
                                    short value)
        Description copied from class: HttpHeaders
        Add the name to value.
        Specified by:
        addShort in class HttpHeaders
        Parameters:
        name - The name to modify
        value - The value
        Returns:
        this
      • setInt

        public HttpHeaders setInt​(java.lang.CharSequence name,
                                  int value)
        Description copied from class: HttpHeaders
        Set the name to value. This will remove all previous values associated with name.
        Specified by:
        setInt in class HttpHeaders
        Parameters:
        name - The name to modify
        value - The value
        Returns:
        this
      • setShort

        public HttpHeaders setShort​(java.lang.CharSequence name,
                                    short value)
        Description copied from class: HttpHeaders
        Set the name to value. This will remove all previous values associated with name.
        Specified by:
        setShort in class HttpHeaders
        Parameters:
        name - The name to modify
        value - The value
        Returns:
        this