@Test(expectedExceptions = IllegalArgumentException.class) public void validatesBytesReadThrowsWhenSettingRangeStartToContentLength() { final HttpDownloadContinuationMarker marker = new HttpDownloadContinuationMarker(STUB_ETAG, STUB_CONTENT_RANGE); marker.updateRangeStart(STUB_CONTENT_RANGE.contentLength()); }
void updateRangeStart(final long totalBytesRead) { final long nextStartInclusive = this.originalRangeStart + totalBytesRead; if (totalBytesRead < 0) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be negative", totalBytesRead)); } if (nextStartInclusive < this.currentRange.getStartInclusive()) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot decrease, previously [%d]", nextStartInclusive, this.currentRange.getStartInclusive())); } if (this.totalRangeSize < totalBytesRead) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be greater than expected number of bytes [%d]", totalBytesRead, this.totalRangeSize)); } if (this.currentRange.getEndInclusive() < nextStartInclusive) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot be greater than end of range [%d]", nextStartInclusive, this.currentRange.getEndInclusive())); } final BoundedRequest nextRange; try { nextRange = new BoundedRequest(nextStartInclusive, this.currentRange.getEndInclusive()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException("Failed to construct updated HttpRange: " + e.getMessage(), e); } this.currentRange = nextRange; }
HttpDownloadContinuationMarker { void updateRangeStart(final long totalBytesRead) { final long nextStartInclusive = this.originalRangeStart + totalBytesRead; if (totalBytesRead < 0) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be negative", totalBytesRead)); } if (nextStartInclusive < this.currentRange.getStartInclusive()) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot decrease, previously [%d]", nextStartInclusive, this.currentRange.getStartInclusive())); } if (this.totalRangeSize < totalBytesRead) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be greater than expected number of bytes [%d]", totalBytesRead, this.totalRangeSize)); } if (this.currentRange.getEndInclusive() < nextStartInclusive) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot be greater than end of range [%d]", nextStartInclusive, this.currentRange.getEndInclusive())); } final BoundedRequest nextRange; try { nextRange = new BoundedRequest(nextStartInclusive, this.currentRange.getEndInclusive()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException("Failed to construct updated HttpRange: " + e.getMessage(), e); } this.currentRange = nextRange; } }
HttpDownloadContinuationMarker { void updateRangeStart(final long totalBytesRead) { final long nextStartInclusive = this.originalRangeStart + totalBytesRead; if (totalBytesRead < 0) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be negative", totalBytesRead)); } if (nextStartInclusive < this.currentRange.getStartInclusive()) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot decrease, previously [%d]", nextStartInclusive, this.currentRange.getStartInclusive())); } if (this.totalRangeSize < totalBytesRead) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be greater than expected number of bytes [%d]", totalBytesRead, this.totalRangeSize)); } if (this.currentRange.getEndInclusive() < nextStartInclusive) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot be greater than end of range [%d]", nextStartInclusive, this.currentRange.getEndInclusive())); } final BoundedRequest nextRange; try { nextRange = new BoundedRequest(nextStartInclusive, this.currentRange.getEndInclusive()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException("Failed to construct updated HttpRange: " + e.getMessage(), e); } this.currentRange = nextRange; } HttpDownloadContinuationMarker(final String etag,
                                   final Response initialContentRange); }
HttpDownloadContinuationMarker { void updateRangeStart(final long totalBytesRead) { final long nextStartInclusive = this.originalRangeStart + totalBytesRead; if (totalBytesRead < 0) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be negative", totalBytesRead)); } if (nextStartInclusive < this.currentRange.getStartInclusive()) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot decrease, previously [%d]", nextStartInclusive, this.currentRange.getStartInclusive())); } if (this.totalRangeSize < totalBytesRead) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be greater than expected number of bytes [%d]", totalBytesRead, this.totalRangeSize)); } if (this.currentRange.getEndInclusive() < nextStartInclusive) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot be greater than end of range [%d]", nextStartInclusive, this.currentRange.getEndInclusive())); } final BoundedRequest nextRange; try { nextRange = new BoundedRequest(nextStartInclusive, this.currentRange.getEndInclusive()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException("Failed to construct updated HttpRange: " + e.getMessage(), e); } this.currentRange = nextRange; } HttpDownloadContinuationMarker(final String etag,
                                   final Response initialContentRange); @Override String toString(); }
HttpDownloadContinuationMarker { void updateRangeStart(final long totalBytesRead) { final long nextStartInclusive = this.originalRangeStart + totalBytesRead; if (totalBytesRead < 0) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be negative", totalBytesRead)); } if (nextStartInclusive < this.currentRange.getStartInclusive()) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot decrease, previously [%d]", nextStartInclusive, this.currentRange.getStartInclusive())); } if (this.totalRangeSize < totalBytesRead) { throw new IllegalArgumentException( String.format( "Bytes read [%d] cannot be greater than expected number of bytes [%d]", totalBytesRead, this.totalRangeSize)); } if (this.currentRange.getEndInclusive() < nextStartInclusive) { throw new IllegalArgumentException( String.format( "Next start position [%d] cannot be greater than end of range [%d]", nextStartInclusive, this.currentRange.getEndInclusive())); } final BoundedRequest nextRange; try { nextRange = new BoundedRequest(nextStartInclusive, this.currentRange.getEndInclusive()); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException("Failed to construct updated HttpRange: " + e.getMessage(), e); } this.currentRange = nextRange; } HttpDownloadContinuationMarker(final String etag,
                                   final Response initialContentRange); @Override String toString();  }