/** * Parse the given, comma-separated string into a list of {@code HttpRange} objects. * <p>This method can be used to parse an {@code Range} header. * @param ranges the string to parse * @return the list of ranges * @throws IllegalArgumentException if the string cannot be parsed, or if * the number of ranges is greater than 100. */ public static List<HttpRange> parseRanges(@Nullable String ranges) { if (!StringUtils.hasLength(ranges)) { return Collections.emptyList(); } if (!ranges.startsWith(BYTE_RANGE_PREFIX)) { throw new IllegalArgumentException("Range '" + ranges + "' does not start with 'bytes='"); } ranges = ranges.substring(BYTE_RANGE_PREFIX.length()); String[] tokens = StringUtils.tokenizeToStringArray(ranges, ","); Assert.isTrue(tokens.length <= MAX_RANGES, () -> "Too many ranges " + tokens.length); List<HttpRange> result = new ArrayList<>(tokens.length); for (String token : tokens) { result.add(parseRange(token)); } return result; }
/** * Parse the given, comma-separated string into a list of {@code HttpRange} objects. * <p>This method can be used to parse an {@code Range} header. * @param ranges the string to parse * @return the list of ranges * @throws IllegalArgumentException if the string cannot be parsed, or if * the number of ranges is greater than 100. */ public static List<HttpRange> parseRanges(@Nullable String ranges) { if (!StringUtils.hasLength(ranges)) { return Collections.emptyList(); } if (!ranges.startsWith(BYTE_RANGE_PREFIX)) { throw new IllegalArgumentException("Range '" + ranges + "' does not start with 'bytes='"); } ranges = ranges.substring(BYTE_RANGE_PREFIX.length()); String[] tokens = StringUtils.tokenizeToStringArray(ranges, ","); Assert.isTrue(tokens.length <= MAX_RANGES, () -> "Too many ranges " + tokens.length); List<HttpRange> result = new ArrayList<>(tokens.length); for (String token : tokens) { result.add(parseRange(token)); } return result; }
/** * Parse the given, comma-separated string into a list of {@code HttpRange} objects. * <p>This method can be used to parse an {@code Range} header. * @param ranges the string to parse * @return the list of ranges * @throws IllegalArgumentException if the string cannot be parsed, or if * the number of ranges is greater than 100. */ public static List<HttpRange> parseRanges(@Nullable String ranges) { if (!StringUtils.hasLength(ranges)) { return Collections.emptyList(); } if (!ranges.startsWith(BYTE_RANGE_PREFIX)) { throw new IllegalArgumentException("Range '" + ranges + "' does not start with 'bytes='"); } ranges = ranges.substring(BYTE_RANGE_PREFIX.length()); String[] tokens = StringUtils.tokenizeToStringArray(ranges, ","); Assert.isTrue(tokens.length <= MAX_RANGES, () -> "Too many ranges " + tokens.length); List<HttpRange> result = new ArrayList<>(tokens.length); for (String token : tokens) { result.add(parseRange(token)); } return result; }
/** * Parse the given, comma-separated string into a list of {@code HttpRange} objects. * <p>This method can be used to parse an {@code Range} header. * @param ranges the string to parse * @return the list of ranges * @throws IllegalArgumentException if the string cannot be parsed, or if * the number of ranges is greater than 100. */ public static List<HttpRange> parseRanges(@Nullable String ranges) { if (!StringUtils.hasLength(ranges)) { return Collections.emptyList(); } if (!ranges.startsWith(BYTE_RANGE_PREFIX)) { throw new IllegalArgumentException("Range '" + ranges + "' does not start with 'bytes='"); } ranges = ranges.substring(BYTE_RANGE_PREFIX.length()); String[] tokens = StringUtils.tokenizeToStringArray(ranges, ","); Assert.isTrue(tokens.length <= MAX_RANGES, () -> "Too many ranges " + tokens.length); List<HttpRange> result = new ArrayList<>(tokens.length); for (String token : tokens) { result.add(parseRange(token)); } return result; }