Top Description Fields Constructors Methods
org.eclipse.jetty.http

public final Record ByteRange

extends Record
Class Inheritance
Record Components
first:long 
last:long 
Imports
java.util.ArrayList, .Comparator, .List, org.slf4j.Logger, .LoggerFactory

A representation of a byte range as specified by RFC 7233.

This class parses the value of the Range request header value, for example:

Range: bytes=100-499
Range: bytes=1-10,5-25,50-,-20

Field Summary

Modifier and TypeField and Description
private final long
first

Record Component accessed by first().

private final long
last

Record Component accessed by last().

private static final Logger

Constructor Summary

AccessConstructor and Description
public
ByteRange(long first, long last)

Method Summary

Modifier and TypeMethod and Description
private ByteRange
public final boolean
equals(Object
the reference object with which to compare.
o
)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.
public long
first()

Record Component getter of first.

public long

Returns:

the length of this byte range
getLength
()

Get the length of this byte range.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.
public long
last()

Record Component getter of last.

private boolean
public static List<ByteRange>

Returns:

a list of ByteRanges
parse
(List<String>
a list of range values
headers
,
long
the length of the resource for which ranges are requested
length
)

Parses the Range header values such as byte=10-20 to obtain a list of ByteRanges.

public String

Returns:

the value for the Content-Range response header for this byte range
toHeaderValue
(long
the content length
length
)

Returns the value for the Content-Range response header corresponding to this byte range.

public static String

Returns:

the non satisfiable value for the Content-Range response header
toNonSatisfiableHeaderValue
(long
the content length in bytes
length
)

Returns the value for the Content-Range response header when the range is non satisfiable and therefore the response status code is HttpStatus#RANGE_NOT_SATISFIABLE_416.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

firstback to summary
private final long first

Record Component accessed by first().

lastback to summary
private final long last

Record Component accessed by last().

LOGback to summary
private static final Logger LOG

Constructor Detail

ByteRangeback to summary
public ByteRange(long first, long last)

Method Detail

coalesceback to summary
private ByteRange coalesce(ByteRange r)
equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this record is equal to the argument; false otherwise.

firstback to summary
public long first()

Record Component getter of first.

getLengthback to summary
public long getLength()

Get the length of this byte range.

Returns:long

the length of this byte range

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

Returns:int

a hash code value for this record.

lastback to summary
public long last()

Record Component getter of last.

overlapsback to summary
private boolean overlaps(ByteRange range)
parseback to summary
public static List<ByteRange> parse(List<String> headers, long length)

Parses the Range header values such as byte=10-20 to obtain a list of ByteRanges.

Returns an empty list if the parsing fails.

Parameters
headers:List<String>

a list of range values

length:long

the length of the resource for which ranges are requested

Returns:List<ByteRange>

a list of ByteRanges

toHeaderValueback to summary
public String toHeaderValue(long length)

Returns the value for the Content-Range response header corresponding to this byte range.

Parameters
length:long

the content length

Returns:String

the value for the Content-Range response header for this byte range

toNonSatisfiableHeaderValueback to summary
public static String toNonSatisfiableHeaderValue(long length)

Returns the value for the Content-Range response header when the range is non satisfiable and therefore the response status code is HttpStatus#RANGE_NOT_SATISFIABLE_416.

Parameters
length:long

the content length in bytes

Returns:String

the non satisfiable value for the Content-Range response header

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

Returns:String

a string representation of the object.