testutils/src/main/java/com/google/android/exoplayer2/testutil/WebServerDispatcher.java
/**
   * Parses an RFC 7233 Range header to its component parts. Returns null if the Range is invalid.
   */
Parses an RFC 7233 Range header to its component parts. Returns null if the Range is invalid.
Parses an RFC 7233 Range header to its component parts . Returns null if the Range is invalid .
@Nullable
  private static Pair<@NullableType Integer, @NullableType Integer> parseRangeHeader(
      String rangeHeader) {
    Pattern rangePattern = Pattern.compile("bytes=(\\d*)-(\\d*)");
    Matcher rangeMatcher = rangePattern.matcher(rangeHeader);
    if (!rangeMatcher.matches() || rangeHeader.contains(",")) {
      return null;
    }
    String first = checkNotNull(rangeMatcher.group(1));
    String second = checkNotNull(rangeMatcher.group(2));
    Pair<@NullableType Integer, @NullableType Integer> result =
        Pair.create(
            first.isEmpty() ? null : Integer.parseInt(first),
            second.isEmpty() ? null : Integer.parseInt(second));
    if (result.first != null && result.second != null && result.second < result.first) {
      return null;
    }
    return result;
  }
@ Nullable private static Pair < @ NullableType Integer , @ NullableType Integer > parseRangeHeader ( String rangeHeader ) { Pattern rangePattern = Pattern . compile ( "bytes=(\\d*)-(\\d*)" ) ; Matcher rangeMatcher = rangePattern . matcher ( rangeHeader ) ; if ( ! rangeMatcher . matches ( ) || rangeHeader . contains ( "," ) ) { return null ; } String first = checkNotNull ( rangeMatcher . group ( 1 ) ) ; String second = checkNotNull ( rangeMatcher . group ( 2 ) ) ; Pair < @ NullableType Integer , @ NullableType Integer > result = Pair . create ( first . isEmpty ( ) ? null : Integer . parseInt ( first ) , second . isEmpty ( ) ? null : Integer . parseInt ( second ) ) ; if ( result . first != null && result . second != null && result . second < result . first ) { return null ; } return result ; }
Parses an RFC 7233 Range header to its component parts.
Parses an RFC 7233 Range header to its component parts .
// This implementation only supports byte ranges and doesn't support multiple ranges.