Top Description Inners Fields Constructors Methods
org.springframework.http

public abstract Class HttpRange

extends Object
Class Inheritance
Known Direct Subclasses
org.springframework.http.HttpRange.ByteRange, org.springframework.http.HttpRange.SuffixByteRange
Imports
java.io.IOException, java.util.ArrayList, .Collection, .Collections, .List, .Objects, .StringJoiner, org.springframework.core.io.InputStreamResource, .Resource, org.springframework.core.io.support.ResourceRegion, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .ObjectUtils, .StringUtils

Represents an HTTP (byte) range for use with the HTTP "Range" header.
Authors
Arjen Poutsma, Juergen Hoeller
Since
4.2
See Also
HTTP/1.1: Range Requests, HttpHeaders#setRange(List), HttpHeaders#getRange()

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
HttpRange.ByteRange

Represents an HTTP/1.1 byte range, with a first and optional last position.

private static class
HttpRange.SuffixByteRange

Represents an HTTP/1.1 suffix byte range, with a number of suffix bytes.

Field Summary

Modifier and TypeField and Description
private static final String
private static final int
MAX_RANGES

Maximum ranges per request.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static HttpRange

Returns:

a byte range that ranges from firstPos till the end
createByteRange
(long
the first byte position
firstBytePos
)

Create an HttpRange from the given position to the end.

public static HttpRange

Returns:

a byte range that ranges from firstPos till lastPos
createByteRange
(long
the first byte position
firstBytePos
,
long
the last byte position
lastBytePos
)

Create a HttpRange from the given fist to last position.

public static HttpRange

Returns:

a byte range that ranges over the last suffixLength number of bytes
createSuffixRange
(long
the number of bytes for the range
suffixLength
)

Create an HttpRange that ranges over the last given number of bytes.

private static long
public abstract long

Returns:

the end of the range for the representation
getRangeEnd
(long
the length of the representation
length
)

Return the end of the range (inclusive) given the total length of a representation.

public abstract long

Returns:

the start of this range for the representation
getRangeStart
(long
the length of the representation
length
)

Return the start of the range given the total length of a representation.

private static HttpRange
public static List<HttpRange>

Returns:

the list of ranges
parseRanges
(String
the string to parse
ranges
)

Parse the given, comma-separated string into a list of HttpRange objects.

public ResourceRegion

Returns:

the selected region of the given Resource
toResourceRegion
(Resource
the Resource to select the region from
resource
)

Turn a Resource into a ResourceRegion using the range information contained in the current HttpRange.

public static List<ResourceRegion>

Returns:

the list of regions for the given resource
toResourceRegions
(List<HttpRange>
the list of ranges
ranges
,
Resource
the resource to select the regions from
resource
)

Convert each HttpRange into a ResourceRegion, selecting the appropriate segment of the given Resource using HTTP Range information.

public static String

Returns:

the string representation
toString
(Collection<HttpRange>
the ranges to create a string of
ranges
)

Return a string representation of the given list of HttpRange objects.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BYTE_RANGE_PREFIXback to summary
private static final String BYTE_RANGE_PREFIX
MAX_RANGESback to summary
private static final int MAX_RANGES

Maximum ranges per request.

Constructor Detail

HttpRangeback to summary
public HttpRange()

Method Detail

createByteRangeback to summary
public static HttpRange createByteRange(long firstBytePos)

Create an HttpRange from the given position to the end.

Parameters
firstBytePos:long

the first byte position

Returns:HttpRange

a byte range that ranges from firstPos till the end

See Also
Byte Ranges
createByteRangeback to summary
public static HttpRange createByteRange(long firstBytePos, long lastBytePos)

Create a HttpRange from the given fist to last position.

Parameters
firstBytePos:long

the first byte position

lastBytePos:long

the last byte position

Returns:HttpRange

a byte range that ranges from firstPos till lastPos

See Also
Byte Ranges
createSuffixRangeback to summary
public static HttpRange createSuffixRange(long suffixLength)

Create an HttpRange that ranges over the last given number of bytes.

Parameters
suffixLength:long

the number of bytes for the range

Returns:HttpRange

a byte range that ranges over the last suffixLength number of bytes

See Also
Byte Ranges
getLengthForback to summary
private static long getLengthFor(Resource resource)
getRangeEndback to summary
public abstract long getRangeEnd(long length)

Return the end of the range (inclusive) given the total length of a representation.

Parameters
length:long

the length of the representation

Returns:long

the end of the range for the representation

getRangeStartback to summary
public abstract long getRangeStart(long length)

Return the start of the range given the total length of a representation.

Parameters
length:long

the length of the representation

Returns:long

the start of this range for the representation

parseRangeback to summary
private static HttpRange parseRange(String range)
parseRangesback to summary
public static List<HttpRange> parseRanges(String ranges)

Parse the given, comma-separated string into a list of HttpRange objects.

This method can be used to parse an Range header.

Parameters
ranges:String

the string to parse

Returns:List<HttpRange>

the list of ranges

Exceptions
IllegalArgumentException:
if the string cannot be parsed or if the number of ranges is greater than 100
toResourceRegionback to summary
public ResourceRegion toResourceRegion(Resource resource)

Turn a Resource into a ResourceRegion using the range information contained in the current HttpRange.

Parameters
resource:Resource

the Resource to select the region from

Returns:ResourceRegion

the selected region of the given Resource

Since
4.3
toResourceRegionsback to summary
public static List<ResourceRegion> toResourceRegions(List<HttpRange> ranges, Resource resource)

Convert each HttpRange into a ResourceRegion, selecting the appropriate segment of the given Resource using HTTP Range information.

Parameters
ranges:List<HttpRange>

the list of ranges

resource:Resource

the resource to select the regions from

Returns:List<ResourceRegion>

the list of regions for the given resource

Exceptions
IllegalArgumentException:
if the sum of all ranges exceeds the resource length
Since
4.3
toStringback to summary
public static String toString(Collection<HttpRange> ranges)

Return a string representation of the given list of HttpRange objects.

This method can be used to for an Range header.

Parameters
ranges:Collection<HttpRange>

the ranges to create a string of

Returns:String

the string representation

org.springframework.http back to summary

private Class HttpRange.ByteRange

extends HttpRange
Class Inheritance

Represents an HTTP/1.1 byte range, with a first and optional last position.
See Also
Byte Ranges, HttpRange#createByteRange(long), HttpRange#createByteRange(long, long)

Field Summary

Modifier and TypeField and Description
private final long
private final Long

Constructor Summary

AccessConstructor and Description
public
ByteRange(long firstPos, Long lastPos)

Method Summary

Modifier and TypeMethod and Description
private void
assertPositions(long firstBytePos, Long lastBytePos)

public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public long
getRangeEnd(long
the length of the representation
length
)

Implements abstract org.springframework.http.HttpRange.getRangeEnd.

Return the end of the range (inclusive) given the total length of a representation.

public long
getRangeStart(long
the length of the representation
length
)

Implements abstract org.springframework.http.HttpRange.getRangeStart.

Return the start of the range given the total length of a representation.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.springframework.http.HttpRange:
createByteRangecreateByteRangecreateSuffixRangeparseRangestoResourceRegiontoResourceRegionstoString

Field Detail

firstPosback to summary
private final long firstPos
lastPosback to summary
private final Long lastPos
Annotations
@Nullable

Constructor Detail

ByteRangeback to summary
public ByteRange(long firstPos, Long lastPos)

Method Detail

assertPositionsback to summary
private void assertPositions(long firstBytePos, Long lastBytePos)
equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getRangeEndback to summary
public long getRangeEnd(long length)

Implements abstract org.springframework.http.HttpRange.getRangeEnd.

Doc from org.springframework.http.HttpRange.getRangeEnd.

Return the end of the range (inclusive) given the total length of a representation.

Parameters
length:long

the length of the representation

Returns:long

the end of the range for the representation

Annotations
@Override
getRangeStartback to summary
public long getRangeStart(long length)

Implements abstract org.springframework.http.HttpRange.getRangeStart.

Doc from org.springframework.http.HttpRange.getRangeStart.

Return the start of the range given the total length of a representation.

Parameters
length:long

the length of the representation

Returns:long

the start of this range for the representation

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.springframework.http back to summary

private Class HttpRange.SuffixByteRange

extends HttpRange
Class Inheritance

Represents an HTTP/1.1 suffix byte range, with a number of suffix bytes.
See Also
Byte Ranges, HttpRange#createSuffixRange(long)

Field Summary

Modifier and TypeField and Description
private final long

Constructor Summary

AccessConstructor and Description
public
SuffixByteRange(long suffixLength)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public long
getRangeEnd(long
the length of the representation
length
)

Implements abstract org.springframework.http.HttpRange.getRangeEnd.

Return the end of the range (inclusive) given the total length of a representation.

public long
getRangeStart(long
the length of the representation
length
)

Implements abstract org.springframework.http.HttpRange.getRangeStart.

Return the start of the range given the total length of a representation.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.springframework.http.HttpRange:
createByteRangecreateByteRangecreateSuffixRangeparseRangestoResourceRegiontoResourceRegionstoString

Field Detail

suffixLengthback to summary
private final long suffixLength

Constructor Detail

SuffixByteRangeback to summary
public SuffixByteRange(long suffixLength)

Method Detail

equalsback to summary
public boolean equals(Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getRangeEndback to summary
public long getRangeEnd(long length)

Implements abstract org.springframework.http.HttpRange.getRangeEnd.

Doc from org.springframework.http.HttpRange.getRangeEnd.

Return the end of the range (inclusive) given the total length of a representation.

Parameters
length:long

the length of the representation

Returns:long

the end of the range for the representation

Annotations
@Override
getRangeStartback to summary
public long getRangeStart(long length)

Implements abstract org.springframework.http.HttpRange.getRangeStart.

Doc from org.springframework.http.HttpRange.getRangeStart.

Return the start of the range given the total length of a representation.

Parameters
length:long

the length of the representation

Returns:long

the start of this range for the representation

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override