Class BasicHeader

java.lang.Object
org.apache.juneau.http.header.BasicHeader
All Implemented Interfaces:
Serializable, Cloneable, Header, NameValuePair
Direct Known Subclasses:
BasicBooleanHeader, BasicCsvHeader, BasicDateHeader, BasicEntityTagHeader, BasicEntityTagsHeader, BasicIntegerHeader, BasicLongHeader, BasicStringHeader, BasicStringRangesHeader, BasicUriHeader, ResponseHeader, SerializedHeader

@BeanIgnore public class BasicHeader extends Object implements Header, Cloneable, Serializable
Superclass of all headers defined in this package. Provides the following features:
  • Default support for various streams and readers.
  • Content from Suppliers.
  • Caching.
  • Fluent setters.
  • Fluent assertions.
See Also:
  • Constructor Details

  • Method Details

    • of

      public static BasicHeader of(String name, Object value)
      Static creator.
      Parameters:
      name - The parameter name.
      value - The parameter value.
      Can be null.
      Returns:
      A new header bean, or null if value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static BasicHeader of(NameValuePair o)
      Static creator.
      Parameters:
      o - The name value pair that makes up the header name and value. The parameter value.
      Any non-String value will be converted to a String using Object.toString().
      Returns:
      A new header bean.
    • getName

      public String getName()
      Specified by:
      getName in interface NameValuePair
    • getValue

      public String getValue()
      Specified by:
      getValue in interface NameValuePair
    • getElements

      Specified by:
      getElements in interface Header
      Throws:
      ParseException
    • equalsIgnoreCase

      public boolean equalsIgnoreCase(String compare)
      Returns true if the specified value is the same using String.equalsIgnoreCase(String).
      Parameters:
      compare - The value to compare against.
      Returns:
      true if the specified value is the same.
    • assertName

      Provides an object for performing assertions against the name of this header.
      Returns:
      An object for performing assertions against the name of this header.
    • assertStringValue

      Provides an object for performing assertions against the value of this header.
      Returns:
      An object for performing assertions against the value of this header.
    • asString

      Returns the value of this header as a string.
      Returns:
      The value of this header as a string, or Optional.empty() if the value is null
    • isPresent

      public boolean isPresent()
      Returns true if the value exists.

      This is a shortcut for calling asString().isPresent().

      Returns:
      true if the value exists.
    • isNotEmpty

      public boolean isNotEmpty()
      Returns true if the value exists and is not empty.

      This is a shortcut for calling !asString().orElse("").isEmpty().

      Returns:
      true if the value exists and is not empty.
    • get

      public String get()
      If a value is present, returns the value, otherwise throws NoSuchElementException.

      This is a shortcut for calling asString().get().

      Returns:
      The value if present.
    • orElse

      public String orElse(String other)
      If a value is present, returns the value, otherwise returns other.

      This is a shortcut for calling asString().orElse(other).

      Parameters:
      other - The other value.
      Returns:
      The value if present or the other value if not.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object