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


Java ResponseBody.charStream方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:auth0,項目名稱:Auth0.Android,代碼行數:20,代碼來源:SimpleRequest.java

示例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();
  }
}
 
開發者ID:john1jan,項目名稱:ReactNativeSignatureExample,代碼行數:28,代碼來源:NetworkingModule.java

示例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();
  }
}
 
開發者ID:ManrajGrover,項目名稱:react-native-box-loaders,代碼行數:16,代碼來源:NetworkingModule.java

示例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) {
            }
        }
    }
}
 
開發者ID:mattermost,項目名稱:mattermost-android-classic,代碼行數:15,代碼來源:JacksonConverterFactory.java

示例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) {

            }
        }
    }
}
 
開發者ID:linhaosheng,項目名稱:ZhihuDailyRRD,代碼行數:16,代碼來源:GsonConverterFactory.java

示例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;
        }
    }
 
開發者ID:ChanJLee,項目名稱:YunShuWeather,代碼行數:33,代碼來源:WeatherResponseConverter.java


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