com.danikula.videocache.headers.HeaderInjector Java Examples

The following examples show how to use com.danikula.videocache.headers.HeaderInjector. 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: HttpUrlSource.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example #2
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 #3
Source File: HttpUrlSource.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example #4
Source File: HttpProxyCacheServerTest.java    From AndroidVideoCache with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadersInjectorIsInvoked() throws Exception {
    HeaderInjector mockedHeaderInjector = Mockito.mock(HeaderInjector.class);

    HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(RuntimeEnvironment.application)
            .headerInjector(mockedHeaderInjector)
            .build();

    readProxyResponse(proxy, HTTP_DATA_URL);
    proxy.shutdown();

    verify(mockedHeaderInjector, times(2)).addHeaders(HTTP_DATA_URL);   // content info & fetch data requests
}
 
Example #5
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 #6
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 #7
Source File: HttpUrlSource.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example #8
Source File: Proxy.java    From QSVideoPlayer with Apache License 2.0 5 votes vote down vote up
synchronized static HttpProxyCacheServer getProxy(Context context, final Map<String, String> headers) {
    if (builder == null)
        builder = new HttpProxyCacheServer.Builder(context);
    if (headers != null)
        builder.headerInjector(new HeaderInjector() {
            @Override
            public Map<String, String> addHeaders(String url) {
                return headers;
            }
        });
    return builder.build();
}
 
Example #9
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 #10
Source File: ApplicationModule.java    From v9porn with MIT License 5 votes vote down vote up
@Singleton
@Provides
static HttpProxyCacheServer providesHttpProxyCacheServer(@ApplicationContext Context context,HeaderInjector headerInjector) {
    return new HttpProxyCacheServer.Builder(context)
            // 1 Gb for cache
            .headerInjector(headerInjector)
            .maxCacheSize(AppCacheUtils.MAX_VIDEO_CACHE_SIZE)
            .cacheDirectory(AppCacheUtils.getVideoCacheDir(context))
            .fileNameGenerator(new VideoCacheFileNameGenerator())
            .build();
}
 
Example #11
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 #12
Source File: HttpUrlSource.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
public HttpUrlSource(String url, SourceInfoStorage sourceInfoStorage, HeaderInjector headerInjector) {
    this.sourceInfoStorage = checkNotNull(sourceInfoStorage);
    this.headerInjector = checkNotNull(headerInjector);
    SourceInfo sourceInfo = sourceInfoStorage.get(url);
    this.sourceInfo = sourceInfo != null ? sourceInfo :
            new SourceInfo(url, Integer.MIN_VALUE, ProxyCacheUtils.getSupposablyMime(url));
}
 
Example #13
Source File: HttpProxyCacheServerTest.java    From AndriodVideoCache with Apache License 2.0 5 votes vote down vote up
@Test
public void testHeadersInjectorIsInvoked() throws Exception {
    HeaderInjector mockedHeaderInjector = Mockito.mock(HeaderInjector.class);

    HttpProxyCacheServer proxy = new HttpProxyCacheServer.Builder(RuntimeEnvironment.application)
            .headerInjector(mockedHeaderInjector)
            .build();

    readProxyResponse(proxy, HTTP_DATA_URL);
    proxy.shutdown();

    verify(mockedHeaderInjector, times(2)).addHeaders(HTTP_DATA_URL);   // content info & fetch data requests
}
 
Example #14
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 #15
Source File: ApplicationModule.java    From v9porn with MIT License 5 votes vote down vote up
@Singleton
@Provides
static HttpProxyCacheServer providesHttpProxyCacheServer(@ApplicationContext Context context,HeaderInjector headerInjector) {
    return new HttpProxyCacheServer.Builder(context)
            // 1 Gb for cache
            .headerInjector(headerInjector)
            .maxCacheSize(AppCacheUtils.MAX_VIDEO_CACHE_SIZE)
            .cacheDirectory(AppCacheUtils.getVideoCacheDir(context))
            .fileNameGenerator(new VideoCacheFileNameGenerator())
            .build();
}
 
Example #16
Source File: ApplicationModule.java    From v9porn with MIT License 4 votes vote down vote up
@Singleton
static @Provides HeaderInjector providesHeaderInjector(MyHeaderInjector myHeaderInjector){
    return myHeaderInjector;
}
 
Example #17
Source File: ApplicationModule.java    From v9porn with MIT License 4 votes vote down vote up
@Singleton
static @Provides HeaderInjector providesHeaderInjector(MyHeaderInjector myHeaderInjector){
    return myHeaderInjector;
}