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


Java CacheRequest類代碼示例

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


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

示例1: getTransferStream

import java.net.CacheRequest; //導入依賴的package包/類
@Override public InputStream getTransferStream(CacheRequest cacheRequest) throws IOException {
  if (!httpEngine.hasResponseBody()) {
    return new FixedLengthInputStream(socketIn, cacheRequest, httpEngine, 0);
  }

  if (httpEngine.responseHeaders.isChunked()) {
    return new ChunkedInputStream(socketIn, cacheRequest, this);
  }

  if (httpEngine.responseHeaders.getContentLength() != -1) {
    return new FixedLengthInputStream(socketIn, cacheRequest, httpEngine,
        httpEngine.responseHeaders.getContentLength());
  }

  // Wrap the input stream from the connection (rather than just returning
  // "socketIn" directly here), so that we can control its use after the
  // reference escapes.
  return new UnknownLengthHttpInputStream(socketIn, cacheRequest, httpEngine);
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:20,代碼來源:HttpTransport.java

示例2: put

import java.net.CacheRequest; //導入依賴的package包/類
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  Response okResponse = JavaApiConverter.createOkResponseForCachePut(uri, urlConnection);
  if (okResponse == null) {
    // The URLConnection is not cacheable or could not be converted. Stop.
    return null;
  }
  okhttp3.internal.cache.CacheRequest okCacheRequest =
      delegate.internalCache.put(okResponse);
  if (okCacheRequest == null) {
    return null;
  }
  return JavaApiConverter.createJavaCacheRequest(okCacheRequest);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:AndroidShimResponseCache.java

示例3: put_httpsGet

import java.net.CacheRequest; //導入依賴的package包/類
@Test public void put_httpsGet() throws Exception {
  final URL serverUrl = configureHttpsServer(new MockResponse());
  assertEquals("https", serverUrl.getProtocol());

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
      try {
        assertTrue(connection instanceof HttpsURLConnection);
        assertEquals(toUri(serverUrl), uri);
        assertEquals(serverUrl, connection.getURL());

        HttpsURLConnection cacheHttpsUrlConnection = (HttpsURLConnection) connection;
        HttpsURLConnection realHttpsUrlConnection =
            (HttpsURLConnection) CacheAdapterTest.this.connection;
        assertEquals(realHttpsUrlConnection.getCipherSuite(),
            cacheHttpsUrlConnection.getCipherSuite());
        assertEquals(realHttpsUrlConnection.getPeerPrincipal(),
            cacheHttpsUrlConnection.getPeerPrincipal());
        assertArrayEquals(realHttpsUrlConnection.getLocalCertificates(),
            cacheHttpsUrlConnection.getLocalCertificates());
        assertArrayEquals(realHttpsUrlConnection.getServerCertificates(),
            cacheHttpsUrlConnection.getServerCertificates());
        assertEquals(realHttpsUrlConnection.getLocalPrincipal(),
            cacheHttpsUrlConnection.getLocalPrincipal());
        return null;
      } catch (Throwable t) {
        throw new IOException("unexpected cache failure", t);
      }
    }
  };
  setInternalCache(new CacheAdapter(responseCache));
  client = client.newBuilder()
      .sslSocketFactory(sslClient.socketFactory, sslClient.trustManager)
      .hostnameVerifier(hostnameVerifier)
      .build();

  connection = new OkUrlFactory(client).open(serverUrl);
  executeGet(connection);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:40,代碼來源:CacheAdapterTest.java

示例4: HttpInputStream

import java.net.CacheRequest; //導入依賴的package包/類
public HttpInputStream (InputStream is, CacheRequest cacheRequest) {
    super (is);
    this.cacheRequest = cacheRequest;
    try {
        this.outputStream = cacheRequest.getBody();
    } catch (IOException ioex) {
        this.cacheRequest.abort();
        this.cacheRequest = null;
        this.outputStream = null;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:HttpURLConnection.java

示例5: AbstractHttpInputStream

import java.net.CacheRequest; //導入依賴的package包/類
AbstractHttpInputStream(InputStream in, HttpEngine httpEngine, CacheRequest cacheRequest)
    throws IOException {
  this.in = in;
  this.httpEngine = httpEngine;

  OutputStream cacheBody = cacheRequest != null ? cacheRequest.getBody() : null;

  // some apps return a null body; for compatibility we treat that like a null cache request
  if (cacheBody == null) {
    cacheRequest = null;
  }

  this.cacheBody = cacheBody;
  this.cacheRequest = cacheRequest;
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:16,代碼來源:AbstractHttpInputStream.java

示例6: FixedLengthInputStream

import java.net.CacheRequest; //導入依賴的package包/類
public FixedLengthInputStream(InputStream is, CacheRequest cacheRequest, HttpEngine httpEngine,
    long length) throws IOException {
  super(is, httpEngine, cacheRequest);
  bytesRemaining = length;
  if (bytesRemaining == 0) {
    endOfInput();
  }
}
 
開發者ID:aabognah,項目名稱:LoRaWAN-Smart-Parking,代碼行數:9,代碼來源:HttpTransport.java

示例7: put

import java.net.CacheRequest; //導入依賴的package包/類
public synchronized CacheRequest put(URI uri, URLConnection conn)
throws IOException {
    System.out.println("put: " + uri);
    Thread.currentThread().dumpStack();
    URL url = uri.toURL();
    return new DeployCacheRequest(url, conn);

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:TestCache.java

示例8: put

import java.net.CacheRequest; //導入依賴的package包/類
@Override public CacheRequest put(URI uri, URLConnection urlConnection) throws IOException {
  Response okResponse = JavaApiConverter.createOkResponseForCachePut(uri, urlConnection);
  if (okResponse == null) {
    // The URLConnection is not cacheable or could not be converted. Stop.
    return null;
  }
  okhttp3.internal.http.CacheRequest okCacheRequest =
      delegate.internalCache.put(okResponse);
  if (okCacheRequest == null) {
    return null;
  }
  return JavaApiConverter.createJavaCacheRequest(okCacheRequest);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:14,代碼來源:AndroidShimResponseCache.java

示例9: put_httpGet

import java.net.CacheRequest; //導入依賴的package包/類
@Test public void put_httpGet() throws Exception {
  final String statusLine = "HTTP/1.1 200 Fantastic";
  final byte[] response = "ResponseString".getBytes(StandardCharsets.UTF_8);
  final URL serverUrl = configureServer(
      new MockResponse()
          .setStatus(statusLine)
          .addHeader("A", "c")
          .setBody(new Buffer().write(response)));

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
      assertTrue(connection instanceof HttpURLConnection);
      assertFalse(connection instanceof HttpsURLConnection);

      assertEquals(response.length, connection.getContentLength());

      HttpURLConnection httpUrlConnection = (HttpURLConnection) connection;
      assertEquals("GET", httpUrlConnection.getRequestMethod());
      assertTrue(httpUrlConnection.getDoInput());
      assertFalse(httpUrlConnection.getDoOutput());

      assertEquals("Fantastic", httpUrlConnection.getResponseMessage());
      assertEquals(toUri(serverUrl), uri);
      assertEquals(serverUrl, connection.getURL());
      assertEquals("value", connection.getRequestProperty("key"));

      // Check retrieval by string key.
      assertEquals(statusLine, httpUrlConnection.getHeaderField(null));
      assertEquals("c", httpUrlConnection.getHeaderField("A"));
      // The RI and OkHttp supports case-insensitive matching for this method.
      assertEquals("c", httpUrlConnection.getHeaderField("a"));
      return null;
    }
  };
  setInternalCache(new CacheAdapter(responseCache));

  connection = new OkUrlFactory(client).open(serverUrl);
  connection.setRequestProperty("key", "value");
  executeGet(connection);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:41,代碼來源:CacheAdapterTest.java

示例10: put_httpPost

import java.net.CacheRequest; //導入依賴的package包/類
@Test public void put_httpPost() throws Exception {
  final String statusLine = "HTTP/1.1 200 Fantastic";
  final URL serverUrl = configureServer(
      new MockResponse()
          .setStatus(statusLine)
          .addHeader("A", "c"));

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
      assertTrue(connection instanceof HttpURLConnection);
      assertFalse(connection instanceof HttpsURLConnection);

      assertEquals(0, connection.getContentLength());

      HttpURLConnection httpUrlConnection = (HttpURLConnection) connection;
      assertEquals("POST", httpUrlConnection.getRequestMethod());
      assertTrue(httpUrlConnection.getDoInput());
      assertTrue(httpUrlConnection.getDoOutput());

      assertEquals("Fantastic", httpUrlConnection.getResponseMessage());
      assertEquals(toUri(serverUrl), uri);
      assertEquals(serverUrl, connection.getURL());
      assertEquals("value", connection.getRequestProperty("key"));

      // Check retrieval by string key.
      assertEquals(statusLine, httpUrlConnection.getHeaderField(null));
      assertEquals("c", httpUrlConnection.getHeaderField("A"));
      // The RI and OkHttp supports case-insensitive matching for this method.
      assertEquals("c", httpUrlConnection.getHeaderField("a"));
      return null;
    }
  };
  setInternalCache(new CacheAdapter(responseCache));

  connection = new OkUrlFactory(client).open(serverUrl);

  executePost(connection);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:39,代碼來源:CacheAdapterTest.java

示例11: put_httpsGet

import java.net.CacheRequest; //導入依賴的package包/類
@Test public void put_httpsGet() throws Exception {
  final URL serverUrl = configureHttpsServer(new MockResponse());
  assertEquals("https", serverUrl.getProtocol());

  ResponseCache responseCache = new AbstractResponseCache() {
    @Override public CacheRequest put(URI uri, URLConnection connection) throws IOException {
      assertTrue(connection instanceof HttpsURLConnection);
      assertEquals(toUri(serverUrl), uri);
      assertEquals(serverUrl, connection.getURL());

      HttpsURLConnection cacheHttpsUrlConnection = (HttpsURLConnection) connection;
      HttpsURLConnection realHttpsUrlConnection =
          (HttpsURLConnection) CacheAdapterTest.this.connection;
      assertEquals(realHttpsUrlConnection.getCipherSuite(),
          cacheHttpsUrlConnection.getCipherSuite());
      assertEquals(realHttpsUrlConnection.getPeerPrincipal(),
          cacheHttpsUrlConnection.getPeerPrincipal());
      assertArrayEquals(realHttpsUrlConnection.getLocalCertificates(),
          cacheHttpsUrlConnection.getLocalCertificates());
      assertArrayEquals(realHttpsUrlConnection.getServerCertificates(),
          cacheHttpsUrlConnection.getServerCertificates());
      assertEquals(realHttpsUrlConnection.getLocalPrincipal(),
          cacheHttpsUrlConnection.getLocalPrincipal());
      return null;
    }
  };
  setInternalCache(new CacheAdapter(responseCache));
  client = client.newBuilder()
      .sslSocketFactory(sslContext.getSocketFactory())
      .hostnameVerifier(hostnameVerifier)
      .build();

  connection = new OkUrlFactory(client).open(serverUrl);
  executeGet(connection);
}
 
開發者ID:lizhangqu,項目名稱:PriorityOkHttp,代碼行數:36,代碼來源:CacheAdapterTest.java


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