com.danikula.videocache.file.Md5FileNameGenerator Java Examples
The following examples show how to use
com.danikula.videocache.file.Md5FileNameGenerator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpProxyCacheServerTest.java From AndriodVideoCache with Apache License 2.0 | 6 votes |
@Test public void testProxyContentWithPartialCache() throws Exception { File cacheDir = RuntimeEnvironment.application.getExternalCacheDir(); File file = new File(cacheDir, new Md5FileNameGenerator().generate(HTTP_DATA_URL)); int partialCacheSize = 1000; byte[] partialData = ProxyCacheTestUtils.generate(partialCacheSize); File partialCacheFile = ProxyCacheTestUtils.getTempFile(file); IoUtils.saveToFile(partialData, partialCacheFile); HttpProxyCacheServer proxy = newProxy(cacheDir); Response response = readProxyResponse(proxy, HTTP_DATA_URL); proxy.shutdown(); byte[] expected = loadAssetFile(ASSETS_DATA_NAME); System.arraycopy(partialData, 0, expected, 0, partialCacheSize); assertThat(response.data).isEqualTo(expected); }
Example #2
Source File: HttpProxyCacheServerTest.java From AndriodVideoCache with Apache License 2.0 | 6 votes |
@Test public void testGetProxiedUrlForPartialCache() throws Exception { File cacheDir = RuntimeEnvironment.application.getExternalCacheDir(); File file = new File(cacheDir, new Md5FileNameGenerator().generate(HTTP_DATA_URL)); int partialCacheSize = 1000; byte[] partialData = ProxyCacheTestUtils.generate(partialCacheSize); File partialCacheFile = ProxyCacheTestUtils.getTempFile(file); IoUtils.saveToFile(partialData, partialCacheFile); HttpProxyCacheServer proxy = newProxy(cacheFolder); String expectedUrl = "http://127.0.0.1:" + getPort(proxy) + "/" + ProxyCacheUtils.encode(HTTP_DATA_URL); assertThat(proxy.getProxyUrl(HTTP_DATA_URL)).isEqualTo(expectedUrl); assertThat(proxy.getProxyUrl(HTTP_DATA_URL, true)).isEqualTo(expectedUrl); assertThat(proxy.getProxyUrl(HTTP_DATA_URL, false)).isEqualTo(expectedUrl); proxy.shutdown(); }
Example #3
Source File: HttpProxyCacheServerTest.java From AndriodVideoCache with Apache License 2.0 | 6 votes |
@Test public void testTrimFileCacheForTotalCountLru() throws Exception { FileNameGenerator fileNameGenerator = new Md5FileNameGenerator(); HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(RuntimeEnvironment.application) .cacheDirectory(cacheFolder) .fileNameGenerator(fileNameGenerator) .maxCacheFilesCount(2) .build(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_ONE_REDIRECT), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_ONE_REDIRECT))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_3_REDIRECTS), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_3_REDIRECTS))).exists(); waitForAsyncTrimming(); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).doesNotExist(); }
Example #4
Source File: HttpProxyCacheServerTest.java From AndriodVideoCache with Apache License 2.0 | 6 votes |
@Test public void testTrimFileCacheForTotalSizeLru() throws Exception { FileNameGenerator fileNameGenerator = new Md5FileNameGenerator(); HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(RuntimeEnvironment.application) .cacheDirectory(cacheFolder) .fileNameGenerator(fileNameGenerator) .maxCacheSize(HTTP_DATA_SIZE * 3 - 1) .build(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_ONE_REDIRECT), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_ONE_REDIRECT))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_3_REDIRECTS), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_3_REDIRECTS))).exists(); waitForAsyncTrimming(); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).doesNotExist(); }
Example #5
Source File: HttpProxyCacheServerTest.java From AndroidVideoCache with Apache License 2.0 | 6 votes |
@Test public void testTrimFileCacheForTotalSizeLru() throws Exception { FileNameGenerator fileNameGenerator = new Md5FileNameGenerator(); HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(RuntimeEnvironment.application) .cacheDirectory(cacheFolder) .fileNameGenerator(fileNameGenerator) .maxCacheSize(HTTP_DATA_SIZE * 3 - 1) .build(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_ONE_REDIRECT), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_ONE_REDIRECT))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_3_REDIRECTS), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_3_REDIRECTS))).exists(); waitForAsyncTrimming(); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).doesNotExist(); }
Example #6
Source File: HttpProxyCacheServerTest.java From AndroidVideoCache with Apache License 2.0 | 6 votes |
@Test public void testTrimFileCacheForTotalCountLru() throws Exception { FileNameGenerator fileNameGenerator = new Md5FileNameGenerator(); HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(RuntimeEnvironment.application) .cacheDirectory(cacheFolder) .fileNameGenerator(fileNameGenerator) .maxCacheFilesCount(2) .build(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_ONE_REDIRECT), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_ONE_REDIRECT))).exists(); readProxyResponse(proxy, proxy.getProxyUrl(HTTP_DATA_URL_3_REDIRECTS), 0); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL_3_REDIRECTS))).exists(); waitForAsyncTrimming(); assertThat(new File(cacheFolder, fileNameGenerator.generate(HTTP_DATA_URL))).doesNotExist(); }
Example #7
Source File: HttpProxyCacheServerTest.java From AndroidVideoCache with Apache License 2.0 | 6 votes |
@Test public void testGetProxiedUrlForPartialCache() throws Exception { File cacheDir = RuntimeEnvironment.application.getExternalCacheDir(); File file = new File(cacheDir, new Md5FileNameGenerator().generate(HTTP_DATA_URL)); int partialCacheSize = 1000; byte[] partialData = ProxyCacheTestUtils.generate(partialCacheSize); File partialCacheFile = ProxyCacheTestUtils.getTempFile(file); IoUtils.saveToFile(partialData, partialCacheFile); HttpProxyCacheServer proxy = newProxy(cacheFolder); String expectedUrl = "http://127.0.0.1:" + getPort(proxy) + "/" + ProxyCacheUtils.encode(HTTP_DATA_URL); assertThat(proxy.getProxyUrl(HTTP_DATA_URL)).isEqualTo(expectedUrl); assertThat(proxy.getProxyUrl(HTTP_DATA_URL, true)).isEqualTo(expectedUrl); assertThat(proxy.getProxyUrl(HTTP_DATA_URL, false)).isEqualTo(expectedUrl); proxy.shutdown(); }
Example #8
Source File: HttpProxyCacheServerTest.java From AndroidVideoCache with Apache License 2.0 | 6 votes |
@Test public void testProxyContentWithPartialCache() throws Exception { File cacheDir = RuntimeEnvironment.application.getExternalCacheDir(); File file = new File(cacheDir, new Md5FileNameGenerator().generate(HTTP_DATA_URL)); int partialCacheSize = 1000; byte[] partialData = ProxyCacheTestUtils.generate(partialCacheSize); File partialCacheFile = ProxyCacheTestUtils.getTempFile(file); IoUtils.saveToFile(partialData, partialCacheFile); HttpProxyCacheServer proxy = newProxy(cacheDir); Response response = readProxyResponse(proxy, HTTP_DATA_URL); proxy.shutdown(); byte[] expected = loadAssetFile(ASSETS_DATA_NAME); System.arraycopy(partialData, 0, expected, 0, partialCacheSize); assertThat(response.data).isEqualTo(expected); }
Example #9
Source File: HttpProxyCacheServer.java From AndroidVideoCache with Apache License 2.0 | 5 votes |
public Builder(Context context) { this.sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(context); this.cacheRoot = StorageUtils.getIndividualCacheDirectory(context); this.diskUsage = new TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE); this.fileNameGenerator = new Md5FileNameGenerator(); this.headerInjector = new EmptyHeadersInjector(); }
Example #10
Source File: VideoCacheManager.java From youqu_master with Apache License 2.0 | 5 votes |
/** * 删除url对应默认缓存文件 * @return 返回缓存是否删除成功 */ public static boolean clearDefaultCache(Context context, String url) { Md5FileNameGenerator md5FileNameGenerator = new Md5FileNameGenerator(); String name = md5FileNameGenerator.generate(url); String pathTmp = StorageUtil.getIndividualCacheDirectory (context.getApplicationContext()).getAbsolutePath() + File.separator + name + ".download"; String path = StorageUtil.getIndividualCacheDirectory (context.getApplicationContext()).getAbsolutePath() + File.separator + name; return StorageUtil.deleteFile(pathTmp) && StorageUtil.deleteFile(path); }
Example #11
Source File: Config.java From TigerVideo with Apache License 2.0 | 5 votes |
private HttpProxyCacheServer buildCacheProxy() { return new HttpProxyCacheServer .Builder(context.getApplicationContext()) .cacheDirectory(new File(Utils.getCacheDir(context))) .fileNameGenerator(new Md5FileNameGenerator() { @Override public String generate(String url) { return ProxyCacheUtils.computeMD5(url); } }) .maxCacheFilesCount(20) .build(); }
Example #12
Source File: HttpProxyCacheServer.java From GSYVideoPlayer with Apache License 2.0 | 5 votes |
public Builder(Context context) { this.sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(context); this.cacheRoot = StorageUtils.getIndividualCacheDirectory(context); this.diskUsage = new TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE); this.fileNameGenerator = new Md5FileNameGenerator(); this.headerInjector = new EmptyHeadersInjector(); }
Example #13
Source File: HttpProxyCacheServer.java From DKVideoPlayer with Apache License 2.0 | 5 votes |
public Builder(Context context) { this.sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(context); this.cacheRoot = StorageUtils.getIndividualCacheDirectory(context); this.diskUsage = new TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE); this.fileNameGenerator = new Md5FileNameGenerator(); this.headerInjector = new EmptyHeadersInjector(); }
Example #14
Source File: HttpProxyCacheServer.java From AndriodVideoCache with Apache License 2.0 | 5 votes |
public Builder(Context context) { this.sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(context); this.cacheRoot = StorageUtils.getIndividualCacheDirectory(context); this.diskUsage = new TotalSizeLruDiskUsage(DEFAULT_MAX_SIZE); this.fileNameGenerator = new Md5FileNameGenerator(); this.headerInjector = new EmptyHeadersInjector(); }
Example #15
Source File: FileNameGeneratorTest.java From AndriodVideoCache with Apache License 2.0 | 4 votes |
private String generateMd5Name(String rootFolder, String url) { FileNameGenerator nameGenerator = new Md5FileNameGenerator(); String name = nameGenerator.generate(url); return new File(rootFolder, name).getAbsolutePath(); }
Example #16
Source File: FileNameGeneratorTest.java From AndriodVideoCache with Apache License 2.0 | 4 votes |
@Test(expected = NullPointerException.class) public void testAssertNullUrl() throws Exception { FileNameGenerator nameGenerator = new Md5FileNameGenerator(); nameGenerator.generate(null); fail("Url should be not null"); }
Example #17
Source File: HttpProxyCacheServerTest.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
private File file(File parent, String url) { FileNameGenerator fileNameGenerator = new Md5FileNameGenerator(); String name = fileNameGenerator.generate(url); return new File(parent, name); }
Example #18
Source File: FileNameGeneratorTest.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
@Test(expected = NullPointerException.class) public void testAssertNullUrl() throws Exception { FileNameGenerator nameGenerator = new Md5FileNameGenerator(); nameGenerator.generate(null); fail("Url should be not null"); }
Example #19
Source File: FileNameGeneratorTest.java From AndroidVideoCache with Apache License 2.0 | 4 votes |
private String generateMd5Name(String rootFolder, String url) { FileNameGenerator nameGenerator = new Md5FileNameGenerator(); String name = nameGenerator.generate(url); return new File(rootFolder, name).getAbsolutePath(); }
Example #20
Source File: HttpProxyCacheServerTest.java From AndriodVideoCache with Apache License 2.0 | 4 votes |
private File file(File parent, String url) { FileNameGenerator fileNameGenerator = new Md5FileNameGenerator(); String name = fileNameGenerator.generate(url); return new File(parent, name); }