本文整理了Java中retrofit.client.Response.getBody
方法的一些代码示例,展示了Response.getBody
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getBody
方法的具体详情如下:
包路径:retrofit.client.Response
类名称:Response
方法名:getBody
[英]Response body. May be null.
[中]响应机构。可能为空。
代码示例来源:origin: chiclaim/AndroidRxJavaSample
@Override
public void call(Response response) {
String content = new String(((TypedByteArray) response.getBody()).getBytes());
printLog(tvLogs, "", content);
}
}, new Action1<Throwable>() {
代码示例来源:origin: chiclaim/AndroidRxJavaSample
@Override
public void call(Response response) {
String content = new String(((TypedByteArray) response.getBody()).getBytes());
tvContent.setText("receiver data : " + content);
}
}, new Action1<Throwable>() {
代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-appengine
public static String responseToString(Response response) {
return new String(((TypedByteArray) response.getBody()).getBytes());
}
}
代码示例来源:origin: com.hp.autonomy.hod/java-hod-client
private <T> T parseTokenInformation(final Response response, final TypeReference<TokenResponse<T>> typeReference) {
try {
final TokenResponse<T> tokenResponse = objectMapper.readValue(response.getBody().in(), typeReference);
return tokenResponse.getToken();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
代码示例来源:origin: com.netflix.spinnaker.orca/orca-clouddriver
private Map<String, Object> fetchCluster(String application,
String credentials,
String cluster,
String cloudProvider) {
try {
Response response = oortService.getCluster(application, credentials, cluster, cloudProvider);
return (Map<String, Object>) objectMapper.readValue(response.getBody().in(), Map.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.netflix.spinnaker.orca/orca-clouddriver
private Map<String, Object> fetchServerGroup(String account,
String region,
String serverGroup) {
try {
Response response = oortService.getServerGroup(account, region, serverGroup);
return (Map<String, Object>) objectMapper.readValue(response.getBody().in(), Map.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: io.divide/client-java
private static <T> T convertBody(Class<T> typeClass, Response response){
String body = null;
try {
body = IOUtils.toString(response.getBody().in());
} catch (IOException e) {
e.printStackTrace();
}
return gson.fromJson(body,typeClass);
}
}
代码示例来源:origin: whilu/TPShareLogin
@Override
public void onNext(Response response) {
String jsonStr = new String(((TypedByteArray) response.getBody()).getBytes());
// 返回格式如下
/*{
"user_data":{},
"verify_data":{} \"
}*/
mListener.onComplete("{\"user_data\":" + jsonStr + "," + "\"verify_data\":" + verifyData + "}");
}
}
代码示例来源:origin: whilu/TPShareLogin
@Override
public void onNext(Response response) {
try {
String jsonStr = new String(((TypedByteArray) response.getBody()).getBytes());
JSONObject jsonObject = new JSONObject(jsonStr);
String accesstoken = jsonObject.getString("access_token");
String openid = jsonObject.getString("openid");
getUserInfo(mRestAdapter, accesstoken, openid, jsonStr);
} catch (JSONException e) {
e.printStackTrace();
mListener.onError(e.toString());
}
}
}
代码示例来源:origin: com.hp.autonomy.hod/java-hod-client
/**
* Checks the response headers for a refreshed authentication token then returns the response body as an input stream.
* @param tokenProxy The token proxy to update in the token repository if required
* @param response The response to read
* @return The response body as an input stream
*/
InputStream parseResponse(final TokenProxy<?, ?> tokenProxy, final Response response) {
checkRefresh(tokenProxy, response);
try {
return response.getBody().in();
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: com.hp.autonomy.hod/java-hod-client
private <E extends EntityType, T extends TokenType> AuthenticationToken<E, T> parseToken(final Response response, final E entityType, final T tokenType) {
try {
final TokenResponse<AuthenticationToken.Json> tokenResponse = objectMapper.readValue(response.getBody().in(), TOKEN_TYPE_REFERENCE);
return tokenResponse.getToken().buildToken(entityType, tokenType);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: io.divide/client-java
private <B extends TransientObject> Collection<B> convertRequest(Class<B[]> type, Response response){
String body = null;
try {
body = IOUtils.toString(response.getBody().in());
} catch (IOException e) {
e.printStackTrace();
}
B[] t = gson.fromJson(body,type);
return ObjectUtils.v2c(t);
}
代码示例来源:origin: com.netflix.spinnaker.rosco/rosco-manifests
protected Path downloadArtifactToTmpFile(BakeManifestEnvironment env, Artifact artifact) throws IOException {
Path path = Paths.get(env.getStagingPath().toString(), nameFromReference(artifact.getReference()));
OutputStream outputStream = new FileOutputStream(path.toString());
Response response = retrySupport.retry(() -> clouddriverService.fetchArtifact(artifact), 5, 1000, true);
InputStream inputStream = response.getBody().in();
IOUtils.copy(inputStream, outputStream);
inputStream.close();
outputStream.close();
return path;
}
代码示例来源:origin: io.brooklyn.ambari/brooklyn-ambari
public AmbariApiException(RetrofitError retrofitError) {
super(MessageFormat.format(ERROR_MESSAGE, retrofitError.getResponse().getStatus(), retrofitError.getUrl(), new String(((TypedByteArray) retrofitError.getResponse().getBody()).getBytes())));
}
}
代码示例来源:origin: braintree/braintree-android-drop-in
@Override
public void failure(RetrofitError error) {
setStatus(R.string.transaction_failed);
setMessage("Unable to create a transaction. Response Code: " +
error.getResponse().getStatus() + " Response body: " +
error.getResponse().getBody());
}
};
代码示例来源:origin: braintree/braintree_android
@Override
public void failure(RetrofitError error) {
setStatus(R.string.transaction_failed);
setMessage("Unable to create a transaction. Response Code: " +
error.getResponse().getStatus() + " Response body: " +
error.getResponse().getBody());
}
};
代码示例来源:origin: lytsing/weibo
public static int readErrorCode(RetrofitError retrofitError) {
if ((retrofitError == null) || (retrofitError.getResponse() == null)
|| (retrofitError.getResponse().getBody() == null)) {
return 0;
}
byte[] responseBytes = ((TypedByteArray) retrofitError.getResponse().getBody()).getBytes();
if (responseBytes == null)
return 0;
try {
String response = new String(responseBytes, "UTF-8");
return parseErrorCode(response);
} catch (UnsupportedEncodingException e) {
VolleyLog.e("Twitter", "Failed to convert to string", e);
}
return 0;
}
代码示例来源:origin: particle-iot/spark-sdk-android
private ResponseErrorData buildResponseData(RetrofitError error) {
if (error.getResponse() == null) {
return null;
}
InputStream in = null;
if (error.getResponse().getBody() != null) {
try {
in = error.getResponse().getBody().in();
} catch (IOException e) {
// Yo, dawg, I heard you like error handling in your error handling...
}
}
return new ResponseErrorData(error.getResponse().getStatus(), in);
}
代码示例来源:origin: braintree/braintree-android-drop-in
@Override
public void failure(RetrofitError error) {
showDialog("Unable to get a client token. Response Code: " +
error.getResponse().getStatus() + " Response body: " +
error.getResponse().getBody());
}
});
代码示例来源:origin: braintree/braintree_android
@Override
public void failure(RetrofitError error) {
setProgressBarIndeterminateVisibility(false);
if (error.getResponse() == null) {
showDialog(error.getCause().getMessage());
} else {
showDialog("Unable to get a client token. Response Code: " +
error.getResponse().getStatus() + " Response body: " +
error.getResponse().getBody());
}
}
});
内容来源于网络,如有侵权,请联系作者删除!