本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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();
}