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


Java ResponseCache.setDefault方法代碼示例

本文整理匯總了Java中java.net.ResponseCache.setDefault方法的典型用法代碼示例。如果您正苦於以下問題:Java ResponseCache.setDefault方法的具體用法?Java ResponseCache.setDefault怎麽用?Java ResponseCache.setDefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.ResponseCache的用法示例。


在下文中一共展示了ResponseCache.setDefault方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: otherStacks_cacheHitWithoutVary

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheHitWithoutVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("FAIL"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ResponseCacheTest.java

示例2: otherStacks_cacheMissWithVaryAcceptEncoding

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAcceptEncoding() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Encoding")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ResponseCacheTest.java

示例3: otherStacks_cacheMissWithVary

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheMissWithVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Language")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  connection.setRequestProperty("Accept-Language", "en-US");
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:ResponseCacheTest.java

示例4: otherStacks_cacheMissWithVaryAsterisk

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAsterisk() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: *")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof OkHttpURLConnection);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof OkHttpURLConnection);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:ResponseCacheTest.java

示例5: otherStacks_cacheHitWithoutVary

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheHitWithoutVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("FAIL"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:20,代碼來源:ResponseCacheTest.java

示例6: otherStacks_cacheMissWithVaryAcceptEncoding

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAcceptEncoding() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Encoding")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:21,代碼來源:ResponseCacheTest.java

示例7: otherStacks_cacheMissWithVary

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheMissWithVary() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: Accept-Language")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  connection.setRequestProperty("Accept-Language", "en-US");
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:22,代碼來源:ResponseCacheTest.java

示例8: otherStacks_cacheMissWithVaryAsterisk

import java.net.ResponseCache; //導入方法依賴的package包/類
@Test public void otherStacks_cacheMissWithVaryAsterisk() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("Cache-Control: max-age=60")
      .addHeader("Vary: *")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setBody("B"));

  // Set the cache as the shared cache.
  ResponseCache.setDefault(cache);

  // Use the platform's HTTP stack.
  URLConnection connection = server.url("/").url().openConnection();
  assertFalse(connection instanceof HttpURLConnectionImpl);
  assertEquals("A", readAscii(connection));

  URLConnection connection2 = server.url("/").url().openConnection();
  assertFalse(connection2 instanceof HttpURLConnectionImpl);
  assertEquals("B", readAscii(connection2));
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:21,代碼來源:ResponseCacheTest.java

示例9: delete

import java.net.ResponseCache; //導入方法依賴的package包/類
/**
 * Uninstalls the cache and deletes all of its stored contents.
 */
public void delete() throws IOException {
  if (ResponseCache.getDefault() == this) {
    ResponseCache.setDefault(null);
  }
  shimResponseCache.delete();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:HttpResponseCache.java

示例10: reset

import java.net.ResponseCache; //導入方法依賴的package包/類
public void reset() {
    // Reset system properties.
    System.setProperties(null);

    // From "L" release onwards, calling System.setProperties(null) clears the java.io.tmpdir,
    // so we set it again. No-op on earlier releases.
    System.setProperty("java.io.tmpdir", tmpDir);

    if (JAVA_RUNTIME_VERSION != null) {
        System.setProperty("java.runtime.version", JAVA_RUNTIME_VERSION);
    }
    if (JAVA_VM_INFO != null) {
        System.setProperty("java.vm.info", JAVA_VM_INFO);
    }
    if (JAVA_VM_VERSION != null) {
        System.setProperty("java.vm.version", JAVA_VM_VERSION);
    }
    if (JAVA_VM_VENDOR != null) {
        System.setProperty("java.vm.vendor", JAVA_VM_VENDOR);
    }
    if (JAVA_VM_NAME != null) {
        System.setProperty("java.vm.name", JAVA_VM_NAME);
    }

    // Require writable java.home and user.dir directories for preferences
    if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
        String javaHome = tmpDir + "/java.home";
        IoUtils.safeMkdirs(new File(javaHome));
        System.setProperty("java.home", javaHome);
    }
    String userHome = System.getProperty("user.home");
    if (userHome.length() == 0) {
        userHome = tmpDir + "/user.home";
        IoUtils.safeMkdirs(new File(userHome));
        System.setProperty("user.home", userHome);
    }

    // Localization
    Locale.setDefault(Locale.US);
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));

    // Preferences
    // Temporarily silence the java.util.prefs logger, which otherwise emits
    // an unactionable warning. See RI bug 4751540.
    Logger loggerToMute = Logger.getLogger("java.util.prefs");
    boolean usedParentHandlers = loggerToMute.getUseParentHandlers();
    loggerToMute.setUseParentHandlers(false);
    try {
        // resetPreferences(Preferences.systemRoot());
        resetPreferences(Preferences.userRoot());
    } finally {
        loggerToMute.setUseParentHandlers(usedParentHandlers);
    }

    // HttpURLConnection
    Authenticator.setDefault(null);
    CookieHandler.setDefault(null);
    ResponseCache.setDefault(null);
    HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
    HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);

    // Logging
    LogManager.getLogManager().reset();
    Logger.getLogger("").addHandler(new ConsoleHandler());

    // Cleanup to force CloseGuard warnings etc
    System.gc();
    System.runFinalization();
}
 
開發者ID:dryganets,項目名稱:vogar,代碼行數:70,代碼來源:TestEnvironment.java

示例11: close

import java.net.ResponseCache; //導入方法依賴的package包/類
/**
 * Uninstalls the cache and releases any active resources. Stored contents will remain on the
 * filesystem.
 */
@Override public void close() throws IOException {
  if (ResponseCache.getDefault() == this) {
    ResponseCache.setDefault(null);
  }
  shimResponseCache.close();
}
 
開發者ID:RunningTheSnail,項目名稱:Okhttp,代碼行數:11,代碼來源:HttpResponseCache.java

示例12: reset

import java.net.ResponseCache; //導入方法依賴的package包/類
public static void reset() {
    // Set system wide cache handler
    System.out.println("install deploy cache handler");
    ResponseCache.setDefault(new TestCache());
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TestCache.java

示例13: tearDown

import java.net.ResponseCache; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
  ResponseCache.setDefault(null);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:HttpResponseCacheTest.java

示例14: tearDown

import java.net.ResponseCache; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
  ResponseCache.setDefault(null);
  cache.delete();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:5,代碼來源:UrlConnectionCacheTest.java

示例15: tearDown

import java.net.ResponseCache; //導入方法依賴的package包/類
@After public void tearDown() throws Exception {
  ProxySelector.setDefault(DEFAULT_PROXY_SELECTOR);
  CookieManager.setDefault(DEFAULT_COOKIE_HANDLER);
  ResponseCache.setDefault(DEFAULT_RESPONSE_CACHE);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:OkHttpClientTest.java


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