public class InclusiveByteRange extends Object
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.2| Modifier and Type | Field and Description |
|---|---|
(package private) long | firstThe first byte position |
(package private) long | lastThe last byte position |
| Constructor and Description |
|---|
InclusiveByteRange(long first,
long last)Creates a new byte range. |
| Modifier and Type | Method and Description |
|---|---|
long | getFirst()Returns the first byte position in this range. |
long | getFirst(long size)Returns the first byte position, resolved against the total entity size. |
long | getLast()Returns the last byte position in this range. |
long | getLast(long size)Returns the last byte position, resolved against the total entity size. |
long | getSize(long size)Returns the number of bytes in this range, resolved against the total entity size. |
static List<InclusiveByteRange> | satisfiableRanges(Enumeration<?> headers,
long size) |
static String | to416HeaderRangeString(long size)Formats a 416 Range Not Satisfiable response header value. |
String | toHeaderRangeString(long size)Formats this range as an HTTP Content-Range header value. |
String | toString()Returns a string representation of this range in the form first:last. |
public InclusiveByteRange(long first,
long last)first - the first byte in the range (inclusive), or negative for suffix rangeslast - the last byte in the range (inclusive), or negative for suffix rangespublic long getFirst()
public long getFirst(long size)
max(0, size - last).size - the total size of the entitypublic long getLast()
public long getLast(long size)
size - 1 for open-ended or out-of-bounds ranges.size - the total size of the entitypublic long getSize(long size)
size - the total size of the entitypublic static List<InclusiveByteRange> satisfiableRanges(Enumeration<?> headers, long size)
headers - Enumeration of Range header fields.size - Size of the resource.public static String to416HeaderRangeString(long size)
size - the total size of the entitypublic String toHeaderRangeString(long size)
bytes first-last/size.size - the total size of the entity