Java Code Examples for com.danikula.videocache.file.FileNameGenerator

The following examples show how to use com.danikula.videocache.file.FileNameGenerator. These examples are extracted from open source projects. 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
@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
@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
@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
@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 Project: imsdk-android   Source File: HttpProxyUtil.java    License: 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 Project: AndriodVideoCache   Source File: Config.java    License: 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 Project: DKVideoPlayer   Source File: Config.java    License: 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 Project: GSYVideoPlayer   Source File: Config.java    License: 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 Project: AndroidVideoCache   Source File: Config.java    License: 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
private File file(File parent, String url) {
    FileNameGenerator fileNameGenerator = new Md5FileNameGenerator();
    String name = fileNameGenerator.generate(url);
    return new File(parent, name);
}
 
Example 11
Source Project: AndriodVideoCache   Source File: FileNameGeneratorTest.java    License: 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 Project: AndriodVideoCache   Source File: FileNameGeneratorTest.java    License: 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 Project: GSYVideoPlayer   Source File: ProxyCacheManager.java    License: Apache License 2.0 4 votes vote down vote up
public static void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
    ProxyCacheManager.fileNameGenerator = fileNameGenerator;
}
 
Example 14
private File file(File parent, String url) {
    FileNameGenerator fileNameGenerator = new Md5FileNameGenerator();
    String name = fileNameGenerator.generate(url);
    return new File(parent, name);
}
 
Example 15
Source Project: AndroidVideoCache   Source File: FileNameGeneratorTest.java    License: 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 Project: AndroidVideoCache   Source File: FileNameGeneratorTest.java    License: 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();
}