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


Java Headers.size方法代碼示例

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


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

示例1: toMultimap

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
    Map<String, List<String>> result = new TreeMap(FIELD_NAME_COMPARATOR);
    int size = headers.size();
    for (int i = 0; i < size; i++) {
        String fieldName = headers.name(i);
        String value = headers.value(i);
        List<String> allValues = new ArrayList();
        List<String> otherValues = (List) result.get(fieldName);
        if (otherValues != null) {
            allValues.addAll(otherValues);
        }
        allValues.add(value);
        result.put(fieldName, Collections.unmodifiableList(allValues));
    }
    if (valueForNullKey != null) {
        result.put(null, Collections.unmodifiableList(Collections.singletonList
                (valueForNullKey)));
    }
    return Collections.unmodifiableMap(result);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:OkHeaders.java

示例2: combine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static Headers combine(Headers cachedHeaders, Headers networkHeaders) throws
        IOException {
    int i;
    Headers.Builder result = new Headers.Builder();
    int size = cachedHeaders.size();
    for (i = 0; i < size; i++) {
        String fieldName = cachedHeaders.name(i);
        String value = cachedHeaders.value(i);
        if (!("Warning".equalsIgnoreCase(fieldName) && value.startsWith("1")) && (!OkHeaders
                .isEndToEnd(fieldName) || networkHeaders.get(fieldName) == null)) {
            result.add(fieldName, value);
        }
    }
    size = networkHeaders.size();
    for (i = 0; i < size; i++) {
        fieldName = networkHeaders.name(i);
        if (!"Content-Length".equalsIgnoreCase(fieldName) && OkHeaders.isEndToEnd(fieldName)) {
            result.add(fieldName, networkHeaders.value(i));
        }
    }
    return result.build();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:23,代碼來源:HttpEngine.java

示例3: transformResponse

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static HttpResponse transformResponse(Response response) {
    int code = response.code();
    String message = response.message();
    BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);

    ResponseBody body = response.body();
    InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
    httpResponse.setEntity(entity);

    Headers headers = response.headers();
    for (int i = 0; i < headers.size(); i++) {
        String name = headers.name(i);
        String value = headers.value(i);
        httpResponse.addHeader(name, value);
        if ("Content-Type".equalsIgnoreCase(name)) {
            entity.setContentType(value);
        } else if ("Content-Encoding".equalsIgnoreCase(name)) {
            entity.setContentEncoding(value);
        }
    }

    return httpResponse;
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:24,代碼來源:UTILS.java

示例4: transformResponse

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static HttpResponse transformResponse(Response response) {
  int code = response.code();
  String message = response.message();
  BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);

  ResponseBody body = response.body();
  InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
  httpResponse.setEntity(entity);

  Headers headers = response.headers();
  for (int i = 0; i < headers.size(); i++) {
    String name = headers.name(i);
    String value = headers.value(i);
    httpResponse.addHeader(name, value);
    if ("Content-Type".equalsIgnoreCase(name)) {
      entity.setContentType(value);
    } else if ("Content-Encoding".equalsIgnoreCase(name)) {
      entity.setContentEncoding(value);
    }
  }

  return httpResponse;
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:24,代碼來源:OkApacheClient.java

示例5: toMultimap

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Returns an immutable map containing each field to its list of values.
 *
 * @param valueForNullKey the request line for requests, or the status line
 *     for responses. If non-null, this value is mapped to the null key.
 */
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
  Map<String, List<String>> result = new TreeMap<>(FIELD_NAME_COMPARATOR);
  for (int i = 0; i < headers.size(); i++) {
    String fieldName = headers.name(i);
    String value = headers.value(i);

    List<String> allValues = new ArrayList<>();
    List<String> otherValues = result.get(fieldName);
    if (otherValues != null) {
      allValues.addAll(otherValues);
    }
    allValues.add(value);
    result.put(fieldName, Collections.unmodifiableList(allValues));
  }
  if (valueForNullKey != null) {
    result.put(null, Collections.unmodifiableList(Collections.singletonList(valueForNullKey)));
  }
  return Collections.unmodifiableMap(result);
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:26,代碼來源:OkHeaders.java

示例6: varyFields

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static Set<String> varyFields(Response response) {
  Set<String> result = Collections.emptySet();
  Headers headers = response.headers();
  for (int i = 0; i < headers.size(); i++) {
    if (!"Vary".equalsIgnoreCase(headers.name(i))) continue;

    String value = headers.value(i);
    if (result.isEmpty()) {
      result = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
    }
    for (String varyField : value.split(",")) {
      result.add(varyField.trim());
    }
  }
  return result;
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:17,代碼來源:OkHeaders.java

示例7: varyHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Returns the subset of the headers in {@code response}'s request that
 * impact the content of response's body.
 */
public static Headers varyHeaders(Response response) {
  Set<String> varyFields = varyFields(response);
  if (varyFields.isEmpty()) return new Headers.Builder().build();

  // Use the request headers sent over the network, since that's what the
  // response varies on. Otherwise OkHttp-supplied headers like
  // "Accept-Encoding: gzip" may be lost.
  Headers requestHeaders = response.networkResponse().request().headers();

  Headers.Builder result = new Headers.Builder();
  for (int i = 0; i < requestHeaders.size(); i++) {
    String fieldName = requestHeaders.name(i);
    if (varyFields.contains(fieldName)) {
      result.add(fieldName, requestHeaders.value(i));
    }
  }
  return result.build();
}
 
開發者ID:NannanZ,項目名稱:spdymcsclient,代碼行數:23,代碼來源:OkHeaders.java

示例8: toMultimap

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
/**
 * Returns an immutable map containing each field to its list of values.
 *
 * @param valueForNullKey the request line for requests, or the status line
 *     for responses. If non-null, this value is mapped to the null key.
 */
public static Map<String, List<String>> toMultimap(Headers headers, String valueForNullKey) {
  Map<String, List<String>> result = new TreeMap<String, List<String>>(FIELD_NAME_COMPARATOR);
  for (int i = 0; i < headers.size(); i++) {
    String fieldName = headers.name(i);
    String value = headers.value(i);

    List<String> allValues = new ArrayList<String>();
    List<String> otherValues = result.get(fieldName);
    if (otherValues != null) {
      allValues.addAll(otherValues);
    }
    allValues.add(value);
    result.put(fieldName, Collections.unmodifiableList(allValues));
  }
  if (valueForNullKey != null) {
    result.put(null, Collections.unmodifiableList(Collections.singletonList(valueForNullKey)));
  }
  return Collections.unmodifiableMap(result);
}
 
開發者ID:xin3liang,項目名稱:platform_external_okhttp,代碼行數:26,代碼來源:OkHeaders.java

示例9: writeRequest

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public void writeRequest(Headers headers, String requestLine) throws IOException {
    if (this.state != 0) {
        throw new IllegalStateException("state: " + this.state);
    }
    this.sink.writeUtf8(requestLine).writeUtf8("\r\n");
    int size = headers.size();
    for (int i = 0; i < size; i++) {
        this.sink.writeUtf8(headers.name(i)).writeUtf8(": ").writeUtf8(headers.value(i))
                .writeUtf8("\r\n");
    }
    this.sink.writeUtf8("\r\n");
    this.state = 1;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:14,代碼來源:Http1xStream.java

示例10: varyHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Headers varyHeaders(Headers requestHeaders, Headers responseHeaders) {
    Set<String> varyFields = varyFields(responseHeaders);
    if (varyFields.isEmpty()) {
        return new Headers.Builder().build();
    }
    Headers.Builder result = new Headers.Builder();
    int size = requestHeaders.size();
    for (int i = 0; i < size; i++) {
        String fieldName = requestHeaders.name(i);
        if (varyFields.contains(fieldName)) {
            result.add(fieldName, requestHeaders.value(i));
        }
    }
    return result.build();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:16,代碼來源:OkHeaders.java

示例11: parseChallenges

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static List<Challenge> parseChallenges(Headers responseHeaders, String challengeHeader) {
    List<Challenge> result = new ArrayList();
    int size = responseHeaders.size();
    for (int i = 0; i < size; i++) {
        if (challengeHeader.equalsIgnoreCase(responseHeaders.name(i))) {
            String value = responseHeaders.value(i);
            int pos = 0;
            while (pos < value.length()) {
                int tokenStart = pos;
                pos = HeaderParser.skipUntil(value, pos, " ");
                String scheme = value.substring(tokenStart, pos).trim();
                pos = HeaderParser.skipWhitespace(value, pos);
                if (!value.regionMatches(true, pos, "realm=\"", 0, "realm=\"".length())) {
                    break;
                }
                pos += "realm=\"".length();
                int realmStart = pos;
                pos = HeaderParser.skipUntil(value, pos, a.e);
                String realm = value.substring(realmStart, pos);
                pos = HeaderParser.skipWhitespace(value, HeaderParser.skipUntil(value, pos +
                        1, ",") + 1);
                result.add(new Challenge(scheme, realm));
            }
        }
    }
    return result;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:28,代碼來源:OkHeaders.java

示例12: if

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public CacheStrategy$Factory(long nowMillis, Request request, Response cacheResponse) {
    this.nowMillis = nowMillis;
    this.request = request;
    this.cacheResponse = cacheResponse;
    if (cacheResponse != null) {
        Headers headers = cacheResponse.headers();
        int size = headers.size();
        for (int i = 0; i < size; i++) {
            String fieldName = headers.name(i);
            String value = headers.value(i);
            if ("Date".equalsIgnoreCase(fieldName)) {
                this.servedDate = HttpDate.parse(value);
                this.servedDateString = value;
            } else if ("Expires".equalsIgnoreCase(fieldName)) {
                this.expires = HttpDate.parse(value);
            } else if ("Last-Modified".equalsIgnoreCase(fieldName)) {
                this.lastModified = HttpDate.parse(value);
                this.lastModifiedString = value;
            } else if ("ETag".equalsIgnoreCase(fieldName)) {
                this.etag = value;
            } else if ("Age".equalsIgnoreCase(fieldName)) {
                this.ageSeconds = HeaderParser.parseSeconds(value, -1);
            } else if (OkHeaders.SENT_MILLIS.equalsIgnoreCase(fieldName)) {
                this.sentRequestMillis = Long.parseLong(value);
            } else if (OkHeaders.RECEIVED_MILLIS.equalsIgnoreCase(fieldName)) {
                this.receivedResponseMillis = Long.parseLong(value);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:31,代碼來源:CacheStrategy$Factory.java

示例13: newHttpEngine

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private HttpEngine newHttpEngine(String method, StreamAllocation streamAllocation,
                                 RetryableSink requestBody, Response priorResponse) throws
        MalformedURLException, UnknownHostException {
    Request.Builder builder = new Request.Builder().url(Internal.instance.getHttpUrlChecked
            (getURL().toString())).method(method, HttpMethod.requiresRequestBody(method) ?
            EMPTY_REQUEST_BODY : null);
    Headers headers = this.requestHeaders.build();
    int size = headers.size();
    for (int i = 0; i < size; i++) {
        builder.addHeader(headers.name(i), headers.value(i));
    }
    boolean bufferRequestBody = false;
    if (HttpMethod.permitsRequestBody(method)) {
        if (this.fixedContentLength != -1) {
            builder.header("Content-Length", Long.toString(this.fixedContentLength));
        } else if (this.chunkLength > 0) {
            builder.header("Transfer-Encoding", "chunked");
        } else {
            bufferRequestBody = true;
        }
        if (headers.get("Content-Type") == null) {
            builder.header("Content-Type", Client.FormMime);
        }
    }
    if (headers.get(Network.USER_AGENT) == null) {
        builder.header(Network.USER_AGENT, defaultUserAgent());
    }
    Request request = builder.build();
    OkHttpClient engineClient = this.client;
    if (!(Internal.instance.internalCache(engineClient) == null || getUseCaches())) {
        engineClient = this.client.clone().setCache(null);
    }
    return new HttpEngine(engineClient, request, bufferRequestBody, true, false,
            streamAllocation, requestBody, priorResponse);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:36,代碼來源:HttpURLConnectionImpl.java

示例14: translateHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private static WritableMap translateHeaders(Headers headers) {
  WritableMap responseHeaders = Arguments.createMap();
  for (int i = 0; i < headers.size(); i++) {
    String headerName = headers.name(i);
    // multiple values for the same header
    if (responseHeaders.hasKey(headerName)) {
      responseHeaders.putString(
          headerName,
          responseHeaders.getString(headerName) + ", " + headers.value(i));
    } else {
      responseHeaders.putString(headerName, headers.value(i));
    }
  }
  return responseHeaders;
}
 
開發者ID:john1jan,項目名稱:ReactNativeSignatureExample,代碼行數:16,代碼來源:NetworkingModule.java

示例15: transformHeaders

import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
private MultivaluedMap<String, String> transformHeaders(Headers headers) {
  MultivaluedMap<String, String> ret = new CaseInsensitiveMap<>();
  for (int i = 0, l = headers.size(); i < l; i++) {
    ret.add(headers.name(i), headers.value(i));
  }
  return ret;
}
 
開發者ID:tbroyer,項目名稱:jaxrs-utils,代碼行數:8,代碼來源:OkHttpClientEngine.java


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