Skip to content

Commit

Permalink
Default to respecting the DataSpec cache fragmentation flag
Browse files Browse the repository at this point in the history
Issue: #4253
PiperOrigin-RevId: 230497544
  • Loading branch information
ojw28 committed Jan 29, 2019
1 parent 52f25f6 commit 3a54d74
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,8 @@ public DownloaderConstructorHelper(
? cacheReadDataSourceFactory
: new FileDataSourceFactory();
if (cacheWriteDataSinkFactory == null) {
CacheDataSinkFactory factory =
cacheWriteDataSinkFactory =
new CacheDataSinkFactory(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE);
factory.experimental_setRespectCacheFragmentationFlag(true);
cacheWriteDataSinkFactory = factory;
}
onlineCacheDataSourceFactory =
new CacheDataSourceFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public final class CacheDataSink implements DataSink {
private final int bufferSize;

private boolean syncFileDescriptor;
private boolean respectCacheFragmentationFlag;
private DataSpec dataSpec;
private long dataSpecFragmentSize;
private File file;
Expand Down Expand Up @@ -123,20 +122,6 @@ public void experimental_setSyncFileDescriptor(boolean syncFileDescriptor) {
this.syncFileDescriptor = syncFileDescriptor;
}

/**
* Sets whether this instance respects the {@link DataSpec#FLAG_ALLOW_CACHE_FRAGMENTATION} flag.
* If set to {@code false} requests will always be fragmented. If set to {@code true} requests
* will be fragmented only if the flag is set.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param respectCacheFragmentationFlag Whether to respect the {@link
* DataSpec#FLAG_ALLOW_CACHE_FRAGMENTATION} flag.
*/
public void experimental_setRespectCacheFragmentationFlag(boolean respectCacheFragmentationFlag) {
this.respectCacheFragmentationFlag = respectCacheFragmentationFlag;
}

@Override
public void open(DataSpec dataSpec) throws CacheDataSinkException {
if (dataSpec.length == C.LENGTH_UNSET
Expand All @@ -146,10 +131,7 @@ public void open(DataSpec dataSpec) throws CacheDataSinkException {
}
this.dataSpec = dataSpec;
this.dataSpecFragmentSize =
!respectCacheFragmentationFlag
|| dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION)
? fragmentSize
: Long.MAX_VALUE;
dataSpec.isFlagSet(DataSpec.FLAG_ALLOW_CACHE_FRAGMENTATION) ? fragmentSize : Long.MAX_VALUE;
dataSpecBytesWritten = 0;
try {
openNextOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public final class CacheDataSinkFactory implements DataSink.Factory {
private final int bufferSize;

private boolean syncFileDescriptor;
private boolean respectCacheFragmentationFlag;

/** @see CacheDataSink#CacheDataSink(Cache, long) */
public CacheDataSinkFactory(Cache cache, long fragmentSize) {
Expand All @@ -51,22 +50,10 @@ public CacheDataSinkFactory experimental_setSyncFileDescriptor(boolean syncFileD
return this;
}

/**
* See {@link CacheDataSink#experimental_setRespectCacheFragmentationFlag(boolean)}.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*/
public CacheDataSinkFactory experimental_setRespectCacheFragmentationFlag(
boolean respectCacheFragmentationFlag) {
this.respectCacheFragmentationFlag = respectCacheFragmentationFlag;
return this;
}

@Override
public DataSink createDataSink() {
CacheDataSink dataSink = new CacheDataSink(cache, fragmentSize, bufferSize);
dataSink.experimental_setSyncFileDescriptor(syncFileDescriptor);
dataSink.experimental_setRespectCacheFragmentationFlag(respectCacheFragmentationFlag);
return dataSink;
}
}

0 comments on commit 3a54d74

Please sign in to comment.