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


Java ResponseBody.close方法代碼示例

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


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

示例1: doInBackground

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
/**
 *
 * @param params
 * @return
 */
@Override
protected String doInBackground(Void... params) {
    OkHttpClient client = new OkHttpClient();

    HttpUrl httpUrl = HttpUrl.parse(COIN_DESK_API_URL);
    //System.out.println("Requesting : " + httpUrl.toString());

    FormEncodingBuilder formBody = new FormEncodingBuilder();
    formBody.add("lastHours", "24");
    formBody.add("maxRespArrSize", "24");

    Request request = new Request.Builder()
            .url(httpUrl)
            .post(formBody.build())
            .build();

    String content = null;
    try {
        Response response = client.newCall(request).execute();
        ResponseBody body = response.body();

        if (isZipped(response)) {
            content = unzip(body);
        } else {
            content = body.string();
        }

        body.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}
 
開發者ID:ehanoc,項目名稱:xwallet,代碼行數:40,代碼來源:CexChartAPI.java

示例2: fromResponseBody

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
@Override
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
    //noinspection EqualsBetweenInconvertibleTypes
    if (Document.class.equals(type)) {
        return new Converter<ResponseBody, Object>() {

            @Override
            public Object convert(ResponseBody responseBody) throws IOException {
                Document doc = Jsoup.parse(responseBody.string());
                responseBody.close();
                return doc;
            }
        };
    }

    return null;
}
 
開發者ID:y3seker,項目名稱:EgeYemekhaneMobil,代碼行數:18,代碼來源:DocumentConverterFactory.java

示例3: doInBackground

import com.squareup.okhttp.ResponseBody; //導入方法依賴的package包/類
/**
 *
 * @param params
 * @return
 */
@Override
protected String doInBackground(Void... params) {

    OkHttpClient client = new OkHttpClient();

    HttpUrl httpUrl = HttpUrl.parse(TwitterSearchURL);
    httpUrl = httpUrl.newBuilder()
            .addQueryParameter("q", _searchTerm)
            .addQueryParameter("lang", "en")
            .addQueryParameter("result_type", "recent")
            .build();

    Request request = new Request.Builder()
            .url(httpUrl)
            .addHeader("Authorization", "Bearer " + _bearerToken)
            .addHeader("Accept-Encoding", "gzip")
            .build();

    String content = null;
    try {
        Response response = client.newCall(request).execute();
        ResponseBody body = response.body();

        if (isZipped(response)) {
            content = unzip(body);
        } else {
            content = body.string();
        }

        body.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}
 
開發者ID:ehanoc,項目名稱:xwallet,代碼行數:42,代碼來源:TwitterSearchApi.java

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


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