HttpClient { static ContentRange parseContentRange(String value) throws ParseException { final String prefix = "bytes "; if (!value.startsWith(prefix)) { throw new ParseException("Unrecognized bytes-unit (only \"bytes\" supported)", 0); } final int idx = value.indexOf('-', prefix.length()); if (idx <= 0) { throw new ParseException("Missing separator '-'.", prefix.length()); } final String firstString = value.substring(prefix.length(), idx); final long first; try { first = Long.parseLong(firstString); } catch (NumberFormatException e) { throw new ParseException("Invalid first-byte-pos " + firstString, prefix.length()); } final int dash = value.indexOf('/', idx); if (dash <= 0) { throw new ParseException("Missing separator '/'", idx); } final String lastString = value.substring(idx + 1, dash); final long last; try { last = Long.parseLong(lastString); } catch (NumberFormatException e) { throw new ParseException("Invalid last-byte-pos " + lastString, idx + 1); } final ContentRange range; try { range = new ContentRange(first, last); } catch (IllegalArgumentException e) { throw new ParseException(e.getMessage(), 0); } return range; } HttpClient(OkHttpClient okHttpClient); static HttpClient newHttpClient(); static HttpClient newHttpClient(OkHttpClient okHttpClient); void get(URI uri, Path output, Map<String, ? extends Credentials> credentials, HttpTransferListener listener); InputStream get(URI uri, Map<String, ? extends Credentials> credentials, HttpTransferListener listener); void partialGet(URI uri, List<ContentRange> ranges, Map<String, ? extends Credentials> credentials,
      RangeReceiver receiver, RangeTransferListener listener);  }
@Test(expected = ParseException.class) public void testParseContentRangeInvalidBytesUnit() throws ParseException { parseContentRange("byte 1-3/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeMissingSeparator() throws ParseException { parseContentRange("bytes 1 3/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeMissingFirst() throws ParseException { parseContentRange("bytes -3/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeInvalidFirst() throws ParseException { parseContentRange("bytes a-3/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeNegativeFirst() throws ParseException { parseContentRange("bytes -1-3/5"); }
@Test(expected = ParseException.class) public void testParseContentRangeMissingLast() throws ParseException { parseContentRange("bytes 1-/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeInvalidLast() throws ParseException { parseContentRange("bytes 1-a/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeNegativeLast() throws ParseException { parseContentRange("bytes 1--3/3"); }
@Test(expected = ParseException.class) public void testParseContentRangeMissingDash() throws ParseException { parseContentRange("bytes 1-3 3"); }
@Test public void testParseContentRangeMissingLength() throws ParseException { assertEquals(new ContentRange(1, 3), parseContentRange("bytes 1-3/")); }
@Test public void testParseContentRangeInvalidLength() throws ParseException { assertEquals(new ContentRange(1, 3), parseContentRange("bytes 1-3/b")); }
@Test public void testParseContentRangeIncorrectLength() throws ParseException { assertEquals(new ContentRange(1, 3), parseContentRange("bytes 1-3/4")); }
@Test(expected = ParseException.class) public void testParseContentRangeFirstLargerLast() throws ParseException { parseContentRange("bytes 3-1/3"); }
@Test public void testParseContentRangeNoLength() throws ParseException { assertEquals(new ContentRange(1, 3), parseContentRange("bytes 1-3/*")); }
@Test public void testParseContentRange() throws ParseException { assertEquals(new ContentRange(1, 3), parseContentRange("bytes 1-3/3")); }