com.amazonaws.util.IOUtils.toString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(265)

本文整理了Java中com.amazonaws.util.IOUtils.toString()方法的一些代码示例,展示了IOUtils.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.toString()方法的具体详情如下:
包路径:com.amazonaws.util.IOUtils
类名称:IOUtils
方法名:toString

IOUtils.toString介绍

[英]Reads and returns the rest of the given input stream as a string. Caller is responsible for closing the given input stream.
[中]读取并以字符串形式返回给定输入流的其余部分。调用者负责关闭给定的输入流。

代码示例

代码示例来源:origin: aws/aws-sdk-java

  1. private String contentToString(InputStream content, String idString) throws Exception {
  2. try {
  3. return IOUtils.toString(content);
  4. } catch (Exception e) {
  5. log.debug(String.format("Unable to read input stream to string (%s)", idString), e);
  6. throw e;
  7. }
  8. }

代码示例来源:origin: aws/aws-sdk-java

  1. /**
  2. * Tries to read all the content from the HTTP response into a string. If an IO failure occurs while reading content,
  3. * empty string is returned instead.
  4. *
  5. * @param response Response to slurp content for.
  6. * @return String containing response content, empty string if failure occurs.
  7. */
  8. private static String trySlurpContent(HttpResponse response) {
  9. try {
  10. return IOUtils.toString(response.getEntity().getContent());
  11. } catch (IOException e) {
  12. return "";
  13. }
  14. }
  15. }

代码示例来源:origin: aws/aws-sdk-java

  1. /**
  2. * Reads a system resource fully into a String
  3. *
  4. * @param location
  5. * Relative or absolute location of system resource.
  6. * @return String contents of resource file
  7. * @throws RuntimeException
  8. * if any error occurs
  9. */
  10. protected String getResourceAsString(String location) {
  11. try {
  12. InputStream resourceStream = getClass().getResourceAsStream(location);
  13. String resourceAsString = IOUtils.toString(resourceStream);
  14. resourceStream.close();
  15. return resourceAsString;
  16. } catch (Exception e) {
  17. throw new RuntimeException(e);
  18. }
  19. }

代码示例来源:origin: aws/aws-sdk-java

  1. private String loadDeafultFileHeader() throws IOException {
  2. try (InputStream inputStream = getClass()
  3. .getResourceAsStream("/com/amazonaws/codegen/DefaultFileHeader.txt")) {
  4. return IOUtils.toString(inputStream)
  5. .replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
  6. }
  7. }

代码示例来源:origin: aws/aws-sdk-java

  1. /**
  2. * Reads a system resource fully into a String
  3. *
  4. * @param location
  5. * Relative or absolute location of system resource.
  6. * @return String contents of resource file
  7. * @throws RuntimeException
  8. * if any error occurs
  9. */
  10. protected String getResourceAsString(String location) {
  11. try {
  12. InputStream resourceStream = getClass().getResourceAsStream(location);
  13. String resourceAsString = IOUtils.toString(resourceStream);
  14. resourceStream.close();
  15. return resourceAsString;
  16. } catch (Exception e) {
  17. throw new RuntimeException(e);
  18. }
  19. }

代码示例来源:origin: aws/aws-sdk-java

  1. private JmesPathExpression getAstFromArgument(String argument, Map<String, JmesPathExpression> argumentToAstMap) throws
  2. IOException {
  3. if (argument != null && !argumentToAstMap.containsKey(argument)) {
  4. final Process p = executeToAstProcess(argument);
  5. if(p.exitValue()!= 0) {
  6. throw new RuntimeException(IOUtils.toString(p.getErrorStream()));
  7. }
  8. JsonNode jsonNode = mapper.readTree(IOUtils.toString(p.getInputStream()));
  9. JmesPathExpression ast = fromAstJsonToAstJava(jsonNode);
  10. argumentToAstMap.put(argument, ast);
  11. IOUtils.closeQuietly(p.getInputStream(), null);
  12. return ast;
  13. } else if (argument != null) {
  14. return argumentToAstMap.get(argument);
  15. }
  16. return null;
  17. }

代码示例来源:origin: aws/aws-sdk-java

  1. /**
  2. * Unsubscribes this endpoint from the topic.
  3. */
  4. public void unsubscribeFromTopic() {
  5. try {
  6. HttpGet request = new HttpGet(unsubscribeUrl.toURI());
  7. HttpResponse response = httpClient.execute(request);
  8. if (!ApacheUtils.isRequestSuccessful(response)) {
  9. throw new SdkClientException(String.format("Could not unsubscribe from %s: %d %s.%n%s",
  10. getTopicArn(),
  11. response.getStatusLine().getStatusCode(),
  12. response.getStatusLine().getReasonPhrase(),
  13. IOUtils.toString(response.getEntity().getContent())));
  14. }
  15. } catch (Exception e) {
  16. throw new SdkClientException(e);
  17. }
  18. }

代码示例来源:origin: aws/aws-sdk-java

  1. /**
  2. * Downloads the certificate from the provided URL. Asserts that the endpoint is an SNS endpoint and that
  3. * the certificate is vended over HTTPs.
  4. *
  5. * @param certUrl URL to download certificate from.
  6. * @return String contents of certificate.
  7. * @throws SdkClientException If certificate cannot be downloaded or URL is invalid.
  8. */
  9. private String downloadCert(URI certUrl) {
  10. try {
  11. signingCertUrlVerifier.verifyCertUrl(certUrl);
  12. HttpResponse response = client.execute(new HttpGet(certUrl));
  13. if (ApacheUtils.isRequestSuccessful(response)) {
  14. try {
  15. return IOUtils.toString(response.getEntity().getContent());
  16. } finally {
  17. response.getEntity().getContent().close();
  18. }
  19. } else {
  20. throw new HttpException("Could not download the certificate from SNS", response);
  21. }
  22. } catch (IOException e) {
  23. throw new SdkClientException("Unable to download SNS certificate from " + certUrl.toString(), e);
  24. }
  25. }

代码示例来源:origin: Netflix/conductor

  1. /**
  2. * Download the payload from the given path
  3. *
  4. * @param path the relative path of the payload in the {@link ExternalPayloadStorage}
  5. * @return the payload object
  6. * @throws ApplicationException in case of JSON parsing errors or download errors
  7. */
  8. @SuppressWarnings("unchecked")
  9. public Map<String, Object> downloadPayload(String path) {
  10. try (InputStream inputStream = externalPayloadStorage.download(path)) {
  11. return objectMapper.readValue(IOUtils.toString(inputStream), Map.class);
  12. } catch (IOException e) {
  13. logger.error("Unable to download payload from external storage path: {}", path, e);
  14. throw new ApplicationException(ApplicationException.Code.INTERNAL_ERROR, e);
  15. }
  16. }

代码示例来源:origin: apache/nifi

  1. public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException {
  2. this.httpResponse = httpResponse;
  3. if(httpResponse.getContent() != null) {
  4. this.body = IOUtils.toString(httpResponse.getContent());
  5. }else {
  6. this.body = null;
  7. }
  8. }

代码示例来源:origin: aws/aws-sdk-java

  1. private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
  2. String errorCode = null;
  3. // Parse the error stream returned from the service.
  4. if(errorStream != null) {
  5. String errorResponse = IOUtils.toString(errorStream);
  6. try {
  7. JsonNode node = Jackson.jsonNodeOf(errorResponse);
  8. JsonNode code = node.get("code");
  9. JsonNode message = node.get("message");
  10. if (code != null && message != null) {
  11. errorCode = code.asText();
  12. responseMessage = message.asText();
  13. }
  14. } catch (Exception exception) {
  15. LOG.debug("Unable to parse error stream");
  16. }
  17. }
  18. AmazonServiceException ase = new AmazonServiceException(responseMessage);
  19. ase.setStatusCode(statusCode);
  20. ase.setErrorCode(errorCode);
  21. throw ase;
  22. }
  23. }

代码示例来源:origin: aws/aws-sdk-java

  1. @Override
  2. public String getObjectAsString(String bucketName, String key)
  3. throws AmazonServiceException, SdkClientException {
  4. rejectNull(bucketName, "Bucket name must be provided");
  5. rejectNull(key, "Object key must be provided");
  6. S3Object object = getObject(bucketName, key);
  7. try {
  8. return IOUtils.toString(object.getObjectContent());
  9. } catch (IOException e) {
  10. throw new SdkClientException("Error streaming content from S3 during download");
  11. } finally {
  12. IOUtils.closeQuietly(object, log);
  13. }
  14. }

代码示例来源:origin: aws/aws-sdk-java

  1. return IOUtils.toString(inputStream);
  2. } else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {

代码示例来源:origin: aws/aws-sdk-java

  1. content = IOUtils.toString(is);
  2. } catch (IOException ioe) {
  3. if (log.isDebugEnabled())

代码示例来源:origin: Netflix/conductor

  1. Response response = restClient.performRequest(HttpMethod.GET, resourcePath);
  2. String responseBody = IOUtils.toString(response.getEntity().getContent());
  3. logger.info("responseBody: {}", responseBody);

代码示例来源:origin: Netflix/conductor

  1. Response response = restClient.performRequest(HttpMethod.GET, resourcePath);
  2. String responseBody = IOUtils.toString(response.getEntity().getContent());
  3. TypeReference<HashMap<String, Object>> typeRef =
  4. new TypeReference<HashMap<String, Object>>() {

代码示例来源:origin: aws-amplify/aws-sdk-android

  1. @Override
  2. public String unmarshall(InputStream in) throws Exception {
  3. assertEquals("content", IOUtils.toString(in));
  4. handleCalled.add(true);
  5. return null;
  6. }
  7. });

代码示例来源:origin: aws-amplify/aws-sdk-android

  1. @Test
  2. public void test() throws Exception {
  3. String s = IOUtils.toString(new ByteArrayInputStream("Testing".getBytes(StringUtils.UTF8)));
  4. assertEquals("Testing", s);
  5. }
  6. }

代码示例来源:origin: aws-amplify/aws-sdk-android

  1. @Test
  2. public void testZeroByteStream() throws Exception {
  3. String s = IOUtils.toString(new InputStream() {
  4. @Override
  5. public int read() throws IOException {
  6. return -1;
  7. }
  8. });
  9. assertEquals("", s);
  10. }

代码示例来源:origin: aws-amplify/aws-sdk-android

  1. @Test
  2. public void testContentEncodingIdentity() throws Exception {
  3. builder = HttpResponse.builder()
  4. .header("Content-Encoding", "identity")
  5. .content(content);
  6. response = builder.build();
  7. assertFalse("Not gzip", response.getContent() instanceof GZIPInputStream);
  8. assertEquals("same content", "content", IOUtils.toString(response.getContent()));
  9. }

相关文章