本文整理汇总了Java中com.squareup.okhttp.ResponseBody.charStream方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseBody.charStream方法的具体用法?Java ResponseBody.charStream怎么用?Java ResponseBody.charStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.squareup.okhttp.ResponseBody
的用法示例。
在下文中一共展示了ResponseBody.charStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onResponse
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public void onResponse(Response response) throws IOException {
if (!response.isSuccessful()) {
postOnFailure(parseUnsuccessfulResponse(response));
return;
}
ResponseBody body = response.body();
try {
Reader charStream = body.charStream();
T payload = getAdapter().fromJson(charStream);
postOnSuccess(payload);
} catch (IOException e) {
final Auth0Exception auth0Exception = new Auth0Exception("Failed to parse response to request to " + url, e);
postOnFailure(getErrorBuilder().from("Failed to parse a successful response", auth0Exception));
} finally {
closeStream(body);
}
}
示例2: readWithProgress
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
private void readWithProgress(
ExecutorToken executorToken,
int requestId,
ResponseBody responseBody) throws IOException {
Reader reader = responseBody.charStream();
try {
StringBuilder sb = new StringBuilder(getBufferSize(responseBody));
char[] buffer = new char[MIN_BUFFER_SIZE];
int read;
long last = System.nanoTime();
while ((read = reader.read(buffer)) != -1) {
sb.append(buffer, 0, read);
long now = System.nanoTime();
if (shouldDispatch(now, last)) {
onDataReceived(executorToken, requestId, sb.toString());
sb.setLength(0);
last = now;
}
}
if (sb.length() > 0) {
onDataReceived(executorToken, requestId, sb.toString());
}
} finally {
reader.close();
}
}
示例3: readWithProgress
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
private void readWithProgress(
ExecutorToken executorToken,
int requestId,
ResponseBody responseBody) throws IOException {
Reader reader = responseBody.charStream();
try {
char[] buffer = new char[MAX_CHUNK_SIZE_BETWEEN_FLUSHES];
int read;
while ((read = reader.read(buffer)) != -1) {
onDataReceived(executorToken, requestId, new String(buffer, 0, read));
}
} finally {
reader.close();
}
}
示例4: convert
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public T convert(ResponseBody value) throws IOException {
Reader reader = value.charStream();
try {
return adapter.readValue(reader);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
}
示例5: convert
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override
public T convert(ResponseBody value) throws IOException {
Reader reader = value.charStream();
try {
return gson.fromJson(reader, type);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignored) {
}
}
}
}
示例6: convert
import com.squareup.okhttp.ResponseBody; //导入方法依赖的package包/类
@Override public T convert(ResponseBody value) throws IOException {
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
final StringBuilder stringBuilder = new StringBuilder();
try {
inputStreamReader = (InputStreamReader) value.charStream();
bufferedReader = new BufferedReader(inputStreamReader);
String content = null;
while ((content = bufferedReader.readLine()) != null) {
stringBuilder.append(content);
}
} finally {
if (bufferedReader != null) {
bufferedReader.close();
}
if (inputStreamReader != null) {
inputStreamReader.close();
}
}
final String json = stringBuilder.toString();
try {
return gson.fromJson(json.replace("HeWeather data service 3.0", "decor"), type);
}catch (Exception e) {
return null;
}
}