本文整理了Java中com.google.api.client.http.HttpResponse.getContentCharset()
方法的一些代码示例,展示了HttpResponse.getContentCharset()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getContentCharset()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpResponse
类名称:HttpResponse
方法名:getContentCharset
暂无
代码示例来源:origin: com.github.mjeanroy/rest-assert-core
@Override
protected String doGetContent() throws IOException {
try (InputStream is = response.getContent(); ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
copy(is, bos);
return new String(bos.toByteArray(), response.getContentCharset());
}
}
}
代码示例来源:origin: com.google.api-client/google-api-client
private <A, T, E> A getParsedDataClass(
Class<A> dataClass, HttpResponse response, RequestInfo<T, E> requestInfo) throws IOException {
// TODO(yanivi): Remove the HttpResponse reference and directly parse the InputStream
if (dataClass == Void.class) {
return null;
}
return requestInfo.request.getParser().parseAndClose(
response.getContent(), response.getContentCharset(), dataClass);
}
代码示例来源:origin: com.google.api-client/google-api-client
/**
* Parses the given error HTTP response using the given JSON factory.
*
* @param jsonFactory JSON factory
* @param response HTTP response
* @return new instance of the Google JSON error information
* @throws IllegalArgumentException if content type is not {@link Json#MEDIA_TYPE} or if expected
* {@code "data"} or {@code "error"} key is not found
*/
public static GoogleJsonError parse(JsonFactory jsonFactory, HttpResponse response)
throws IOException {
JsonObjectParser jsonObjectParser = new JsonObjectParser.Builder(jsonFactory).setWrapperKeys(
Collections.singleton("error")).build();
return jsonObjectParser.parseAndClose(
response.getContent(), response.getContentCharset(), GoogleJsonError.class);
}
代码示例来源:origin: com.google.api-client/google-api-client
@Override
protected TokenResponse executeRefreshToken() throws IOException {
GenericUrl tokenUrl = new GenericUrl(getTokenServerEncodedUrl());
HttpRequest request = getTransport().createRequestFactory().buildGetRequest(tokenUrl);
JsonObjectParser parser = new JsonObjectParser(getJsonFactory());
request.setParser(parser);
request.getHeaders().set("Metadata-Flavor", "Google");
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();
int statusCode = response.getStatusCode();
if (statusCode == HttpStatusCodes.STATUS_CODE_OK) {
InputStream content = response.getContent();
if (content == null) {
// Throw explicitly rather than allow a later null reference as default mock
// transports return success codes with empty contents.
throw new IOException("Empty content from metadata token server request.");
}
return parser.parseAndClose(content, response.getContentCharset(), TokenResponse.class);
}
if (statusCode == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
throw new IOException(String.format("Error code %s trying to get security access token from"
+ " Compute Engine metadata for the default service account. This may be because"
+ " the virtual machine instance does not have permission scopes specified.",
statusCode));
}
throw new IOException(String.format("Unexpected Error code %s trying to get security access"
+ " token from Compute Engine metadata for the default service account: %s", statusCode,
response.parseAsString()));
}
}
代码示例来源:origin: com.google.cloud.datastore/datastore-v1beta3-proto-client
if (!httpResponse.isSuccessStatusCode()) {
throw makeException(url, methodName, httpResponse.getContent(),
httpResponse.getContentType(), httpResponse.getContentCharset(), null,
httpResponse.getStatusCode());
代码示例来源:origin: GoogleCloudPlatform/google-cloud-datastore
try (InputStream content = GzipFixingInputStream.maybeWrap(httpResponse.getContent())) {
throw makeException(url, methodName, content,
httpResponse.getContentType(), httpResponse.getContentCharset(), null,
httpResponse.getStatusCode());
代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client
try (InputStream content = GzipFixingInputStream.maybeWrap(httpResponse.getContent())) {
throw makeException(url, methodName, content,
httpResponse.getContentType(), httpResponse.getContentCharset(), null,
httpResponse.getStatusCode());
代码示例来源:origin: googleads/googleads-java-lib
"Response contents incorrect",
expectedResponses.get(i).getBody(),
Streams.readAll(response.getContent(), response.getContentCharset()));
assertEquals(
"Location header incorrect on response",
内容来源于网络,如有侵权,请联系作者删除!