com.danikula.videocache.file.FileNameGenerator Java Examples

The following examples show how to use com.danikula.videocache.file.FileNameGenerator. 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 vote down vote up
@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 #2
Source File: HttpProxyCacheServerTest.java    From AndriodVideoCache with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: HttpProxyCacheServerTest.java    From AndroidVideoCache with Apache License 2.0 6 votes vote down vote up
@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 AndroidVideoCache with Apache License 2.0 6 votes vote down vote up
@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: HttpProxyUtil.java    From imsdk-android with MIT License 5 votes vote down vote up
private static HttpProxyCacheServer newProxy(Context context) {
    return new HttpProxyCacheServer.Builder(context)
            .fileNameGenerator(new FileNameGenerator() {
                @Override
                public String generate(String url) {
                    return  findRealUrl(url);
                }
            })
            .build();
}
 
Example #6
Source File: Config.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example #7
Source File: Config.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example #8
Source File: Config.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example #9
Source File: Config.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
Config(File cacheRoot, FileNameGenerator fileNameGenerator, DiskUsage diskUsage, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.cacheRoot = cacheRoot;
    this.fileNameGenerator = fileNameGenerator;
    this.diskUsage = diskUsage;
    this.sourceInfoStorage = sourceInfoStorage;
    this.headerInjector = headerInjector;
}
 
Example #10
Source File: HttpProxyCacheServerTest.java    From AndriodVideoCache with Apache License 2.0 4 votes vote down vote up
private File file(File parent, String url) {
    FileNameGenerator fileNameGenerator = new Md5FileNameGenerator();
    String name = fileNameGenerator.generate(url);
    return new File(parent, name);
}
 
Example #11
Source File: FileNameGeneratorTest.java    From AndriodVideoCache with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testAssertNullUrl() throws Exception {
    FileNameGenerator nameGenerator = new Md5FileNameGenerator();
    nameGenerator.generate(null);
    fail("Url should be not null");
}
 
Example #12
Source File: FileNameGeneratorTest.java    From AndriodVideoCache with Apache License 2.0 4 votes vote down vote up
private String generateMd5Name(String rootFolder, String url) {
    FileNameGenerator nameGenerator = new Md5FileNameGenerator();
    String name = nameGenerator.generate(url);
    return new File(rootFolder, name).getAbsolutePath();
}
 
Example #13
Source File: ProxyCacheManager.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public static void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
    ProxyCacheManager.fileNameGenerator = fileNameGenerator;
}
 
Example #14
Source File: HttpProxyCacheServerTest.java    From AndroidVideoCache with Apache License 2.0 4 votes vote down vote up
private File file(File parent, String url) {
    FileNameGenerator fileNameGenerator = new Md5FileNameGenerator();
    String name = fileNameGenerator.generate(url);
    return new File(parent, name);
}
 
Example #15
Source File: FileNameGeneratorTest.java    From AndroidVideoCache with Apache License 2.0 4 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testAssertNullUrl() throws Exception {
    FileNameGenerator nameGenerator = new Md5FileNameGenerator();
    nameGenerator.generate(null);
    fail("Url should be not null");
}
 
Example #16
Source File: FileNameGeneratorTest.java    From AndroidVideoCache with Apache License 2.0 4 votes vote down vote up
private String generateMd5Name(String rootFolder, String url) {
    FileNameGenerator nameGenerator = new Md5FileNameGenerator();
    String name = nameGenerator.generate(url);
    return new File(rootFolder, name).getAbsolutePath();
}