Package org.springframework.http
Class HttpRange
java.lang.Object
org.springframework.http.HttpRange
Represents an HTTP (byte) range for use with the HTTP
"Range"
header.- Since:
- 4.2
- Author:
- Arjen Poutsma, Juergen Hoeller
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpRange
createByteRange
(long firstBytePos) Create anHttpRange
from the given position to the end.static HttpRange
createByteRange
(long firstBytePos, long lastBytePos) Create aHttpRange
from the given fist to last position.static HttpRange
createSuffixRange
(long suffixLength) Create anHttpRange
that ranges over the last given number of bytes.abstract long
getRangeEnd
(long length) Return the end of the range (inclusive) given the total length of a representation.abstract long
getRangeStart
(long length) Return the start of the range given the total length of a representation.parseRanges
(String ranges) Parse the given, comma-separated string into a list ofHttpRange
objects.toResourceRegion
(Resource resource) Turn aResource
into aResourceRegion
using the range information contained in the currentHttpRange
.static List<ResourceRegion>
toResourceRegions
(List<HttpRange> ranges, Resource resource) Convert eachHttpRange
into aResourceRegion
, selecting the appropriate segment of the givenResource
using HTTP Range information.static String
toString
(Collection<HttpRange> ranges) Return a string representation of the given list ofHttpRange
objects.
-
Constructor Details
-
HttpRange
public HttpRange()
-
-
Method Details
-
toResourceRegion
Turn aResource
into aResourceRegion
using the range information contained in the currentHttpRange
.- Parameters:
resource
- theResource
to select the region from- Returns:
- the selected region of the given
Resource
- Since:
- 4.3
-
getRangeStart
public abstract long getRangeStart(long length) Return the start of the range given the total length of a representation.- Parameters:
length
- the length of the representation- Returns:
- the start of this range for the representation
-
getRangeEnd
public abstract long getRangeEnd(long length) Return the end of the range (inclusive) given the total length of a representation.- Parameters:
length
- the length of the representation- Returns:
- the end of the range for the representation
-
createByteRange
Create anHttpRange
from the given position to the end.- Parameters:
firstBytePos
- the first byte position- Returns:
- a byte range that ranges from
firstPos
till the end - See Also:
-
createByteRange
Create aHttpRange
from the given fist to last position.- Parameters:
firstBytePos
- the first byte positionlastBytePos
- the last byte position- Returns:
- a byte range that ranges from
firstPos
tilllastPos
- See Also:
-
createSuffixRange
Create anHttpRange
that ranges over the last given number of bytes.- Parameters:
suffixLength
- the number of bytes for the range- Returns:
- a byte range that ranges over the last
suffixLength
number of bytes - See Also:
-
parseRanges
Parse the given, comma-separated string into a list ofHttpRange
objects.This method can be used to parse an
Range
header.- Parameters:
ranges
- the string to parse- Returns:
- the list of ranges
- Throws:
IllegalArgumentException
- if the string cannot be parsed or if the number of ranges is greater than 100
-
toResourceRegions
Convert eachHttpRange
into aResourceRegion
, selecting the appropriate segment of the givenResource
using HTTP Range information.- Parameters:
ranges
- the list of rangesresource
- the resource to select the regions from- Returns:
- the list of regions for the given resource
- Throws:
IllegalArgumentException
- if the sum of all ranges exceeds the resource length- Since:
- 4.3
-
toString
Return a string representation of the given list ofHttpRange
objects.This method can be used to for an
Range
header.- Parameters:
ranges
- the ranges to create a string of- Returns:
- the string representation
-