From 5512aae4518ed563d645eea3ed9b5f3be4dbb964 Mon Sep 17 00:00:00 2001 From: eguven Date: Wed, 14 Sep 2016 07:05:15 -0700 Subject: [PATCH] Revert CacheSpan EOS changes. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=133123235 --- .../upstream/cache/CacheSpanTest.java | 21 +++++------- .../exoplayer2/upstream/cache/CacheSpan.java | 34 ++++++++----------- .../upstream/cache/SimpleCache.java | 2 +- 3 files changed, 24 insertions(+), 33 deletions(-) diff --git a/library/src/androidTest/java/com/google/android/exoplayer2/upstream/cache/CacheSpanTest.java b/library/src/androidTest/java/com/google/android/exoplayer2/upstream/cache/CacheSpanTest.java index 4d000c7619..38008c814e 100644 --- a/library/src/androidTest/java/com/google/android/exoplayer2/upstream/cache/CacheSpanTest.java +++ b/library/src/androidTest/java/com/google/android/exoplayer2/upstream/cache/CacheSpanTest.java @@ -26,10 +26,10 @@ import junit.framework.TestCase; public class CacheSpanTest extends TestCase { public void testCacheFile() throws Exception { - assertCacheSpan(new File("parent"), "key", 0, 0, true); - assertCacheSpan(new File("parent/"), "key", 1, 2, false); - assertCacheSpan(new File("parent"), "<>:\"/\\|?*%", 1, 2, true); - assertCacheSpan(new File("/"), "key", 1, 2, false); + assertCacheSpan(new File("parent"), "key", 0, 0); + assertCacheSpan(new File("parent/"), "key", 1, 2); + assertCacheSpan(new File("parent"), "<>:\"/\\|?*%", 1, 2); + assertCacheSpan(new File("/"), "key", 1, 2); assertNullCacheSpan(new File("parent"), "", 1, 2); assertNullCacheSpan(new File("parent"), "key", -1, 2); @@ -44,7 +44,7 @@ public class CacheSpanTest extends TestCase { + "A standalone carriage-return character \r" + "A next-line character \u0085" + "A line-separator character \u2028" - + "A paragraph-separator character \u2029", 1, 2, true); + + "A paragraph-separator character \u2029", 1, 2); } public void testCacheFileNameRandomData() throws Exception { @@ -54,14 +54,12 @@ public class CacheSpanTest extends TestCase { String key = TestUtil.buildTestString(1000, random); long offset = Math.abs(random.nextLong()); long lastAccessTimestamp = Math.abs(random.nextLong()); - boolean isEOS = random.nextBoolean(); - assertCacheSpan(parent, key, offset, lastAccessTimestamp, isEOS); + assertCacheSpan(parent, key, offset, lastAccessTimestamp); } } - private void assertCacheSpan(File parent, String key, long offset, long lastAccessTimestamp, - boolean isEOS) { - File cacheFile = CacheSpan.getCacheFileName(parent, key, offset, lastAccessTimestamp, isEOS); + private void assertCacheSpan(File parent, String key, long offset, long lastAccessTimestamp) { + File cacheFile = CacheSpan.getCacheFileName(parent, key, offset, lastAccessTimestamp); CacheSpan cacheSpan = CacheSpan.createCacheEntry(cacheFile); String message = cacheFile.toString(); assertNotNull(message, cacheSpan); @@ -69,12 +67,11 @@ public class CacheSpanTest extends TestCase { assertEquals(message, key, cacheSpan.key); assertEquals(message, offset, cacheSpan.position); assertEquals(message, lastAccessTimestamp, cacheSpan.lastAccessTimestamp); - assertEquals(message, isEOS, cacheSpan.isEOS); } private void assertNullCacheSpan(File parent, String key, long offset, long lastAccessTimestamp) { - File cacheFile = CacheSpan.getCacheFileName(parent, key, offset, lastAccessTimestamp, false); + File cacheFile = CacheSpan.getCacheFileName(parent, key, offset, lastAccessTimestamp); CacheSpan cacheSpan = CacheSpan.createCacheEntry(cacheFile); assertNull(cacheFile.toString(), cacheSpan); } diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheSpan.java b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheSpan.java index ffece2e07f..d706f4f006 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheSpan.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheSpan.java @@ -30,7 +30,7 @@ public final class CacheSpan implements Comparable { private static final Pattern CACHE_FILE_PATTERN_V1 = Pattern.compile("^(.+)\\.(\\d+)\\.(\\d+)\\.v1\\.exo$", Pattern.DOTALL); private static final Pattern CACHE_FILE_PATTERN_V2 = - Pattern.compile("^(.+)\\.(\\d+)(E?)\\.(\\d+)\\.v2\\.exo$", Pattern.DOTALL); + Pattern.compile("^(.+)\\.(\\d+)\\.(\\d+)\\.v2\\.exo$", Pattern.DOTALL); /** * The cache key that uniquely identifies the original stream. @@ -56,27 +56,23 @@ public final class CacheSpan implements Comparable { * The last access timestamp, or {@link C#TIME_UNSET} if {@link #isCached} is false. */ public final long lastAccessTimestamp; - /** - * Whether the {@link CacheSpan} is know to contain the end of the original stream. - */ - public final boolean isEOS; public static File getCacheFileName(File cacheDir, String key, long offset, - long lastAccessTimestamp, boolean isEOS) { - return new File(cacheDir, Util.escapeFileName(key) + "." + offset + (isEOS ? "E" : "") + "." - + lastAccessTimestamp + SUFFIX); + long lastAccessTimestamp) { + return new File(cacheDir, + Util.escapeFileName(key) + "." + offset + "." + lastAccessTimestamp + SUFFIX); } public static CacheSpan createLookup(String key, long position) { - return new CacheSpan(key, position, C.LENGTH_UNSET, false, C.TIME_UNSET, null, false); + return new CacheSpan(key, position, C.LENGTH_UNSET, false, C.TIME_UNSET, null); } public static CacheSpan createOpenHole(String key, long position) { - return new CacheSpan(key, position, C.LENGTH_UNSET, false, C.TIME_UNSET, null, false); + return new CacheSpan(key, position, C.LENGTH_UNSET, false, C.TIME_UNSET, null); } public static CacheSpan createClosedHole(String key, long position, long length) { - return new CacheSpan(key, position, length, false, C.TIME_UNSET, null, false); + return new CacheSpan(key, position, length, false, C.TIME_UNSET, null); } /** @@ -92,8 +88,7 @@ public final class CacheSpan implements Comparable { } String key = Util.unescapeFileName(matcher.group(1)); return key == null ? null : createCacheEntry( - key, Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(4)), file, - "E".equals(matcher.group(3))); + key, Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(3)), file); } static File upgradeIfNeeded(File file) { @@ -103,26 +98,25 @@ public final class CacheSpan implements Comparable { } String key = matcher.group(1); // Keys were not escaped in version 1. File newCacheFile = getCacheFileName(file.getParentFile(), key, - Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(3)), false); + Long.parseLong(matcher.group(2)), Long.parseLong(matcher.group(3))); file.renameTo(newCacheFile); return newCacheFile; } private static CacheSpan createCacheEntry(String key, long position, long lastAccessTimestamp, - File file, boolean isEOS) { - return new CacheSpan(key, position, file.length(), true, lastAccessTimestamp, file, isEOS); + File file) { + return new CacheSpan(key, position, file.length(), true, lastAccessTimestamp, file); } // Visible for testing. CacheSpan(String key, long position, long length, boolean isCached, - long lastAccessTimestamp, File file, boolean isEOS) { + long lastAccessTimestamp, File file) { this.key = key; this.position = position; this.length = length; this.isCached = isCached; this.file = file; this.lastAccessTimestamp = lastAccessTimestamp; - this.isEOS = isEOS; } /** @@ -139,9 +133,9 @@ public final class CacheSpan implements Comparable { */ public CacheSpan touch() { long now = System.currentTimeMillis(); - File newCacheFile = getCacheFileName(file.getParentFile(), key, position, now, isEOS); + File newCacheFile = getCacheFileName(file.getParentFile(), key, position, now); file.renameTo(newCacheFile); - return createCacheEntry(key, position, now, newCacheFile, isEOS); + return createCacheEntry(key, position, now, newCacheFile); } @Override diff --git a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java index 9128ba99ca..a2f2596ad5 100644 --- a/library/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java +++ b/library/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java @@ -160,7 +160,7 @@ public final class SimpleCache implements Cache { cacheDir.mkdirs(); } evictor.onStartFile(this, key, position, maxLength); - return CacheSpan.getCacheFileName(cacheDir, key, position, System.currentTimeMillis(), false); + return CacheSpan.getCacheFileName(cacheDir, key, position, System.currentTimeMillis()); } @Override