Record Class ByteRanges

java.lang.Object
java.lang.Record
com.jsgalactic.axiom.http.ByteRanges
Record Components:
ranges - the ranges to send, in request order; at least one and at most 8

public record ByteRanges(List<ByteRange> ranges) extends Record
The satisfiable ranges of a Range: bytes=... header field (RFC 9110 section 14.2), in the order the client sent them.

Parsing is strict and bounded: only the bytes unit is accepted, a range list holds at most 8 specifications, every number is ASCII digits, and whitespace is allowed only around commas. A specification whose first byte is past the end of the representation, or a suffix of zero, is unsatisfiable and is dropped; if none remain, parsing yields empty. Numbers too large for a long are clamped rather than overflowing, so they become unsatisfiable instead of wrapping around. Open-ended ranges are clamped to the representation's length.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Most specifications a parsed Range field may contain: eight.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Validates the bound and takes an immutable copy.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    parse(String header, long length)
    Parses a Range field against a representation of the given length.
    Returns the value of the ranges record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_RANGES

      public static final int MAX_RANGES
      Most specifications a parsed Range field may contain: eight.
      See Also:
  • Constructor Details

  • Method Details

    • parse

      public static Optional<ByteRanges> parse(String header, long length)
      Parses a Range field against a representation of the given length.
      Parameters:
      header - the complete Range field value, or null when absent
      length - total length of the representation in bytes, positive
      Returns:
      the satisfiable ranges, or empty when the header is absent, malformed, has too many specifications, or has no satisfiable range
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • ranges

      public List<ByteRange> ranges()
      Returns the value of the ranges record component.
      Returns:
      the value of the ranges record component