SimpleCacheSpan extends CacheSpan { @Nullable public static SimpleCacheSpan createCacheEntry(File file, long length, CachedContentIndex index) { return createCacheEntry(file, length, C.TIME_UNSET, index); } private  SimpleCacheSpan(
      String key, long position, long length, long lastTouchTimestamp, @Nullable File file); static File getCacheFile(File cacheDir, int id, long position, long timestamp); static SimpleCacheSpan createLookup(String key, long position); static SimpleCacheSpan createOpenHole(String key, long position); static SimpleCacheSpan createClosedHole(String key, long position, long length); @Nullable static SimpleCacheSpan createCacheEntry(File file, long length, CachedContentIndex index); @Nullable static SimpleCacheSpan createCacheEntry(
      File file, long length, long lastTouchTimestamp, CachedContentIndex index); SimpleCacheSpan copyWithFileAndLastTouchTimestamp(File file, long lastTouchTimestamp);  }
@Test public void testUpgradeFileName() throws Exception { String key = "abc%def"; int id = index.assignIdForKey(key); File v3file = createTestFile(id + ".0.1.v3.exo"); File v2file = createTestFile("abc%25def.1.2.v2.exo"); File wrongEscapedV2file = createTestFile("abc%2Gdef.3.4.v2.exo"); File v1File = createTestFile("abc%def.5.6.v1.exo"); for (File file : cacheDir.listFiles()) { SimpleCacheSpan cacheEntry = SimpleCacheSpan.createCacheEntry(file, file.length(), index); if (file.equals(wrongEscapedV2file)) { assertThat(cacheEntry).isNull(); } else { assertThat(cacheEntry).isNotNull(); } } assertThat(v3file.exists()).isTrue(); assertThat(v2file.exists()).isFalse(); assertThat(wrongEscapedV2file.exists()).isTrue(); assertThat(v1File.exists()).isFalse(); File[] files = cacheDir.listFiles(); assertThat(files).hasLength(4); Set<String> keys = index.getKeys(); assertWithMessage("There should be only one key for all files.").that(keys).hasSize(1); assertThat(keys).contains(key); TreeSet<SimpleCacheSpan> spans = index.get(key).getSpans(); assertWithMessage("upgradeOldFiles() shouldn't add any spans.").that(spans.isEmpty()).isTrue(); LongSparseArray<Long> cachedPositions = new LongSparseArray<>(); for (File file : files) { SimpleCacheSpan cacheSpan = SimpleCacheSpan.createCacheEntry(file, file.length(), index); if (cacheSpan != null) { assertThat(cacheSpan.key).isEqualTo(key); cachedPositions.put(cacheSpan.position, cacheSpan.lastTouchTimestamp); } } assertThat(cachedPositions.get(0)).isEqualTo(1); assertThat(cachedPositions.get(1)).isEqualTo(2); assertThat(cachedPositions.get(5)).isEqualTo(6); }