com.danikula.videocache.sourcestorage.SourceInfoStorageFactory Java Examples

The following examples show how to use com.danikula.videocache.sourcestorage.SourceInfoStorageFactory. 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: HttpProxyCacheTest.java    From AndroidVideoCache with Apache License 2.0 6 votes vote down vote up
@Test
public void testReuseSourceInfo() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File cacheFile = newCacheFile();
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(cacheFile));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");

    HttpUrlSource notOpenableSource = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache2 = new HttpProxyCache(notOpenableSource, new FileCache(cacheFile));
    Response response = processRequest(proxyCache2, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();

    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("image/jpeg");
}
 
Example #2
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with Apache License 2.0 6 votes vote down vote up
@Test
public void testReuseSourceInfo() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File cacheFile = newCacheFile();
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(cacheFile));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");

    HttpUrlSource notOpenableSource = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache2 = new HttpProxyCache(notOpenableSource, new FileCache(cacheFile));
    Response response = processRequest(proxyCache2, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();

    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("image/jpeg");
}
 
Example #3
Source File: HttpUrlSourceTest.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testHeaderInjectorNullNotAcceptable() throws Exception {
    HeaderInjector mockedHeaderInjector = Mockito.mock(HeaderInjector.class);
    when(mockedHeaderInjector.addHeaders(Mockito.anyString())).thenReturn(null);
    SourceInfoStorage emptySourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_ONE_REDIRECT, emptySourceInfoStorage, mockedHeaderInjector);
    source.open(0);
    fail("source.open should throw NPE!");
}
 
Example #4
Source File: HttpProxyCacheServer.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: HttpProxyCacheTest.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
@Test
public void testTouchSourceForExistedSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "cached/mime"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File file = newCacheFile();
    IoUtils.saveToFile(loadAssetFile(ASSETS_DATA_NAME), file);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(file));
    Response response = processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("cached/mime");
}
 
Example #6
Source File: HttpProxyCacheTest.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForExistedSourceInfoAndAbsentCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "image/jpg"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no cache file");
}
 
Example #7
Source File: HttpProxyCacheTest.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForAbsentSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no file and caches source info");
}
 
Example #8
Source File: HttpUrlSourceTest.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
@Test(expected = NullPointerException.class)
public void testHeaderInjectorNullNotAcceptable() throws Exception {
    HeaderInjector mockedHeaderInjector = Mockito.mock(HeaderInjector.class);
    when(mockedHeaderInjector.addHeaders(Mockito.anyString())).thenReturn(null);
    SourceInfoStorage emptySourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL_ONE_REDIRECT, emptySourceInfoStorage, mockedHeaderInjector);
    source.open(0);
    fail("source.open should throw NPE!");
}
 
Example #9
Source File: HttpProxyCacheServer.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
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: HttpProxyCacheServer.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
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 #11
Source File: HttpProxyCacheServer.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
@Test
public void testTouchSourceForExistedSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "cached/mime"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    File file = newCacheFile();
    IoUtils.saveToFile(loadAssetFile(ASSETS_DATA_NAME), file);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(file));
    Response response = processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
    assertThat(response.contentLength).isEqualTo(HTTP_DATA_SIZE);
    assertThat(response.contentType).isEqualTo("cached/mime");
}
 
Example #13
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForExistedSourceInfoAndAbsentCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newSourceInfoStorage(RuntimeEnvironment.application);
    sourceInfoStorage.put(HTTP_DATA_URL, new SourceInfo(HTTP_DATA_URL, HTTP_DATA_SIZE, "image/jpg"));
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no cache file");
}
 
Example #14
Source File: HttpProxyCacheTest.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
@Test(expected = ProxyCacheException.class)
public void testTouchSourceForAbsentSourceInfoAndCache() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    HttpUrlSource source = ProxyCacheTestUtils.newNotOpenableHttpUrlSource(HTTP_DATA_URL, sourceInfoStorage);
    HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(newCacheFile()));
    processRequest(proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
    proxyCache.shutdown();
    fail("Angry source should throw error! There is no file and caches source info");
}
 
Example #15
Source File: HttpUrlSource.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url) {
    this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
}
 
Example #16
Source File: HttpUrlSource.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url) {
    this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
}
 
Example #17
Source File: HttpUrlSourceTest.java    From AndroidVideoCache with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testNotOpenableHttpUrlSourceOpen() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    ProxyCacheTestUtils.newNotOpenableHttpUrlSource("", sourceInfoStorage).open(Mockito.anyInt());
    fail("source.open() should throw exception");
}
 
Example #18
Source File: HttpUrlSource.java    From AndriodVideoCache with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url) {
    this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
}
 
Example #19
Source File: HttpUrlSource.java    From AndroidVideoCache with Apache License 2.0 4 votes vote down vote up
public HttpUrlSource(String url) {
    this(url, SourceInfoStorageFactory.newEmptySourceInfoStorage());
}
 
Example #20
Source File: HttpUrlSourceTest.java    From AndriodVideoCache with Apache License 2.0 4 votes vote down vote up
@Test(expected = RuntimeException.class)
public void testNotOpenableHttpUrlSourceOpen() throws Exception {
    SourceInfoStorage sourceInfoStorage = SourceInfoStorageFactory.newEmptySourceInfoStorage();
    ProxyCacheTestUtils.newNotOpenableHttpUrlSource("", sourceInfoStorage).open(Mockito.anyInt());
    fail("source.open() should throw exception");
}