Refactoring DataSpec constructor calls to use DataSpec.withUri() and DataSpec.subrange().

This reduces the number of calls to the DataSpec constructor and minimizes the number of files that need to be updated when adding a new DataSpec parameter (ex: followup []

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=205719005
This commit is contained in:
sammon 2018-07-23 13:56:03 -07:00 committed by Oliver Woodman
parent 61b838f414
commit 01b69854ff
2 changed files with 2 additions and 17 deletions

View File

@ -622,15 +622,7 @@ public class CronetDataSource extends BaseDataSource implements HttpDataSource {
request.followRedirect();
} else {
currentUrlRequest.cancel();
DataSpec redirectUrlDataSpec =
new DataSpec(
Uri.parse(newLocationUrl),
currentDataSpec.postBody,
currentDataSpec.absoluteStreamPosition,
currentDataSpec.position,
currentDataSpec.length,
currentDataSpec.key,
currentDataSpec.flags);
DataSpec redirectUrlDataSpec = currentDataSpec.withUri(Uri.parse(newLocationUrl));
UrlRequest.Builder requestBuilder;
try {
requestBuilder = buildRequestBuilder(redirectUrlDataSpec);

View File

@ -56,14 +56,7 @@ public final class TeeDataSource implements DataSource {
}
if (dataSpec.length == C.LENGTH_UNSET && bytesRemaining != C.LENGTH_UNSET) {
// Reconstruct dataSpec in order to provide the resolved length to the sink.
dataSpec =
new DataSpec(
dataSpec.uri,
dataSpec.absoluteStreamPosition,
dataSpec.position,
bytesRemaining,
dataSpec.key,
dataSpec.flags);
dataSpec = dataSpec.subrange(0, bytesRemaining);
}
dataSinkNeedsClosing = true;
dataSink.open(dataSpec);