當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。