当前位置: 首页>>代码示例>>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;未经允许,请勿转载。