本文整理了Java中com.google.api.client.http.HttpResponse.getContent()
方法的一些代码示例,展示了HttpResponse.getContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.getContent()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpResponse
类名称:HttpResponse
方法名:getContent
暂无
代码示例来源:origin: GoogleContainerTools/jib
/**
* @return the HTTP response body as a {@link Blob}.
* @throws IOException if getting the HTTP response content fails.
*/
public Blob getBody() throws IOException {
return Blobs.from(httpResponse.getContent());
}
代码示例来源: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: google/data-transfer-project
static <T> T makePostRequest(HttpTransport httpTransport, String url, HttpContent httpContent,
Class<T> clazz) throws IOException {
HttpRequestFactory factory = httpTransport.createRequestFactory();
HttpRequest postRequest = factory.buildPostRequest(new GenericUrl(url), httpContent);
HttpResponse response = postRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams
.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return new ObjectMapper().readValue(result, clazz);
}
}
代码示例来源: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: google/data-transfer-project
private <T> T makeGetRequest(String url, Optional<Map<String, String>> parameters, Class<T> clazz)
throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest getRequest = requestFactory
.buildGetRequest(new GenericUrl(url + "?" + generateParamsString(parameters)));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams
.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return objectMapper.readValue(result, clazz);
}
代码示例来源:origin: google/data-transfer-project
private String getToken(String frob) throws IOException {
URL signedUrl =
signatureGenerator.getSignature(
GET_TOKEN_URL, ImmutableMap.of("frob", frob, "method", GET_TOKEN_METHOD));
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
HttpRequest getRequest = requestFactory.buildGetRequest(new GenericUrl(signedUrl));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
AuthElement authElement = xmlMapper.readValue(response.getContent(), AuthElement.class);
Preconditions.checkState(authElement.stat.equals("ok"), "state must be ok: %s", authElement);
Preconditions.checkState(
!Strings.isNullOrEmpty(authElement.auth.token), "token must not be empty", authElement);
return authElement.auth.token;
}
}
代码示例来源:origin: google/data-transfer-project
private <T> T makeRequest(String url, Class<T> clazz, TokensAndUrlAuthData authData)
throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest getRequest =
requestFactory.buildGetRequest(
new GenericUrl(url + "?access_token=" + authData.getAccessToken()));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result =
CharStreams.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
return objectMapper.readValue(result, clazz);
}
}
代码示例来源:origin: google/data-transfer-project
<T> T makePostRequest(String url, Optional<Map<String, String>> parameters,
HttpContent httpContent, Class<T> clazz)
throws IOException {
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest postRequest = requestFactory
.buildPostRequest(new GenericUrl(url + "?" + generateParamsString(parameters)),
httpContent);
HttpResponse response = postRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
String result = CharStreams
.toString(new InputStreamReader(response.getContent(), Charsets.UTF_8));
if (clazz.isAssignableFrom(String.class)) {
return (T) result;
} else {
return objectMapper.readValue(result, clazz);
}
}
代码示例来源:origin: google/data-transfer-project
private String requestRaw(String path) throws IOException {
HttpRequest getRequest = TRANSPORT.createRequestFactory().buildGetRequest(
new GenericUrl(baseUrl + path));
HttpHeaders headers = new HttpHeaders();
headers.setAuthorization("Bearer " + accessToken);
getRequest.setHeaders(headers);
HttpResponse response = getRequest.execute();
validateResponse(getRequest, response, 200);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
IOUtils.copy(response.getContent(), byteArrayOutputStream, true);
return byteArrayOutputStream.toString();
}
代码示例来源:origin: google/data-transfer-project
private <T extends RememberTheMilkResponse> T makeRequest(
Map<String, String> parameters, Class<T> dataClass) throws IOException {
URL signedUrl = signatureGenerator.getSignature(BASE_URL, parameters);
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
HttpRequest getRequest = requestFactory.buildGetRequest(new GenericUrl(signedUrl));
HttpResponse response = getRequest.execute();
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(
"Bad status code: " + statusCode + " error: " + response.getStatusMessage());
}
T parsedResponse = xmlMapper.readValue(response.getContent(), dataClass);
if (parsedResponse.error != null) {
throw new IOException(
"Error making call to " + signedUrl + " error: " + parsedResponse.error);
}
return parsedResponse;
}
代码示例来源:origin: google/data-transfer-project
/**
* Parses the contents of a URL to produce an RDF model.
*/
public Model getModel(String url) throws IOException {
HttpRequestFactory factory = TRANSPORT.createRequestFactory();
HttpRequest rootGetRequest = factory.buildGetRequest(
new GenericUrl(url));
HttpHeaders headers = new HttpHeaders();
headers.setCookie(authCookie);
headers.setAccept("text/turtle");
rootGetRequest.setHeaders(headers);
HttpResponse response = rootGetRequest.execute();
if (response.getStatusCode() != 200) {
throw new IOException("Unexpected return code: "
+ response.getStatusCode()
+ "\nMessage:\n"
+ response.getStatusMessage());
}
StringWriter writer = new StringWriter();
IOUtils.copy(response.getContent(), writer, "UTF-8");
String fixedString = fixProblematicPeriods(writer.toString());
Model defaultModel = ModelFactory.createDefaultModel();
return defaultModel.read(
new StringReader(fixedString),
url,
"TURTLE");
}
代码示例来源:origin: google/data-transfer-project
.export(file.getId(), newMimeType)
.executeMedia()
.getContent();
} else {
inputStream =
.setAlt("media")
.executeMedia()
.getContent();
代码示例来源:origin: google/google-api-java-client-samples
new InputStreamReader(fileContents.getContent(), Charsets.UTF_8));
String line;
while ((line = reader.readLine()) != null) {
代码示例来源:origin: gradle.plugin.com.google.cloud.tools/jib-gradle-plugin
/**
* @return the HTTP response body as a {@link Blob}.
* @throws IOException if getting the HTTP response content fails.
*/
public Blob getBody() throws IOException {
return Blobs.from(httpResponse.getContent());
}
代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.rt.server.commons
/**
* Writes the response payload of forwarded request to the servlet response.
*/
protected void writeResponsePayload(HttpServletResponse resp, HttpResponse httpResp) throws IOException {
try (InputStream in = httpResp.getContent()) {
writeResponsePayload(resp, in);
}
}
代码示例来源:origin: com.onpositive.aml/org.aml.registry
public static void readToFile(String url,File target) throws IOException {
HttpRequest buildGetRequest;
buildGetRequest = createRequestFactory.buildGetRequest(new GenericUrl(url));
InputStream str=buildGetRequest.execute().getContent();
FileUtils.copyInputStreamToFile(str, target);
}
代码示例来源:origin: com.splout.db/splout-javaclient
public DeployInfo deploy(final DeployRequest... requests) throws IOException {
try {
String strCont = JSONSerDe.ser(new ArrayList<DeployRequest>(Arrays.asList(requests)));
HttpContent content = new StringHttpContent(strCont);
HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(
qNodes[(int) (Math.random() * qNodes.length)] + "/api/deploy"), content);
HttpResponse resp = request.execute();
return JSONSerDe.deSer(asString(resp.getContent()), DeployInfo.class);
} catch(JSONSerDeException e) {
throw new IOException(e);
}
}
代码示例来源:origin: com.splout.db/splout-javaclient
public Tablespace tablespace(String tablespace) throws IOException {
HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(
qNodes[(int) (Math.random() * qNodes.length)] + "/api/tablespace/" + tablespace));
HttpResponse resp = request.execute();
try {
return JSONSerDe.deSer(asString(resp.getContent()), Tablespace.class);
} catch(JSONSerDeException e) {
throw new IOException(e);
}
}
代码示例来源:origin: com.splout.db/splout-javaclient
@SuppressWarnings("unchecked")
public List<String> dNodeList() throws IOException {
HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(
qNodes[(int) (Math.random() * qNodes.length)] + "/api/dnodelist"));
HttpResponse resp = request.execute();
try {
return JSONSerDe.deSer(asString(resp.getContent()), ArrayList.class);
} catch(JSONSerDeException e) {
throw new IOException(e);
}
}
代码示例来源:origin: googleglass/mirror-quickstart-java
public static InputStream getAttachmentInputStream(Credential credential, String timelineItemId,
String attachmentId) throws IOException {
Mirror mirrorService = getMirror(credential);
Mirror.Timeline.Attachments attachments = mirrorService.timeline().attachments();
Attachment attachmentMetadata = attachments.get(timelineItemId, attachmentId).execute();
HttpResponse resp =
mirrorService.getRequestFactory()
.buildGetRequest(new GenericUrl(attachmentMetadata.getContentUrl())).execute();
return resp.getContent();
}
内容来源于网络,如有侵权,请联系作者删除!