當前位置: 首頁>>代碼示例>>Java>>正文


Java Response類代碼示例

本文整理匯總了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);
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:18,代碼來源:HttpProxyCacheServerTest.java

示例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));
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:18,代碼來源:HttpProxyCacheServerTest.java

示例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));
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:18,代碼來源:HttpProxyCacheServerTest.java

示例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);
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:24,代碼來源:HttpProxyCacheTest.java

示例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();
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:20,代碼來源:HttpProxyCacheTest.java

示例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");
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:18,代碼來源:HttpProxyCacheTest.java

示例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");
}
 
開發者ID:dingdingyr,項目名稱:AndroidVideoCache-,代碼行數:19,代碼來源:HttpProxyCacheTest.java

示例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);
}
 
開發者ID:dingdingyr,項目名稱:AndroidVideoCache-,代碼行數:22,代碼來源:HttpProxyCacheTest.java

示例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();
}
 
開發者ID:dingdingyr,項目名稱:AndroidVideoCache-,代碼行數:20,代碼來源:HttpProxyCacheTest.java

示例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();
}
 
開發者ID:korrio,項目名稱:AdvancedVideoView,代碼行數:17,代碼來源:HttpProxyCacheTest.java

示例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();
}
 
開發者ID:korrio,項目名稱:AdvancedVideoView,代碼行數:21,代碼來源:HttpProxyCacheTest.java

示例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));
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:9,代碼來源:HttpProxyCacheServerTest.java

示例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));
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:14,代碼來源:HttpProxyCacheServerTest.java

示例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));
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:14,代碼來源:HttpProxyCacheServerTest.java

示例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));
}
 
開發者ID:Achenglove,項目名稱:AndroidVideoCache,代碼行數:8,代碼來源:HttpProxyCacheServerTest.java


注:本文中的com.danikula.videocache.support.Response類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。