Class HttpUtil


  • public final class HttpUtil
    extends Object
    Utility methods for HTTP.
    • Method Detail

      • buildRangeRequestHeader

        @Nullable
        public static String buildRangeRequestHeader​(long position,
                                                     long length)
        Builds a Range header for the given position and length.
        Parameters:
        position - The request position.
        length - The request length, or C.LENGTH_UNSET if the request is unbounded.
        Returns:
        The corresponding range header, or null if a header is unnecessary because the whole resource is being requested.
      • getDocumentSize

        public static long getDocumentSize​(@Nullable
                                           String contentRangeHeader)
        Attempts to parse the document size from a Content-Range header.
        Parameters:
        contentRangeHeader - The Content-Range header, or null if not set.
        Returns:
        The document size, or C.LENGTH_UNSET if it could not be determined.
      • getContentLength

        public static long getContentLength​(@Nullable
                                            String contentLengthHeader,
                                            @Nullable
                                            String contentRangeHeader)
        Attempts to parse the length of a response body from the corresponding response headers.
        Parameters:
        contentLengthHeader - The Content-Length header, or null if not set.
        contentRangeHeader - The Content-Range header, or null if not set.
        Returns:
        The length of the response body, or C.LENGTH_UNSET if it could not be determined.