Class Range.Builder

java.lang.Object
org.apache.juneau.http.header.Range.Builder
Enclosing class:
Range

public static class Range.Builder extends Object
Fluent builder for assembling an HTTP Range header value.

Composes the range unit (default bytes) and one or more range specs defined by RFC 7233 §3.1 into the unit=spec,spec,... wire format. Typed setters cover the three byte-range-spec forms — a closed range (0-499) via range(long, long), an open-ended range (500-) via from(long), and a suffix range (-500) via suffix(long) — and spec(String) is a generic escape hatch.

Example:

String value = Range.create() .range(0, 499) .from(9500) .build(); // => "bytes=0-499,9500-"

See Also:
Since:
10.0.0
  • Constructor Details

  • Method Details

    • unit

      public Range.Builder unit(String value)
      Sets the range unit (default bytes).
      Parameters:
      value - The range unit. Must not be null or blank.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If value is null or blank.
    • range

      public Range.Builder range(long startValue, long endValue)
      Adds a closed byte-range spec of the form start-end.
      Parameters:
      startValue - The first byte position (inclusive). Must be non-negative.
      endValue - The last byte position (inclusive). Must be greater than or equal to startValue.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If the positions are negative or out of order.
    • from

      public Range.Builder from(long startValue)
      Adds an open-ended byte-range spec of the form start- (from the position to the end).
      Parameters:
      startValue - The first byte position (inclusive). Must be non-negative.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If startValue is negative.
    • suffix

      public Range.Builder suffix(long length)
      Adds a suffix byte-range spec of the form -length (the final length bytes).
      Parameters:
      length - The number of trailing bytes. Must be non-negative.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If length is negative.
    • spec

      public Range.Builder spec(String value)
      Generic escape hatch for adding any range spec verbatim.
      Parameters:
      value - The range spec (e.g. "0-499"). Must not be null or blank.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If value is null or blank.
    • build

      public String build()
      Builds the rendered Range header value.

      Returns an empty string when no range specs have been registered.

      Returns:
      The header value. Never null.
    • toHeader

      public Range toHeader()
      Builds a Range header bean directly from this builder.
      Returns:
      A Range carrying build(). Never null.
    • toString

      public String toString()
      Overrides:
      toString in class Object