Default to respecting the DataSpec cache fragmentation flag

Issue: #4253
PiperOrigin-RevId: 230497544
This commit is contained in:
olly 2019-01-23 10:51:02 +00:00 committed by Oliver Woodman
parent 52f25f6ea8
commit 3a54d744b9
3 changed files with 2 additions and 35 deletions

View file

@ -110,10 +110,8 @@ public final class 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(

View file

@ -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;
@ -123,20 +122,6 @@ public final class CacheDataSink implements DataSink {
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
@ -146,10 +131,7 @@ public final class CacheDataSink implements DataSink {
}
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();

View file

@ -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) {
@ -51,22 +50,10 @@ public final class CacheDataSinkFactory implements DataSink.Factory {
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;
}
}