本文整理匯總了Java中com.squareup.okhttp.Headers.name方法的典型用法代碼示例。如果您正苦於以下問題:Java Headers.name方法的具體用法?Java Headers.name怎麽用?Java Headers.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.okhttp.Headers
的用法示例。
在下文中一共展示了Headers.name方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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);
}
示例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();
}
示例3: TreeMap
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Map<String, List<String>> toMultimap$29224fb9(Headers paramHeaders)
{
TreeMap localTreeMap = new TreeMap(FIELD_NAME_COMPARATOR);
int i = 0;
int j = paramHeaders.namesAndValues.length / 2;
while (i < j)
{
String str1 = paramHeaders.name(i);
String str2 = paramHeaders.value(i);
ArrayList localArrayList = new ArrayList();
List localList = (List)localTreeMap.get(str1);
if (localList != null) {
localArrayList.addAll(localList);
}
localArrayList.add(str2);
localTreeMap.put(str1, Collections.unmodifiableList(localArrayList));
i++;
}
return Collections.unmodifiableMap(localTreeMap);
}
示例4: 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;
}
示例5: 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;
}
示例6: 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);
}
示例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();
}
示例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);
}
示例9: 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();
}
示例10: 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);
}
}
}
}
示例11: 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;
}
示例12: combine
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public static Headers combine(Headers paramHeaders1, Headers paramHeaders2)
throws IOException
{
Headers.Builder localBuilder = new Headers.Builder();
int i = 0;
int j = paramHeaders1.namesAndValues.length / 2;
while (i < j)
{
String str2 = paramHeaders1.name(i);
String str3 = paramHeaders1.value(i);
if (((!"Warning".equalsIgnoreCase(str2)) || (!str3.startsWith("1"))) && ((!OkHeaders.isEndToEnd(str2)) || (paramHeaders2.get(str2) == null))) {
localBuilder.add(str2, str3);
}
i++;
}
int k = 0;
int m = paramHeaders2.namesAndValues.length / 2;
while (k < m)
{
String str1 = paramHeaders2.name(k);
if ((!"Content-Length".equalsIgnoreCase(str1)) && (OkHeaders.isEndToEnd(str1))) {
localBuilder.add(str1, paramHeaders2.value(k));
}
k++;
}
return localBuilder.build();
}
示例13: Factory
import com.squareup.okhttp.Headers; //導入方法依賴的package包/類
public Factory(long paramLong, Request paramRequest, Response paramResponse)
{
this.nowMillis = paramLong;
this.request = paramRequest;
this.cacheResponse = paramResponse;
if (paramResponse != null)
{
Headers localHeaders = paramResponse.headers;
int i = 0;
int j = localHeaders.namesAndValues.length / 2;
if (i < j)
{
String str1 = localHeaders.name(i);
String str2 = localHeaders.value(i);
if ("Date".equalsIgnoreCase(str1))
{
this.servedDate = HttpDate.parse(str2);
this.servedDateString = str2;
}
for (;;)
{
i++;
break;
if ("Expires".equalsIgnoreCase(str1))
{
this.expires = HttpDate.parse(str2);
}
else if ("Last-Modified".equalsIgnoreCase(str1))
{
this.lastModified = HttpDate.parse(str2);
this.lastModifiedString = str2;
}
else if ("ETag".equalsIgnoreCase(str1))
{
this.etag = str2;
}
else if ("Age".equalsIgnoreCase(str1))
{
this.ageSeconds = HeaderParser.parseSeconds(str2, -1);
}
else if (OkHeaders.SENT_MILLIS.equalsIgnoreCase(str1))
{
this.sentRequestMillis = Long.parseLong(str2);
}
else if (OkHeaders.RECEIVED_MILLIS.equalsIgnoreCase(str1))
{
this.receivedResponseMillis = Long.parseLong(str2);
}
}
}
}
}