• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Internal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中okhttp3.internal.Internal的典型用法代码示例。如果您正苦于以下问题:Java Internal类的具体用法?Java Internal怎么用?Java Internal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Internal类属于okhttp3.internal包,在下文中一共展示了Internal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: extractOkHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Extracts OkHttp headers from the supplied {@link Map}. Only real headers are extracted. Any
 * entry (one with a {@code null} key) is discarded.
 */
// @VisibleForTesting
static Headers extractOkHeaders(Map<String, List<String>> javaHeaders) {
  Headers.Builder okHeadersBuilder = new Headers.Builder();
  for (Map.Entry<String, List<String>> javaHeader : javaHeaders.entrySet()) {
    String name = javaHeader.getKey();
    if (name == null) {
      // The Java API uses the null key to store the status line in responses.
      // Earlier versions of OkHttp would use the null key to store the "request line" in
      // requests. e.g. "GET / HTTP 1.1". Although this is no longer the case it must be
      // explicitly ignored because Headers.Builder does not support null keys.
      continue;
    }
    for (String value : javaHeader.getValue()) {
      Internal.instance.addLenient(okHeadersBuilder, name, value);
    }
  }
  return okHeadersBuilder.build();
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:23,代码来源:JavaApiConverter.java


示例2: pruneAndGetAllocationCount

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Prunes any leaked allocations and then returns the number of remaining live allocations on
 * {@code connection}. Allocations are leaked if the connection is tracking them but the
 * application code has abandoned them. Leak detection is imprecise and relies on garbage
 * collection.
 */
private int pruneAndGetAllocationCount(RealConnection connection, long now) {
  List<Reference<StreamAllocation>> references = connection.allocations;
  for (int i = 0; i < references.size(); ) {
    Reference<StreamAllocation> reference = references.get(i);

    if (reference.get() != null) {
      i++;
      continue;
    }

    // We've discovered a leaked allocation. This is an application bug.
    Internal.logger.warning("A connection to " + connection.route().address().url()
        + " was leaked. Did you forget to close a response body?");
    references.remove(i);
    connection.noNewStreams = true;

    // If this was the last allocation, the connection is eligible for immediate eviction.
    if (references.isEmpty()) {
      connection.idleAtNanos = now - keepAliveDurationNs;
      return 0;
    }
  }

  return references.size();
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:32,代码来源:ConnectionPool.java


示例3: maybeCache

import okhttp3.internal.Internal; //导入依赖的package包/类
private void maybeCache() throws IOException {
  InternalCache responseCache = Internal.instance.internalCache(client);
  if (responseCache == null) return;

  // Should we cache this response for this request?
  if (!CacheStrategy.isCacheable(userResponse, networkRequest)) {
    if (HttpMethod.invalidatesCache(networkRequest.method())) {
      try {
        responseCache.remove(networkRequest);
      } catch (IOException ignored) {
        // The cache cannot be written.
      }
    }
    return;
  }

  // Offer this request to the cache.
  storeRequest = responseCache.put(stripBody(userResponse));
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:20,代码来源:HttpEngine.java


示例4: readHttp2HeadersList

import okhttp3.internal.Internal; //导入依赖的package包/类
/** Returns headers for a name value block containing an HTTP/2 response. */
public static Response.Builder readHttp2HeadersList(List<Header> headerBlock) throws IOException {
  String status = null;

  Headers.Builder headersBuilder = new Headers.Builder();
  for (int i = 0, size = headerBlock.size(); i < size; i++) {
    ByteString name = headerBlock.get(i).name;

    String value = headerBlock.get(i).value.utf8();
    if (name.equals(RESPONSE_STATUS)) {
      status = value;
    } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) {
      Internal.instance.addLenient(headersBuilder, name.utf8(), value);
    }
  }
  if (status == null) throw new ProtocolException("Expected ':status' header not present");

  StatusLine statusLine = StatusLine.parse("HTTP/1.1 " + status);
  return new Response.Builder()
      .protocol(Protocol.HTTP_2)
      .code(statusLine.code)
      .message(statusLine.message)
      .headers(headersBuilder.build());
}
 
开发者ID:RunningTheSnail,项目名称:Okhttp,代码行数:25,代码来源:Http2Codec.java


示例5: createHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Returns headers for the header names and values in the {@link Map}.
 */
private static Headers createHeaders(Map<String, List<String>> headers) {
  Headers.Builder builder = new Headers.Builder();
  for (Map.Entry<String, List<String>> header : headers.entrySet()) {
    if (header.getKey() == null || header.getValue() == null) {
      continue;
    }
    String name = header.getKey().trim();
    for (String value : header.getValue()) {
      String trimmedValue = value.trim();
      Internal.instance.addLenient(builder, name, trimmedValue);
    }
  }
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JavaApiConverter.java


示例6: varyHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
private static Headers varyHeaders(URLConnection urlConnection, Headers responseHeaders) {
  if (HttpHeaders.hasVaryAll(responseHeaders)) {
    // "*" means that this will be treated as uncacheable anyway.
    return null;
  }
  Set<String> varyFields = HttpHeaders.varyFields(responseHeaders);
  if (varyFields.isEmpty()) {
    return new Headers.Builder().build();
  }

  // This probably indicates another HTTP stack is trying to use the shared ResponseCache.
  // We cannot guarantee this case will work properly because we cannot reliably extract *all*
  // the request header values, and we can't get multiple Vary request header values.
  // We also can't be sure about the Accept-Encoding behavior of other stacks.
  if (!(urlConnection instanceof CacheHttpURLConnection
      || urlConnection instanceof CacheHttpsURLConnection)) {
    return null;
  }

  // This is the case we expect: The URLConnection is from a call to
  // JavaApiConverter.createJavaUrlConnection() and we have access to the user's request headers.
  Map<String, List<String>> requestProperties = urlConnection.getRequestProperties();
  Headers.Builder result = new Headers.Builder();
  for (String fieldName : varyFields) {
    List<String> fieldValues = requestProperties.get(fieldName);
    if (fieldValues == null) {
      if (fieldName.equals("Accept-Encoding")) {
        // Accept-Encoding is special. If OkHttp sees Accept-Encoding is unset it will add
        // "gzip". We don't have access to the request that was actually made so we must do the
        // same.
        result.add("Accept-Encoding", "gzip");
      }
    } else {
      for (String fieldValue : fieldValues) {
        Internal.instance.addLenient(result, fieldName, fieldValue);
      }
    }
  }
  return result.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:JavaApiConverter.java


示例7: extractOkHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Extracts OkHttp headers from the supplied {@link Map}. Only real headers are extracted. Any
 * entry (one with a {@code null} key) is discarded. Special internal headers used to track cache
 * metadata are omitted from the result and added to {@code okResponseBuilder} instead.
 */
// @VisibleForTesting
static Headers extractOkHeaders(
    Map<String, List<String>> javaHeaders, Response.Builder okResponseBuilder) {
  Headers.Builder okHeadersBuilder = new Headers.Builder();
  for (Map.Entry<String, List<String>> javaHeader : javaHeaders.entrySet()) {
    String name = javaHeader.getKey();
    if (name == null) {
      // The Java API uses the null key to store the status line in responses.
      // Earlier versions of OkHttp would use the null key to store the "request line" in
      // requests. e.g. "GET / HTTP 1.1". Although this is no longer the case it must be
      // explicitly ignored because Headers.Builder does not support null keys.
      continue;
    }
    if (okResponseBuilder != null && javaHeader.getValue().size() == 1) {
      if (name.equals(SENT_MILLIS)) {
        okResponseBuilder.sentRequestAtMillis(Long.valueOf(javaHeader.getValue().get(0)));
        continue;
      }
      if (name.equals(RECEIVED_MILLIS)) {
        okResponseBuilder.receivedResponseAtMillis(Long.valueOf(javaHeader.getValue().get(0)));
        continue;
      }
    }
    for (String value : javaHeader.getValue()) {
      Internal.instance.addLenient(okHeadersBuilder, name, value);
    }
  }
  return okHeadersBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:JavaApiConverter.java


示例8: emptyResponseHeaderNameFromCacheIsLenient

import okhttp3.internal.Internal; //导入依赖的package包/类
@Test public void emptyResponseHeaderNameFromCacheIsLenient() throws Exception {
  Headers.Builder headers = new Headers.Builder()
      .add("Cache-Control: max-age=120");
  Internal.instance.addLenient(headers, ": A");
  server.enqueue(new MockResponse()
      .setHeaders(headers.build())
      .setBody("body"));

  HttpURLConnection connection = openConnection(server.url("/").url());
  assertEquals("A", connection.getHeaderField(""));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:ResponseCacheTest.java


示例9: readHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
/** Reads headers or trailers. */
public Headers readHeaders() throws IOException {
  Headers.Builder headers = new Headers.Builder();
  // parse the result headers until the first blank line
  for (String line; (line = source.readUtf8LineStrict()).length() != 0; ) {
    Internal.instance.addLenient(headers, line);
  }
  return headers.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:Http1Codec.java


示例10: readResponseHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
@Override public Response.Builder readResponseHeaders(boolean expectContinue) throws IOException {
  List<Header> headers = stream.takeResponseHeaders();
  Response.Builder responseBuilder = readHttp2HeadersList(headers);
  if (expectContinue && Internal.instance.code(responseBuilder) == HTTP_CONTINUE) {
    return null;
  }
  return responseBuilder;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Http2Codec.java


示例11: readHttp2HeadersList

import okhttp3.internal.Internal; //导入依赖的package包/类
/** Returns headers for a name value block containing an HTTP/2 response. */
public static Response.Builder readHttp2HeadersList(List<Header> headerBlock) throws IOException {
  StatusLine statusLine = null;
  Headers.Builder headersBuilder = new Headers.Builder();
  for (int i = 0, size = headerBlock.size(); i < size; i++) {
    Header header = headerBlock.get(i);

    // If there were multiple header blocks they will be delimited by nulls. Discard existing
    // header blocks if the existing header block is a '100 Continue' intermediate response.
    if (header == null) {
      if (statusLine != null && statusLine.code == HTTP_CONTINUE) {
        statusLine = null;
        headersBuilder = new Headers.Builder();
      }
      continue;
    }

    ByteString name = header.name;
    String value = header.value.utf8();
    if (name.equals(RESPONSE_STATUS)) {
      statusLine = StatusLine.parse("HTTP/1.1 " + value);
    } else if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(name)) {
      Internal.instance.addLenient(headersBuilder, name.utf8(), value);
    }
  }
  if (statusLine == null) throw new ProtocolException("Expected ':status' header not present");

  return new Response.Builder()
      .protocol(Protocol.HTTP_2)
      .code(statusLine.code)
      .message(statusLine.message)
      .headers(headersBuilder.build());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:Http2Codec.java


示例12: configureSecureSocket

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Configures the supplied {@link SSLSocket} to connect to the specified host using an appropriate
 * {@link ConnectionSpec}. Returns the chosen {@link ConnectionSpec}, never {@code null}.
 *
 * @throws IOException if the socket does not support any of the TLS modes available
 */
public ConnectionSpec configureSecureSocket(SSLSocket sslSocket) throws IOException {
  ConnectionSpec tlsConfiguration = null;
  for (int i = nextModeIndex, size = connectionSpecs.size(); i < size; i++) {
    ConnectionSpec connectionSpec = connectionSpecs.get(i);
    if (connectionSpec.isCompatible(sslSocket)) {
      tlsConfiguration = connectionSpec;
      nextModeIndex = i + 1;
      break;
    }
  }

  if (tlsConfiguration == null) {
    // This may be the first time a connection has been attempted and the socket does not support
    // any the required protocols, or it may be a retry (but this socket supports fewer
    // protocols than was suggested by a prior socket).
    throw new UnknownServiceException(
        "Unable to find acceptable protocols. isFallback=" + isFallback
            + ", modes=" + connectionSpecs
            + ", supported protocols=" + Arrays.toString(sslSocket.getEnabledProtocols()));
  }

  isFallbackPossible = isFallbackPossible(sslSocket);

  Internal.instance.apply(tlsConfiguration, sslSocket, isFallback);

  return tlsConfiguration;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:ConnectionSpecSelector.java


示例13: deallocate

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Releases resources held by this allocation. If sufficient resources are allocated, the
 * connection will be detached or closed. Callers must be synchronized on the connection pool.
 *
 * <p>Returns a closeable that the caller should pass to {@link Util#closeQuietly} upon completion
 * of the synchronized block. (We don't do I/O while synchronized on the connection pool.)
 */
private Socket deallocate(boolean noNewStreams, boolean released, boolean streamFinished) {
  assert (Thread.holdsLock(connectionPool));

  if (streamFinished) {
    this.codec = null;
  }
  if (released) {
    this.released = true;
  }
  Socket socket = null;
  if (connection != null) {
    if (noNewStreams) {
      connection.noNewStreams = true;
    }
    if (this.codec == null && (this.released || connection.noNewStreams)) {
      release(connection);
      if (connection.allocations.isEmpty()) {
        connection.idleAtNanos = System.nanoTime();
        if (Internal.instance.connectionBecameIdle(connectionPool, connection)) {
          socket = connection.socket();
        }
      }
      connection = null;
    }
  }
  return socket;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:StreamAllocation.java


示例14: emptyResponseHeaderNameFromCacheIsLenient

import okhttp3.internal.Internal; //导入依赖的package包/类
@Test public void emptyResponseHeaderNameFromCacheIsLenient() throws Exception {
  Headers.Builder headers = new Headers.Builder()
      .add("Cache-Control: max-age=120");
  Internal.instance.addLenient(headers, ": A");
  server.enqueue(new MockResponse()
      .setHeaders(headers.build())
      .setBody("body"));

  Response response = get(server.url("/"));
  assertEquals("A", response.header(""));
  assertEquals("body", response.body().string());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:CacheTest.java


示例15: emptyResponseHeaderNameIsLenient

import okhttp3.internal.Internal; //导入依赖的package包/类
@Test public void emptyResponseHeaderNameIsLenient() throws Exception {
  Headers.Builder headers = new Headers.Builder();
  Internal.instance.addLenient(headers, ":A");
  server.enqueue(new MockResponse().setHeaders(headers.build()).setBody("body"));
  connection = urlFactory.open(server.url("/").url());
  connection.getResponseCode();
  assertEquals("A", connection.getHeaderField(""));
  connection.getInputStream().close();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:URLConnectionTest.java


示例16: emptyResponseHeaderNameFromCacheIsLenient

import okhttp3.internal.Internal; //导入依赖的package包/类
@Test public void emptyResponseHeaderNameFromCacheIsLenient() throws Exception {
  Headers.Builder headers = new Headers.Builder()
      .add("Cache-Control: max-age=120");
  Internal.instance.addLenient(headers, ": A");
  server.enqueue(new MockResponse().setHeaders(headers.build()).setBody("body"));

  HttpURLConnection connection = urlFactory.open(server.url("/").url());
  assertEquals("A", connection.getHeaderField(""));
  assertEquals("body", readAscii(connection));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:UrlConnectionCacheTest.java


示例17: readHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
/** Reads headers or trailers. */
public Headers readHeaders() throws IOException {
  Headers.Builder headers = new Headers.Builder();
  // parse the result headers until the first blank line
  for (String line; (line = readHeaderLine()).length() != 0; ) {
    Internal.instance.addLenient(headers, line);
  }
  return headers.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:Http1Codec.java


示例18: varyHeaders

import okhttp3.internal.Internal; //导入依赖的package包/类
private static Headers varyHeaders(URLConnection urlConnection, Headers responseHeaders) {
  if (OkHeaders.hasVaryAll(responseHeaders)) {
    // "*" means that this will be treated as uncacheable anyway.
    return null;
  }
  Set<String> varyFields = OkHeaders.varyFields(responseHeaders);
  if (varyFields.isEmpty()) {
    return new Headers.Builder().build();
  }

  // This probably indicates another HTTP stack is trying to use the shared ResponseCache.
  // We cannot guarantee this case will work properly because we cannot reliably extract *all*
  // the request header values, and we can't get multiple Vary request header values.
  // We also can't be sure about the Accept-Encoding behavior of other stacks.
  if (!(urlConnection instanceof CacheHttpURLConnection
      || urlConnection instanceof CacheHttpsURLConnection)) {
    return null;
  }

  // This is the case we expect: The URLConnection is from a call to
  // JavaApiConverter.createJavaUrlConnection() and we have access to the user's request headers.
  Map<String, List<String>> requestProperties = urlConnection.getRequestProperties();
  Headers.Builder result = new Headers.Builder();
  for (String fieldName : varyFields) {
    List<String> fieldValues = requestProperties.get(fieldName);
    if (fieldValues == null) {
      if (fieldName.equals("Accept-Encoding")) {
        // Accept-Encoding is special. If OkHttp sees Accept-Encoding is unset it will add
        // "gzip". We don't have access to the request that was actually made so we must do the
        // same.
        result.add("Accept-Encoding", "gzip");
      }
    } else {
      for (String fieldValue : fieldValues) {
        Internal.instance.addLenient(result, fieldName, fieldValue);
      }
    }
  }
  return result.build();
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:41,代码来源:JavaApiConverter.java


示例19: createWebSocket

import okhttp3.internal.Internal; //导入依赖的package包/类
private void createWebSocket(Response response, WebSocketListener listener) throws IOException {
  if (response.code() != 101) {
    Util.closeQuietly(response.body());
    throw new ProtocolException("Expected HTTP 101 response but was '"
        + response.code()
        + " "
        + response.message()
        + "'");
  }

  String headerConnection = response.header("Connection");
  if (!"Upgrade".equalsIgnoreCase(headerConnection)) {
    throw new ProtocolException(
        "Expected 'Connection' header value 'Upgrade' but was '" + headerConnection + "'");
  }
  String headerUpgrade = response.header("Upgrade");
  if (!"websocket".equalsIgnoreCase(headerUpgrade)) {
    throw new ProtocolException(
        "Expected 'Upgrade' header value 'websocket' but was '" + headerUpgrade + "'");
  }
  String headerAccept = response.header("Sec-WebSocket-Accept");
  String acceptExpected = Util.shaBase64(key + WebSocketProtocol.ACCEPT_MAGIC);
  if (!acceptExpected.equals(headerAccept)) {
    throw new ProtocolException("Expected 'Sec-WebSocket-Accept' header value '"
        + acceptExpected
        + "' but was '"
        + headerAccept
        + "'");
  }

  StreamAllocation streamAllocation = Internal.instance.callEngineGetStreamAllocation(call);
  RealWebSocket webSocket = StreamWebSocket.create(
      streamAllocation, response, random, listener);

  listener.onOpen(webSocket, response);

  while (webSocket.readMessage()) {
  }
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:40,代码来源:WebSocketCall.java


示例20: deallocate

import okhttp3.internal.Internal; //导入依赖的package包/类
/**
 * Releases resources held by this allocation. If sufficient resources are allocated, the
 * connection will be detached or closed.
 */
private void deallocate(boolean noNewStreams, boolean released, boolean streamFinished) {
  RealConnection connectionToClose = null;
  synchronized (connectionPool) {
    if (streamFinished) {
      this.stream = null;
    }
    if (released) {
      this.released = true;
    }
    if (connection != null) {
      if (noNewStreams) {
        connection.noNewStreams = true;
      }
      if (this.stream == null && (this.released || connection.noNewStreams)) {
        release(connection);
        if (connection.allocations.isEmpty()) {
          connection.idleAtNanos = System.nanoTime();
          if (Internal.instance.connectionBecameIdle(connectionPool, connection)) {
            connectionToClose = connection;
          }
        }
        connection = null;
      }
    }
  }
  if (connectionToClose != null) {
    Util.closeQuietly(connectionToClose.socket());
  }
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:34,代码来源:StreamAllocation.java



注:本文中的okhttp3.internal.Internal类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LinkTargetException类代码示例发布时间:2022-05-23
下一篇:
Java GreedyPVRTexturePixelBufferStrategy类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap