当前位置: 首页>>代码示例>>Java>>正文


Java Headers类代码示例

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


Headers类属于com.squareup.okhttp包,在下文中一共展示了Headers类的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: appendHeaders

import com.squareup.okhttp.Headers; //导入依赖的package包/类
protected void appendHeaders(Request.Builder builder, Map<String, String> headers)
{
    if (builder == null)
    {
        throw new IllegalArgumentException("builder can not be empty!");
    }

    Headers.Builder headerBuilder = new Headers.Builder();
    if (headers == null || headers.isEmpty()) return;

    for (String key : headers.keySet())
    {
        headerBuilder.add(key, headers.get(key));
    }
    builder.headers(headerBuilder.build());
}
 
开发者ID:dscn,项目名称:ktball,代码行数:17,代码来源:OkHttpRequest.java

示例3: buildUpload

import com.squareup.okhttp.Headers; //导入依赖的package包/类
private static Request buildUpload(ACTION action, File[] files,
		String[] filenames, Object requestBean) {
	String json = GsonTool.toJson(requestBean);
	MultipartBuilder builder = new MultipartBuilder()
			.type(MultipartBuilder.FORM);
	if (files != null) {
		for (int i = 0; i < filenames.length; i++) {
			builder.addPart(Headers.of("Content-Disposition",
					"form-data;name=\"" + "file" + i + "\";filename=\""
							+ filenames[i] + "\""), RequestBody.create(
					MediaType.parse("application/octet-stream"), files[i]));
		}
	}
	builder.addPart(
			Headers.of("Content-Disposition", "form-data; name=\""
					+ RequestArr.requestArg + "\""),
			RequestBody.create(null, json));
	String url = RequestArr.mainUrl + RequestArr.mUrls.get(action);
	return new Request.Builder().url(url).post(builder.build()).build();
}
 
开发者ID:wangcantian,项目名称:Mobile-Office,代码行数:21,代码来源:RequestFactory.java

示例4: 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

示例5: addParams

import com.squareup.okhttp.Headers; //导入依赖的package包/类
private void addParams(MultipartBuilder builder, Map<String, String> params)
{
    if (builder == null)
    {
        throw new IllegalArgumentException("builder can not be null .");
    }

    if (params != null && !params.isEmpty())
    {
        for (String key : params.keySet())
        {
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + key + "\""),
                    RequestBody.create(null, params.get(key)));

        }
    }
}
 
开发者ID:dscn,项目名称:ktball,代码行数:18,代码来源:OkHttpUploadRequest.java

示例6: buildRequestBody

import com.squareup.okhttp.Headers; //导入依赖的package包/类
@Override
public RequestBody buildRequestBody()
{
    MultipartBuilder builder = new MultipartBuilder()
            .type(MultipartBuilder.FORM);
    addParams(builder, params);

    if (files != null)
    {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++)
        {
            Pair<String, File> filePair = files[i];
            String fileKeyName = filePair.first;
            File file = filePair.second;
            String fileName = file.getName();
            fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
            builder.addPart(Headers.of("Content-Disposition",
                            "form-data; name=\"" + fileKeyName + "\"; filename=\"" + fileName + "\""),
                    fileBody);
        }
    }

    return builder.build();
}
 
开发者ID:dscn,项目名称:ktball,代码行数:26,代码来源:OkHttpUploadRequest.java

示例7: getChartset

import com.squareup.okhttp.Headers; //导入依赖的package包/类
public static Charset getChartset(RecordedRequest request){
    Headers headers = request.getHeaders();
    String value = headers.get("content-type");
    String[] array = value.split(";");
    Charset charset = null;
    try {
        if(array.length>1&&array[1].startsWith("charset=")){
            String charSetStr = array[1].split("=")[1];
            charset = Charset.forName(charSetStr);
        }
    } catch (Exception e) {
        System.out.println("ContentType:"+value);
        e.printStackTrace();
    }
    if(charset==null){
        charset = Charset.forName("utf-8");
    }
    return charset;
}
 
开发者ID:alexclin0188,项目名称:httplite,代码行数:20,代码来源:HttpUtil.java

示例8: 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);
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:21,代码来源:OkHeaders.java

示例9: readResponse

import com.squareup.okhttp.Headers; //导入依赖的package包/类
public final Response.Builder readResponse()
  throws IOException
{
  if ((this.state != 1) && (this.state != 3)) {
    throw new IllegalStateException("state: " + this.state);
  }
  StatusLine localStatusLine;
  Response.Builder localBuilder;
  do
  {
    localStatusLine = StatusLine.parse(this.source.readUtf8LineStrict());
    localBuilder = new Response.Builder();
    localBuilder.protocol = localStatusLine.protocol;
    localBuilder.code = localStatusLine.code;
    localBuilder.message = localStatusLine.message;
    Headers.Builder localBuilder1 = new Headers.Builder();
    readHeaders(localBuilder1);
    localBuilder1.add(OkHeaders.SELECTED_PROTOCOL, localStatusLine.protocol.toString());
    localBuilder.headers(localBuilder1.build());
  } while (localStatusLine.code == 100);
  this.state = 4;
  return localBuilder;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:24,代码来源:HttpConnection.java

示例10: writeRequest

import com.squareup.okhttp.Headers; //导入依赖的package包/类
public final void writeRequest(Headers paramHeaders, String paramString)
  throws IOException
{
  if (this.state != 0) {
    throw new IllegalStateException("state: " + this.state);
  }
  this.sink.writeUtf8(paramString).writeUtf8("\r\n");
  int i = 0;
  int j = paramHeaders.namesAndValues.length / 2;
  while (i < j)
  {
    this.sink.writeUtf8(paramHeaders.name(i)).writeUtf8(": ").writeUtf8(paramHeaders.value(i)).writeUtf8("\r\n");
    i++;
  }
  this.sink.writeUtf8("\r\n");
  this.state = 1;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:18,代码来源:HttpConnection.java

示例11: isBinaryContent

import com.squareup.okhttp.Headers; //导入依赖的package包/类
private static boolean isBinaryContent(Headers paramHeaders, MediaType paramMediaType)
{
  List localList = paramHeaders.values("Content-Encoding");
  if (localList != null)
  {
    Iterator localIterator = localList.iterator();
    while (localIterator.hasNext()) {
      if (((String)localIterator.next()).equalsIgnoreCase("gzip")) {
        return true;
      }
    }
  }
  String str1 = paramMediaType.type;
  String str2 = paramMediaType.subtype;
  if (str1 != null)
  {
    if (str1.equals("text")) {
      return false;
    }
    if ((str1.equals("application")) && (str2 != null)) {
      return (!str2.equals("xml")) && (!str2.equals("json"));
    }
  }
  return true;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:26,代码来源:CurlLoggingInterceptor.java

示例12: buildMultipartFormRequest

import com.squareup.okhttp.Headers; //导入依赖的package包/类
private Request buildMultipartFormRequest(String url, String[] fileKeys, File[] files, Param[] paramses) {
    paramses = validateParam(paramses);
    MultipartBuilder builder = new MultipartBuilder().type(MultipartBuilder.FORM);

    for (Param param : paramses) {
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + param.key + "\""), RequestBody.create(null, param.value));
    }

    if (files != null) {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
            String fileName = file.getName();
            fileBody = RequestBody.create(MediaType.parse(guessMineType(fileName)), file);
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"" + fileKeys[i] + "\"; filename=\"" + fileName + "\""), fileBody);
        }
    }

    RequestBody requestBody = builder.build();
    return new Request.Builder().url(url).post(requestBody).build();
}
 
开发者ID:g977284333,项目名称:KwPresent,代码行数:22,代码来源:DownLoadManager.java

示例13: buildRequestBody

import com.squareup.okhttp.Headers; //导入依赖的package包/类
@Override
public RequestBody buildRequestBody() {
    MultipartBuilder builder = new MultipartBuilder()
            .type(MultipartBuilder.FORM);
    addParams(builder, params);

    if (files != null) {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++) {
            Pair<String, File> filePair = files[i];
            String fileKeyName = filePair.first;
            File file = filePair.second;
            String fileName = file.getName();
            fileBody = RequestBody.create(MediaType.parse(guessMimeType(fileName)), file);
            builder.addPart(Headers.of("Content-Disposition",
                            "form-data; name=\"" + fileKeyName + "\"; filename=\"" + fileName + "\""),
                    fileBody);
        }
    }

    return builder.build();
}
 
开发者ID:bmbstack,项目名称:android-kit-old,代码行数:23,代码来源:OkHttpUploadRequest.java

示例14: buildMultipartFormRequest

import com.squareup.okhttp.Headers; //导入依赖的package包/类
private RequestBody buildMultipartFormRequest(String[] fileKeys, File[] files, Map<String, String> params) {
    MultipartBuilder builder = new MultipartBuilder().type(MultipartBuilder.FORM);
    for (Map.Entry<String, String> entry : params.entrySet()) {
        builder.addPart(Headers.of("Content-Disposition", "form-data;name=\"" + entry.getKey() + "\""), RequestBody.create(null, entry.getValue()));
    }
    if (files != null && fileKeys != null && files.length == fileKeys.length) {
        RequestBody fileBody = null;
        for (int i = 0; i < files.length; i++) {
            fileBody = RequestBody.create(MediaType.parse(getMimeType(files[i].getName())), files[i]);
            builder.addPart(Headers.of("Content-Disposition",
                    "form-data;name=\"" + fileKeys[i] + "\";filename=\"" + files[i].getName() + "\""), fileBody);
        }
    } else {
        try {
            throw new Exception("文件名参数长度和文件实体内容长度不一致");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return builder.build();
}
 
开发者ID:hjw541988478,项目名称:OkHttpTutorial,代码行数:22,代码来源:OkHttpUtil.java

示例15: addHeader

import com.squareup.okhttp.Headers; //导入依赖的package包/类
private void addHeader() {
    try {
        URI uri = new URI(url);
        String userInfo = uri.getUserInfo();
        if (userInfo != null) {
            setHeader("Authorization", "Basic " + base64Encode(userInfo));
        }
    } catch (URISyntaxException e) {
        debug(e);
    }

    StringBuilder userAgent = new StringBuilder("BirudoRogu-Android");
    setHeader("User-Agent", userAgent.toString());
    // set headers on request
    Headers.Builder headerBuilder = new Headers.Builder();
    for (String key : header.keySet()) {
        headerBuilder.set(key, header.get(key));
    }
    setHeaders(headerBuilder.build());
}
 
开发者ID:eyedol,项目名称:birudo,代码行数:21,代码来源:BaseHttpClient.java


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