@Test public void suffixTooLarge() { final List<Range<Long>> ranges = parser.parseRangeSpec("bytes=-10", 5L); System.err.println(ranges); assertThat(ranges, is(nullValue())); }
public List<Range<Long>> parseRangeSpec(final String rangeHeader, long size) { Range<Long> content = Range.closed(0L, size - 1L); if (!Strings.isNullOrEmpty(rangeHeader)) { try { if (rangeHeader.startsWith("bytes=") && rangeHeader.length() > 6 && !rangeHeader.contains(",")) { final String rangeSpec = rangeHeader.substring(6, rangeHeader.length()); if (rangeSpec.startsWith("-")) { final long byteCount = Long.parseLong(rangeSpec.substring(1)); if (byteCount > size) { return UNSATISFIABLE; } final Range<Long> suffix = Range.atLeast(size - byteCount); return ensureSatisfiable(suffix, content); } else if (rangeSpec.endsWith("-")) { final Range<Long> requested = Range.atLeast(Long.parseLong(rangeSpec.substring(0, rangeSpec.length() - 1))); return ensureSatisfiable(requested, content); } else if (rangeSpec.contains("-")) { final String[] parts = rangeSpec.split("-"); return ensureSatisfiable(Range.closed(Long.parseLong(parts[0]), Long.parseLong(parts[1])), content); } else { log.warn("Malformed HTTP Range value: {}, ignoring it", rangeHeader); } } else { log.warn("Unsupported non-byte or multiple HTTP Ranges: {}; sending complete content", rangeHeader); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Problem parsing Range value: {}, ignoring", rangeHeader, e); } else { log.warn("Problem parsing Range value: {}, ignoring: {}", rangeHeader, e.toString()); } } } return WHOLE_RANGE; }
RangeParser extends ComponentSupport { public List<Range<Long>> parseRangeSpec(final String rangeHeader, long size) { Range<Long> content = Range.closed(0L, size - 1L); if (!Strings.isNullOrEmpty(rangeHeader)) { try { if (rangeHeader.startsWith("bytes=") && rangeHeader.length() > 6 && !rangeHeader.contains(",")) { final String rangeSpec = rangeHeader.substring(6, rangeHeader.length()); if (rangeSpec.startsWith("-")) { final long byteCount = Long.parseLong(rangeSpec.substring(1)); if (byteCount > size) { return UNSATISFIABLE; } final Range<Long> suffix = Range.atLeast(size - byteCount); return ensureSatisfiable(suffix, content); } else if (rangeSpec.endsWith("-")) { final Range<Long> requested = Range.atLeast(Long.parseLong(rangeSpec.substring(0, rangeSpec.length() - 1))); return ensureSatisfiable(requested, content); } else if (rangeSpec.contains("-")) { final String[] parts = rangeSpec.split("-"); return ensureSatisfiable(Range.closed(Long.parseLong(parts[0]), Long.parseLong(parts[1])), content); } else { log.warn("Malformed HTTP Range value: {}, ignoring it", rangeHeader); } } else { log.warn("Unsupported non-byte or multiple HTTP Ranges: {}; sending complete content", rangeHeader); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Problem parsing Range value: {}, ignoring", rangeHeader, e); } else { log.warn("Problem parsing Range value: {}, ignoring: {}", rangeHeader, e.toString()); } } } return WHOLE_RANGE; } }
RangeParser extends ComponentSupport { public List<Range<Long>> parseRangeSpec(final String rangeHeader, long size) { Range<Long> content = Range.closed(0L, size - 1L); if (!Strings.isNullOrEmpty(rangeHeader)) { try { if (rangeHeader.startsWith("bytes=") && rangeHeader.length() > 6 && !rangeHeader.contains(",")) { final String rangeSpec = rangeHeader.substring(6, rangeHeader.length()); if (rangeSpec.startsWith("-")) { final long byteCount = Long.parseLong(rangeSpec.substring(1)); if (byteCount > size) { return UNSATISFIABLE; } final Range<Long> suffix = Range.atLeast(size - byteCount); return ensureSatisfiable(suffix, content); } else if (rangeSpec.endsWith("-")) { final Range<Long> requested = Range.atLeast(Long.parseLong(rangeSpec.substring(0, rangeSpec.length() - 1))); return ensureSatisfiable(requested, content); } else if (rangeSpec.contains("-")) { final String[] parts = rangeSpec.split("-"); return ensureSatisfiable(Range.closed(Long.parseLong(parts[0]), Long.parseLong(parts[1])), content); } else { log.warn("Malformed HTTP Range value: {}, ignoring it", rangeHeader); } } else { log.warn("Unsupported non-byte or multiple HTTP Ranges: {}; sending complete content", rangeHeader); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Problem parsing Range value: {}, ignoring", rangeHeader, e); } else { log.warn("Problem parsing Range value: {}, ignoring: {}", rangeHeader, e.toString()); } } } return WHOLE_RANGE; }  }
RangeParser extends ComponentSupport { public List<Range<Long>> parseRangeSpec(final String rangeHeader, long size) { Range<Long> content = Range.closed(0L, size - 1L); if (!Strings.isNullOrEmpty(rangeHeader)) { try { if (rangeHeader.startsWith("bytes=") && rangeHeader.length() > 6 && !rangeHeader.contains(",")) { final String rangeSpec = rangeHeader.substring(6, rangeHeader.length()); if (rangeSpec.startsWith("-")) { final long byteCount = Long.parseLong(rangeSpec.substring(1)); if (byteCount > size) { return UNSATISFIABLE; } final Range<Long> suffix = Range.atLeast(size - byteCount); return ensureSatisfiable(suffix, content); } else if (rangeSpec.endsWith("-")) { final Range<Long> requested = Range.atLeast(Long.parseLong(rangeSpec.substring(0, rangeSpec.length() - 1))); return ensureSatisfiable(requested, content); } else if (rangeSpec.contains("-")) { final String[] parts = rangeSpec.split("-"); return ensureSatisfiable(Range.closed(Long.parseLong(parts[0]), Long.parseLong(parts[1])), content); } else { log.warn("Malformed HTTP Range value: {}, ignoring it", rangeHeader); } } else { log.warn("Unsupported non-byte or multiple HTTP Ranges: {}; sending complete content", rangeHeader); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Problem parsing Range value: {}, ignoring", rangeHeader, e); } else { log.warn("Problem parsing Range value: {}, ignoring: {}", rangeHeader, e.toString()); } } } return WHOLE_RANGE; }  List<Range<Long>> parseRangeSpec(final String rangeHeader, long size); }
RangeParser extends ComponentSupport { public List<Range<Long>> parseRangeSpec(final String rangeHeader, long size) { Range<Long> content = Range.closed(0L, size - 1L); if (!Strings.isNullOrEmpty(rangeHeader)) { try { if (rangeHeader.startsWith("bytes=") && rangeHeader.length() > 6 && !rangeHeader.contains(",")) { final String rangeSpec = rangeHeader.substring(6, rangeHeader.length()); if (rangeSpec.startsWith("-")) { final long byteCount = Long.parseLong(rangeSpec.substring(1)); if (byteCount > size) { return UNSATISFIABLE; } final Range<Long> suffix = Range.atLeast(size - byteCount); return ensureSatisfiable(suffix, content); } else if (rangeSpec.endsWith("-")) { final Range<Long> requested = Range.atLeast(Long.parseLong(rangeSpec.substring(0, rangeSpec.length() - 1))); return ensureSatisfiable(requested, content); } else if (rangeSpec.contains("-")) { final String[] parts = rangeSpec.split("-"); return ensureSatisfiable(Range.closed(Long.parseLong(parts[0]), Long.parseLong(parts[1])), content); } else { log.warn("Malformed HTTP Range value: {}, ignoring it", rangeHeader); } } else { log.warn("Unsupported non-byte or multiple HTTP Ranges: {}; sending complete content", rangeHeader); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Problem parsing Range value: {}, ignoring", rangeHeader, e); } else { log.warn("Problem parsing Range value: {}, ignoring: {}", rangeHeader, e.toString()); } } } return WHOLE_RANGE; }  List<Range<Long>> parseRangeSpec(final String rangeHeader, long size); static final List<Range<Long>> UNSATISFIABLE; static final List<Range<Long>> WHOLE_RANGE; }