public static ByteRange buildByteRange(String rangeHeaderValue) throws RestServiceException {
    if (!rangeHeaderValue.startsWith(BYTE_RANGE_PREFIX)) {
      throw new RestServiceException("Invalid byte range syntax; does not start with '" + BYTE_RANGE_PREFIX + "'",
          RestServiceErrorCode.InvalidArgs);
    }
    ByteRange range;
    try {
      int hyphenIndex = rangeHeaderValue.indexOf('-', BYTE_RANGE_PREFIX.length());
      String startOffsetStr = rangeHeaderValue.substring(BYTE_RANGE_PREFIX.length(), hyphenIndex);
      String endOffsetStr = rangeHeaderValue.substring(hyphenIndex + 1);
      if (startOffsetStr.isEmpty()) {
        range = ByteRanges.fromLastNBytes(Long.parseLong(endOffsetStr));
      } else if (endOffsetStr.isEmpty()) {
        range = ByteRanges.fromStartOffset(Long.parseLong(startOffsetStr));
      } else {
        range = ByteRanges.fromOffsetRange(Long.parseLong(startOffsetStr), Long.parseLong(endOffsetStr));
      }
    } catch (Exception e) {
      throw new RestServiceException(
          "Valid byte range could not be parsed from Range header value: " + rangeHeaderValue,
          RestServiceErrorCode.InvalidArgs);
    }
    return range;
  }
Build a {@link ByteRange} given a Range header value. This method can parse the following Range
header syntax:
{@code Range:bytes=byte_range} where {@code bytes=byte_range} supports the following range syntax:
<ul>
  <li>For bytes {@code {a}} through {@code {b}} inclusive: {@code bytes={a}-{b}}</li>
  <li>For all bytes including and after {@code {a}}: {@code bytes={a}-}</li>
  <li>For the last {@code {b}} bytes of a file: {@code bytes=-{b}}</li>
</ul>
@param rangeHeaderValue the value of the Range header.
@return The {@link ByteRange} parsed from the arguments.
@throws RestServiceException if no range header was found, or if a valid range could not be parsed from the header
                             value,
ambry-api/src/main/java/com/github/ambry/rest/RestUtils.java