本文整理汇总了Java中com.danikula.videocache.support.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.danikula.videocache.support包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testProxyContentWithPartialCache
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@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);
}
示例2: testProxyPartialResponse
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProxyPartialResponse() throws Exception {
int offset = 18000;
Pair<File, Response> response = readProxyData(HTTP_DATA_BIG_URL, offset);
assertThat(response.second.code).isEqualTo(206);
assertThat(response.second.contentLength).isEqualTo(HTTP_DATA_BIG_SIZE - offset);
assertThat(response.second.contentType).isEqualTo("image/jpeg");
assertThat(response.second.headers.containsKey("Accept-Ranges")).isTrue();
assertThat(response.second.headers.get("Accept-Ranges").get(0)).isEqualTo("bytes");
assertThat(response.second.headers.containsKey("Content-Range")).isTrue();
String rangeHeader = String.format("bytes %d-%d/%d", offset, HTTP_DATA_BIG_SIZE - 1, HTTP_DATA_BIG_SIZE);
assertThat(response.second.headers.get("Content-Range").get(0)).isEqualTo(rangeHeader);
byte[] expectedData = Arrays.copyOfRange(loadAssetFile(ASSETS_DATA_BIG_NAME), offset, HTTP_DATA_BIG_SIZE);
assertThat(response.second.data).isEqualTo(expectedData);
assertThat(getFileContent(response.first)).isEqualTo(loadAssetFile(ASSETS_DATA_BIG_NAME));
}
示例3: testProxyPartialResponseWithRedirect
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProxyPartialResponseWithRedirect() throws Exception {
int offset = 18000;
Pair<File, Response> response = readProxyData(HTTP_DATA_BIG_URL_ONE_REDIRECT, offset);
assertThat(response.second.code).isEqualTo(206);
assertThat(response.second.contentLength).isEqualTo(HTTP_DATA_BIG_SIZE - offset);
assertThat(response.second.contentType).isEqualTo("image/jpeg");
assertThat(response.second.headers.containsKey("Accept-Ranges")).isTrue();
assertThat(response.second.headers.get("Accept-Ranges").get(0)).isEqualTo("bytes");
assertThat(response.second.headers.containsKey("Content-Range")).isTrue();
String rangeHeader = String.format("bytes %d-%d/%d", offset, HTTP_DATA_BIG_SIZE - 1, HTTP_DATA_BIG_SIZE);
assertThat(response.second.headers.get("Content-Range").get(0)).isEqualTo(rangeHeader);
byte[] expectedData = Arrays.copyOfRange(loadAssetFile(ASSETS_DATA_BIG_NAME), offset, HTTP_DATA_BIG_SIZE);
assertThat(response.second.data).isEqualTo(expectedData);
assertThat(getFileContent(response.first)).isEqualTo(loadAssetFile(ASSETS_DATA_BIG_NAME));
}
示例4: testPreventClosingOriginalSourceForNewPartialRequestWithoutCache
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test // https://github.com/danikula/AndroidVideoCache/issues/43
public void testPreventClosingOriginalSourceForNewPartialRequestWithoutCache() throws Exception {
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_BIG_URL);
FileCache fileCache = new FileCache(ProxyCacheTestUtils.newCacheFile());
HttpProxyCache proxyCache = new HttpProxyCache(source, fileCache);
ExecutorService executor = Executors.newFixedThreadPool(5);
Future<Response> firstRequestFeature = processAsync(executor, proxyCache, "GET /" + HTTP_DATA_URL + " HTTP/1.1");
Thread.sleep(100); // wait for first request started to process
int offset = 30000;
String partialRequest = "GET /" + HTTP_DATA_URL + " HTTP/1.1\nRange: bytes=" + offset + "-";
Future<Response> secondRequestFeature = processAsync(executor, proxyCache, partialRequest);
Response secondResponse = secondRequestFeature.get();
Response firstResponse = firstRequestFeature.get();
byte[] responseData = loadAssetFile(ASSETS_DATA_BIG_NAME);
assertThat(firstResponse.data).isEqualTo(responseData);
byte[] partialData = new byte[responseData.length - offset];
System.arraycopy(responseData, offset, partialData, 0, partialData.length);
assertThat(secondResponse.data).isEqualTo(partialData);
}
示例5: testLoadEmptyFile
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testLoadEmptyFile() throws Exception {
String zeroSizeUrl = "https://raw.githubusercontent.com/danikula/AndroidVideoCache/master/files/empty.txt";
HttpUrlSource source = new HttpUrlSource(zeroSizeUrl);
HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(ProxyCacheTestUtils.newCacheFile()));
GetRequest request = new GetRequest("GET /" + HTTP_DATA_URL + " HTTP/1.1");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Socket socket = mock(Socket.class);
when(socket.getOutputStream()).thenReturn(out);
CacheListener listener = Mockito.mock(CacheListener.class);
proxyCache.registerCacheListener(listener);
proxyCache.processRequest(request, socket);
proxyCache.registerCacheListener(null);
Response response = new Response(out.toByteArray());
Mockito.verify(listener).onCacheAvailable(Mockito.<File>any(), eq(zeroSizeUrl), eq(100));
assertThat(response.data).isEmpty();
}
示例6: testReuseSourceInfo
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@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");
}
示例7: testProcessRequestNoCache
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProcessRequestNoCache() throws Exception {
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL);
FileCache cache = new FileCache(ProxyCacheTestUtils.newCacheFile());
HttpProxyCache proxyCache = new HttpProxyCache(source, cache);
GetRequest request = new GetRequest("GET /" + HTTP_DATA_URL + " HTTP/1.1");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Socket socket = mock(Socket.class);
when(socket.getOutputStream()).thenReturn(out);
proxyCache.processRequest(request, socket);
Response response = new Response(out.toByteArray());
assertThat(response.data).isEqualTo(loadTestData());
assertThat(response.code).isEqualTo(200);
assertThat(response.contentLength).isEqualTo(ProxyCacheTestUtils.HTTP_DATA_SIZE);
assertThat(response.contentType).isEqualTo("image/jpeg");
}
示例8: testProcessPartialRequestWithoutCache
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProcessPartialRequestWithoutCache() throws Exception {
HttpUrlSource source = new HttpUrlSource(HTTP_DATA_URL);
FileCache fileCache = new FileCache(ProxyCacheTestUtils.newCacheFile());
FileCache spyFileCache = Mockito.spy(fileCache);
doThrow(new RuntimeException()).when(spyFileCache).read(any(byte[].class), anyLong(), anyInt());
HttpProxyCache proxyCache = new HttpProxyCache(source, spyFileCache);
GetRequest request = new GetRequest("GET /" + HTTP_DATA_URL + " HTTP/1.1\nRange: bytes=2000-");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Socket socket = mock(Socket.class);
when(socket.getOutputStream()).thenReturn(out);
proxyCache.processRequest(request, socket);
Response response = new Response(out.toByteArray());
byte[] fullData = loadTestData();
byte[] partialData = new byte[fullData.length - 2000];
System.arraycopy(fullData, 2000, partialData, 0, partialData.length);
assertThat(response.data).isEqualTo(partialData);
assertThat(response.code).isEqualTo(206);
}
示例9: testLoadEmptyFile
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testLoadEmptyFile() throws Exception {
String zeroSizeUrl = "https://dl.dropboxusercontent.com/u/15506779/persistent/proxycache/empty.txt";
HttpUrlSource source = new HttpUrlSource(zeroSizeUrl);
HttpProxyCache proxyCache = new HttpProxyCache(source, new FileCache(ProxyCacheTestUtils.newCacheFile()));
GetRequest request = new GetRequest("GET /" + HTTP_DATA_URL + " HTTP/1.1");
ByteArrayOutputStream out = new ByteArrayOutputStream();
Socket socket = mock(Socket.class);
when(socket.getOutputStream()).thenReturn(out);
CacheListener listener = Mockito.mock(CacheListener.class);
proxyCache.registerCacheListener(listener);
proxyCache.processRequest(request, socket);
proxyCache.registerCacheListener(null);
Response response = new Response(out.toByteArray());
Mockito.verify(listener).onCacheAvailable(Mockito.<File>any(), eq(zeroSizeUrl), eq(100));
assertThat(response.data).isEmpty();
}
示例10: testProxyFullResponse
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProxyFullResponse() throws Exception {
File file = newCacheFile();
HttpProxyCache proxy = new HttpProxyCache(new HttpUrlSource(HTTP_DATA_BIG_URL), new FileCache(file));
Response response = readProxyResponse(proxy);
assertThat(response.code).isEqualTo(200);
assertThat(response.contentLength).isEqualTo(HTTP_DATA_BIG_SIZE);
assertThat(response.contentType).isEqualTo("image/jpeg");
assertThat(response.headers.containsKey("Accept-Ranges")).isTrue();
assertThat(response.headers.get("Accept-Ranges").get(0)).isEqualTo("bytes");
assertThat(response.headers.containsKey("Content-Range")).isFalse();
assertThat(response.data).isEqualTo(getFileContent(file));
assertThat(response.data).isEqualTo(loadAssetFile(ASSETS_DATA_BIG_NAME));
proxy.shutdown();
}
示例11: testProxyPartialResponse
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProxyPartialResponse() throws Exception {
int offset = 42000;
File file = newCacheFile();
HttpProxyCache proxy = new HttpProxyCache(new HttpUrlSource(HTTP_DATA_BIG_URL), new FileCache(file));
Response response = readProxyResponse(proxy, offset);
assertThat(response.code).isEqualTo(206);
assertThat(response.contentLength).isEqualTo(HTTP_DATA_BIG_SIZE - offset);
assertThat(response.contentType).isEqualTo("image/jpeg");
assertThat(response.headers.containsKey("Accept-Ranges")).isTrue();
assertThat(response.headers.get("Accept-Ranges").get(0)).isEqualTo("bytes");
assertThat(response.headers.containsKey("Content-Range")).isTrue();
String rangeHeader = String.format("bytes %d-%d/%d", offset, HTTP_DATA_BIG_SIZE, HTTP_DATA_BIG_SIZE);
assertThat(response.headers.get("Content-Range").get(0)).isEqualTo(rangeHeader);
byte[] expectedData = Arrays.copyOfRange(loadAssetFile(ASSETS_DATA_BIG_NAME), offset, HTTP_DATA_BIG_SIZE);
assertThat(response.data).isEqualTo(expectedData);
assertThat(getFileContent(file)).isEqualTo(loadAssetFile(ASSETS_DATA_BIG_NAME));
proxy.shutdown();
}
示例12: testHttpProxyCache
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testHttpProxyCache() throws Exception {
Pair<File, Response> response = readProxyData(HTTP_DATA_URL);
assertThat(response.second.code).isEqualTo(200);
assertThat(response.second.data).isEqualTo(getFileContent(response.first));
assertThat(response.second.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
}
示例13: testProxyFullResponse
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProxyFullResponse() throws Exception {
Pair<File, Response> response = readProxyData(HTTP_DATA_BIG_URL);
assertThat(response.second.code).isEqualTo(200);
assertThat(response.second.contentLength).isEqualTo(HTTP_DATA_BIG_SIZE);
assertThat(response.second.contentType).isEqualTo("image/jpeg");
assertThat(response.second.headers.containsKey("Accept-Ranges")).isTrue();
assertThat(response.second.headers.get("Accept-Ranges").get(0)).isEqualTo("bytes");
assertThat(response.second.headers.containsKey("Content-Range")).isFalse();
assertThat(response.second.data).isEqualTo(getFileContent(response.first));
assertThat(response.second.data).isEqualTo(loadAssetFile(ASSETS_DATA_BIG_NAME));
}
示例14: testProxyFullResponseWithRedirect
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test
public void testProxyFullResponseWithRedirect() throws Exception {
Pair<File, Response> response = readProxyData(HTTP_DATA_BIG_URL_ONE_REDIRECT);
assertThat(response.second.code).isEqualTo(200);
assertThat(response.second.contentLength).isEqualTo(HTTP_DATA_BIG_SIZE);
assertThat(response.second.contentType).isEqualTo("image/jpeg");
assertThat(response.second.headers.containsKey("Accept-Ranges")).isTrue();
assertThat(response.second.headers.get("Accept-Ranges").get(0)).isEqualTo("bytes");
assertThat(response.second.headers.containsKey("Content-Range")).isFalse();
assertThat(response.second.data).isEqualTo(getFileContent(response.first));
assertThat(response.second.data).isEqualTo(loadAssetFile(ASSETS_DATA_BIG_NAME));
}
示例15: testWorkWithExternalProxy
import com.danikula.videocache.support.Response; //导入依赖的package包/类
@Test // https://github.com/danikula/AndroidVideoCache/issues/28
public void testWorkWithExternalProxy() throws Exception {
installExternalSystemProxy();
Pair<File, Response> response = readProxyData(HTTP_DATA_URL, 0);
assertThat(response.second.data).isEqualTo(loadAssetFile(ASSETS_DATA_NAME));
}