本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}