From 6373554d6a7f94ab8dba9b3f82bda928c7bd4dff Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 2 Jan 2019 15:43:11 +0000 Subject: [PATCH] Move syncFileDescriptor to use an experimental method PiperOrigin-RevId: 227520168 --- .../upstream/cache/CacheDataSink.java | 45 +++++++------------ .../android/exoplayer2/util/AtomicFile.java | 2 +- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java index 8d310015f8..63bc47504b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java @@ -43,8 +43,8 @@ public final class CacheDataSink implements DataSink { private final Cache cache; private final long maxCacheFileSize; private final int bufferSize; - private final boolean syncFileDescriptor; + private boolean syncFileDescriptor; private DataSpec dataSpec; private File file; private OutputStream outputStream; @@ -64,18 +64,6 @@ public final class CacheDataSink implements DataSink { } - /** - * Constructs a CacheDataSink using the {@link #DEFAULT_BUFFER_SIZE}. - * - * @param cache The cache into which data should be written. - * @param maxCacheFileSize The maximum size of a cache file, in bytes. If the sink is opened for - * a {@link DataSpec} whose size exceeds this value, then the data will be fragmented into - * multiple cache files. - */ - public CacheDataSink(Cache cache, long maxCacheFileSize) { - this(cache, maxCacheFileSize, DEFAULT_BUFFER_SIZE, true); - } - /** * Constructs a CacheDataSink using the {@link #DEFAULT_BUFFER_SIZE}. * @@ -83,10 +71,9 @@ public final class CacheDataSink implements DataSink { * @param maxCacheFileSize The maximum size of a cache file, in bytes. If the sink is opened for a * {@link DataSpec} whose size exceeds this value, then the data will be fragmented into * multiple cache files. - * @param syncFileDescriptor Whether file descriptors are sync'd when closing output streams. */ - public CacheDataSink(Cache cache, long maxCacheFileSize, boolean syncFileDescriptor) { - this(cache, maxCacheFileSize, DEFAULT_BUFFER_SIZE, syncFileDescriptor); + public CacheDataSink(Cache cache, long maxCacheFileSize) { + this(cache, maxCacheFileSize, DEFAULT_BUFFER_SIZE); } /** @@ -98,23 +85,21 @@ public final class CacheDataSink implements DataSink { * value disables buffering. */ public CacheDataSink(Cache cache, long maxCacheFileSize, int bufferSize) { - this(cache, maxCacheFileSize, bufferSize, true); - } - - /** - * @param cache The cache into which data should be written. - * @param maxCacheFileSize The maximum size of a cache file, in bytes. If the sink is opened for a - * {@link DataSpec} whose size exceeds this value, then the data will be fragmented into - * multiple cache files. - * @param bufferSize The buffer size in bytes for writing to a cache file. A zero or negative - * value disables buffering. - * @param syncFileDescriptor Whether file descriptors are sync'd when closing output streams. - */ - public CacheDataSink( - Cache cache, long maxCacheFileSize, int bufferSize, boolean syncFileDescriptor) { this.cache = Assertions.checkNotNull(cache); this.maxCacheFileSize = maxCacheFileSize; this.bufferSize = bufferSize; + syncFileDescriptor = true; + } + + /** + * Sets whether file descriptors are synced when closing output streams. + * + *

This method is experimental, and will be renamed or removed in a future release. It should + * only be called before the renderer is used. + * + * @param syncFileDescriptor Whether file descriptors are synced when closing output streams. + */ + public void experimental_setSyncFileDescriptor(boolean syncFileDescriptor) { this.syncFileDescriptor = syncFileDescriptor; } diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/AtomicFile.java b/library/core/src/main/java/com/google/android/exoplayer2/util/AtomicFile.java index 4bdee5ceea..2466d5a049 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/AtomicFile.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/AtomicFile.java @@ -29,7 +29,7 @@ import java.io.OutputStream; * has successfully completed. * *

Atomic file guarantees file integrity by ensuring that a file has been completely written and - * sync'd to disk before removing its backup. As long as the backup file exists, the original file + * synced to disk before removing its backup. As long as the backup file exists, the original file * is considered to be invalid (left over from a previous attempt to write the file). * *

Atomic file does not confer any file locking semantics. Do not use this class when the file