org.springframework.http

Class HttpRange

  • java.lang.Object
    • org.springframework.http.HttpRange
    • Constructor Summary

      Constructors 
      Constructor and Description
      HttpRange() 
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method and Description
      static HttpRange createByteRange(long firstBytePos)
      Create an HttpRange from the given position to the end.
      static HttpRange createByteRange(long firstBytePos, long lastBytePos)
      Create a HttpRange from the given fist to last position.
      static HttpRange createSuffixRange(long suffixLength)
      Create an HttpRange 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.
      static java.util.List<HttpRange> parseRanges(java.lang.String ranges)
      Parse the given, comma-separated string into a list of HttpRange objects.
      ResourceRegion toResourceRegion(Resource resource)
      Turn a Resource into a ResourceRegion using the range information contained in the current HttpRange.
      static java.util.List<ResourceRegion> toResourceRegions(java.util.List<HttpRange> ranges, Resource resource)
      Convert each HttpRange into a ResourceRegion, selecting the appropriate segment of the given Resource using HTTP Range information.
      static java.lang.String toString(java.util.Collection<HttpRange> ranges)
      Return a string representation of the given list of HttpRange objects.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpRange

        public HttpRange()
    • Method Detail

      • toResourceRegion

        public ResourceRegion toResourceRegion(Resource resource)
        Turn a Resource into a ResourceRegion using the range information contained in the current HttpRange.
        Parameters:
        resource - the Resource 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

        public static HttpRange createByteRange(long firstBytePos)
        Create an HttpRange 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:
        Byte Ranges
      • createByteRange

        public static HttpRange createByteRange(long firstBytePos,
                                                long lastBytePos)
        Create a HttpRange from the given fist to last position.
        Parameters:
        firstBytePos - the first byte position
        lastBytePos - the last byte position
        Returns:
        a byte range that ranges from firstPos till lastPos
        See Also:
        Byte Ranges
      • createSuffixRange

        public static HttpRange createSuffixRange(long suffixLength)
        Create an HttpRange 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:
        Byte Ranges
      • parseRanges

        public static java.util.List<HttpRange> parseRanges(@Nullable
                                                            java.lang.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 - the string to parse
        Returns:
        the list of ranges
        Throws:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • toResourceRegions

        public static java.util.List<ResourceRegion> toResourceRegions(java.util.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 - the list of ranges
        resource - the resource to select the regions from
        Returns:
        the list of regions for the given resource
        Since:
        4.3
      • toString

        public static java.lang.String toString(java.util.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 - the ranges to create a string of
        Returns:
        the string representation