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