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


Java ResponseBody.contentType方法代码示例

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


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

示例1: entityFromOkHttpResponse

import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
private static HttpEntity entityFromOkHttpResponse(Response r) throws IOException {
    BasicHttpEntity entity = new BasicHttpEntity();
    ResponseBody body = r.body();

    entity.setContent(body.byteStream());
    entity.setContentLength(body.contentLength());
    entity.setContentEncoding(r.header("Content-Encoding"));

    if (body.contentType() != null) {
        entity.setContentType(body.contentType().type());
    }
    return entity;
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:14,代码来源:OkHttpStack.java

示例2: onMessage

import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public void onMessage(ResponseBody body) throws IOException {
    if (body.contentType() == TEXT) {
        listener.textMessage(body.charStream());
    } else if (body.contentType() == BINARY) {
        listener.bytesMessage(body.byteStream());
    }
    body.close();
}
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:10,代码来源:WebSockets.java

示例3: intercept

import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public Response intercept(Chain chain) throws IOException {
  String requestId = String.valueOf(mNextRequestId.getAndIncrement());

  Request request = chain.request();

  RequestBodyHelper requestBodyHelper = null;
  if (mEventReporter.isEnabled()) {
    requestBodyHelper = new RequestBodyHelper(mEventReporter, requestId);
    OkHttpInspectorRequest inspectorRequest =
        new OkHttpInspectorRequest(requestId, request, requestBodyHelper);
    mEventReporter.requestWillBeSent(inspectorRequest);
  }

  Response response;
  try {
    response = chain.proceed(request);
  } catch (IOException e) {
    if (mEventReporter.isEnabled()) {
      mEventReporter.httpExchangeFailed(requestId, e.toString());
    }
    throw e;
  }

  if (mEventReporter.isEnabled()) {
    if (requestBodyHelper != null && requestBodyHelper.hasBody()) {
      requestBodyHelper.reportDataSent();
    }

    Connection connection = chain.connection();
    mEventReporter.responseHeadersReceived(
        new OkHttpInspectorResponse(
            requestId,
            request,
            response,
            connection));

    ResponseBody body = response.body();
    MediaType contentType = null;
    InputStream responseStream = null;
    if (body != null) {
      contentType = body.contentType();
      responseStream = body.byteStream();
    }

    responseStream = mEventReporter.interpretResponseStream(
        requestId,
        contentType != null ? contentType.toString() : null,
        response.header("Content-Encoding"),
        responseStream,
        new DefaultResponseHandler(mEventReporter, requestId));
    if (responseStream != null) {
      response = response.newBuilder()
          .body(new ForwardingResponseBody(body, responseStream))
          .build();
    }
  }

  return response;
}
 
开发者ID:Laisly,项目名称:weex,代码行数:61,代码来源:OkHttpInterceptor.java


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