java.lang.Object
org.klomp.snark.web.InclusiveByteRange
Byte range inclusive of end points.
parses the following types of byte ranges:
bytes=100-499
bytes=-300
bytes=100-
bytes=1-2,2-3,6-,-2
given an entity length, converts range to string
bytes 100-499/500
Based on RFC2616 3.12, 14.16, 14.35.1, 14.35.2Field Summary
Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionlonggetFirst()Returns the first byte position in this range.longgetFirst(long size) Returns the first byte position, resolved against the total entity size.longgetLast()Returns the last byte position in this range.longgetLast(long size) Returns the last byte position, resolved against the total entity size.longgetSize(long size) Returns the number of bytes in this range, resolved against the total entity size.static List<InclusiveByteRange> satisfiableRanges(Enumeration<?> headers, long size) Parse the Range header fields into a list of byte ranges.static Stringto416HeaderRangeString(long size) Formats a 416 Range Not Satisfiable response header value.toHeaderRangeString(long size) Formats this range as an HTTP Content-Range header value.toString()Returns a string representation of this range in the formfirst:last.
Field Details
first
long firstThe first byte position.last
long lastThe last byte position.
Constructor Details
InclusiveByteRange
public InclusiveByteRange(long first, long last) Creates a new byte range.- Parameters:
first- the first byte in the range (inclusive), or negative for suffix rangeslast- the last byte in the range (inclusive), or negative for suffix ranges
Method Details
getFirst
public long getFirst()Returns the first byte position in this range.- Returns:
- the first byte position (may be negative for suffix ranges)
getLast
public long getLast()Returns the last byte position in this range.- Returns:
- the last byte position (may be negative for suffix ranges)
satisfiableRanges
Parse the Range header fields into a list of byte ranges.- Parameters:
headers- Enumeration of Range header fields.size- Size of the resource.- Returns:
- List of satisfiable ranges
getFirst
public long getFirst(long size) Returns the first byte position, resolved against the total entity size. For suffix ranges (negative first), returnsmax(0, size - last).- Parameters:
size- the total size of the entity- Returns:
- the resolved first byte position
getLast
public long getLast(long size) Returns the last byte position, resolved against the total entity size. Clamps tosize - 1for open-ended or out-of-bounds ranges.- Parameters:
size- the total size of the entity- Returns:
- the resolved last byte position
getSize
public long getSize(long size) Returns the number of bytes in this range, resolved against the total entity size.- Parameters:
size- the total size of the entity- Returns:
- the number of bytes in the range (always >= 1)
toHeaderRangeString
Formats this range as an HTTP Content-Range header value. Returns a string of the formbytes first-last/size.- Parameters:
size- the total size of the entity- Returns:
- the Content-Range header value
to416HeaderRangeString
Formats a 416 Range Not Satisfiable response header value. Returns a string of the form "bytes star/star-size".- Parameters:
size- the total size of the entity- Returns:
- the Content-Range header value for a 416 response
toString