### Question:
RangeHeaderParserUtil { public static RangeHeader parseRangeHeader(String rangeHeaderVal, long length) { long start = 0; long end = 0; boolean noStart = false; boolean readFull = false; boolean inValidRange = false; RangeHeader rangeHeader; Matcher matcher = RANGE_HEADER_MATCH_PATTERN.matcher(rangeHeaderVal); if (matcher.matches()) { if (!matcher.group("start").equals("")) { start = Long.parseLong(matcher.group("start")); } else { noStart = true; } if (!matcher.group("end").equals("")) { end = Long.parseLong(matcher.group("end")); } else { end = length - 1; } if (noStart) { if (end < length) { start = length - end; } else { start = 0; } end = length - 1; } else { if (start >= length) { readFull = true; if (end >= length) { inValidRange = true; } else { start = 0; end = length - 1; } } else { if (end >= length) { end = length - 1; } } } } else { start = 0; end = length - 1; readFull = true; } rangeHeader = new RangeHeader(start, end, readFull, inValidRange); return rangeHeader; } private  RangeHeaderParserUtil(); static RangeHeader parseRangeHeader(String rangeHeaderVal, long
      length);  }### Answer:
@Test public void testRangeHeaderParser() { RangeHeader rangeHeader; rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=0-8", 10); assertEquals(0, rangeHeader.getStartOffset()); assertEquals(8, rangeHeader.getEndOffset()); assertEquals(false, rangeHeader.isReadFull()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=0-0", 10); assertEquals(0, rangeHeader.getStartOffset()); assertEquals(0, rangeHeader.getEndOffset()); assertEquals(false, rangeHeader.isReadFull()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=11-10", 10); assertEquals(true, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=11-8", 10); assertEquals(0, rangeHeader.getStartOffset()); assertEquals(9, rangeHeader.getEndOffset()); assertEquals(true, rangeHeader.isReadFull()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("mb=11-8", 10); assertEquals(0, rangeHeader.getStartOffset()); assertEquals(9, rangeHeader.getEndOffset()); assertEquals(true, rangeHeader.isReadFull()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=-11-8", 10); assertEquals(0, rangeHeader.getStartOffset()); assertEquals(9, rangeHeader.getEndOffset()); assertEquals(true, rangeHeader.isReadFull()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=-6", 10); assertEquals(4, rangeHeader.getStartOffset()); assertEquals(9, rangeHeader.getEndOffset()); assertEquals(false, rangeHeader.isReadFull()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=-106", 10); assertEquals(0, rangeHeader.getStartOffset()); assertEquals(9, rangeHeader.getEndOffset()); assertEquals(false, rangeHeader.isInValidRange()); rangeHeader = RangeHeaderParserUtil.parseRangeHeader("bytes=3977248768" + "-4977248768", 4977248769L); assertEquals(3977248768L, rangeHeader.getStartOffset()); assertEquals(4977248768L, rangeHeader.getEndOffset()); assertEquals(false, rangeHeader.isInValidRange()); }