Class BasicLongHeader

java.lang.Object
org.apache.juneau.http.header.BasicHeader
org.apache.juneau.http.header.BasicLongHeader
All Implemented Interfaces:
Serializable, Cloneable, Header, NameValuePair
Direct Known Subclasses:
ContentLength

@Header @Schema(type="integer", format="int64") public class BasicLongHeader extends BasicHeader
Category of headers that consist of a single long value.

Example

Content-Length: 300

See Also:
  • Constructor Details

  • Method Details

    • of

      public static BasicLongHeader of(String name, String value)
      Static creator.
      Parameters:
      name - The header name.
      value - The header value.
      Must be parsable by Long.parseLong(String).
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static BasicLongHeader of(String name, Long value)
      Static creator.
      Parameters:
      name - The header name.
      value - The header value.
      Must be parsable by Long.parseLong(String).
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • of

      public static BasicLongHeader of(String name, Supplier<Long> value)
      Static creator with delayed value.

      Header value is re-evaluated on each call to getValue().

      Parameters:
      name - The header name.
      value - The supplier of the header value.
      Can be null.
      Returns:
      A new header bean, or null if the value is null.
      Throws:
      IllegalArgumentException - If name is null or empty.
    • getValue

      public String getValue()
      Specified by:
      getValue in interface NameValuePair
      Overrides:
      getValue in class BasicHeader
    • asLong

      public Optional<Long> asLong()
      Returns the header value as a Long wrapped in an Optional.
      Returns:
      The header value as a Long wrapped in an Optional. Never null.
    • toLong

      public Long toLong()
      Returns the header value as a Long.
      Returns:
      The header value as a Long. Can be null.
    • assertLong

      public org.apache.juneau.assertions.FluentLongAssertion<BasicLongHeader> assertLong()
      Provides the ability to perform fluent-style assertions on this header.
      Examples:

      // Validates the response body is not too large. client .get(URL) .run() .getHeader("Length").asLongHeader().assertLong().isLessThan(100000);

      Returns:
      A new fluent assertion object.
      Throws:
      AssertionError - If assertion failed.
    • orElse

      public Long orElse(Long other)
      Return the value if present, otherwise return other.

      This is a shortened form for calling asLong().orElse(other).

      Parameters:
      other - The value to be returned if there is no value present, can be null.
      Returns:
      The value, if present, otherwise other.