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

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

本文整理了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

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

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

/**
   * Tries to read all the content from the HTTP response into a string. If an IO failure occurs while reading content,
   * empty string is returned instead.
   *
   * @param response Response to slurp content for.
   * @return String containing response content, empty string if failure occurs.
   */
  private static String trySlurpContent(HttpResponse response) {
    try {
      return IOUtils.toString(response.getEntity().getContent());
    } catch (IOException e) {
      return "";
    }
  }
}

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

/**
 * Reads a system resource fully into a String
 * 
 * @param location
 *            Relative or absolute location of system resource.
 * @return String contents of resource file
 * @throws RuntimeException
 *             if any error occurs
 */
protected String getResourceAsString(String location) {
  try {
    InputStream resourceStream = getClass().getResourceAsStream(location);
    String resourceAsString = IOUtils.toString(resourceStream);
    resourceStream.close();
    return resourceAsString;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

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

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

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

/**
 * Reads a system resource fully into a String
 * 
 * @param location
 *            Relative or absolute location of system resource.
 * @return String contents of resource file
 * @throws RuntimeException
 *             if any error occurs
 */
protected String getResourceAsString(String location) {
  try {
    InputStream resourceStream = getClass().getResourceAsStream(location);
    String resourceAsString = IOUtils.toString(resourceStream);
    resourceStream.close();
    return resourceAsString;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}

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

private JmesPathExpression getAstFromArgument(String argument, Map<String, JmesPathExpression> argumentToAstMap) throws
                                                            IOException {
  if (argument != null && !argumentToAstMap.containsKey(argument)) {
    final Process p = executeToAstProcess(argument);
    if(p.exitValue()!= 0) {
      throw new RuntimeException(IOUtils.toString(p.getErrorStream()));
    }
    JsonNode jsonNode = mapper.readTree(IOUtils.toString(p.getInputStream()));
    JmesPathExpression ast = fromAstJsonToAstJava(jsonNode);
    argumentToAstMap.put(argument, ast);
    IOUtils.closeQuietly(p.getInputStream(), null);
    return ast;
  } else if (argument != null) {
    return argumentToAstMap.get(argument);
  }
  return null;
}

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

/**
 * Unsubscribes this endpoint from the topic.
 */
public void unsubscribeFromTopic() {
  try {
    HttpGet request = new HttpGet(unsubscribeUrl.toURI());
    HttpResponse response = httpClient.execute(request);
    if (!ApacheUtils.isRequestSuccessful(response)) {
      throw new SdkClientException(String.format("Could not unsubscribe from %s: %d %s.%n%s",
                            getTopicArn(),
                            response.getStatusLine().getStatusCode(),
                            response.getStatusLine().getReasonPhrase(),
                            IOUtils.toString(response.getEntity().getContent())));
    }
  } catch (Exception e) {
    throw new SdkClientException(e);
  }
}

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

/**
 * Downloads the certificate from the provided URL. Asserts that the endpoint is an SNS endpoint and that
 * the certificate is vended over HTTPs.
 *
 * @param certUrl URL to download certificate from.
 * @return String contents of certificate.
 * @throws SdkClientException If certificate cannot be downloaded or URL is invalid.
 */
private String downloadCert(URI certUrl) {
  try {
    signingCertUrlVerifier.verifyCertUrl(certUrl);
    HttpResponse response = client.execute(new HttpGet(certUrl));
    if (ApacheUtils.isRequestSuccessful(response)) {
      try {
        return IOUtils.toString(response.getEntity().getContent());
      } finally {
        response.getEntity().getContent().close();
      }
    } else {
      throw new HttpException("Could not download the certificate from SNS", response);
    }
  } catch (IOException e) {
    throw new SdkClientException("Unable to download SNS certificate from " + certUrl.toString(), e);
  }
}

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

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

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

public GenericApiGatewayResponse(HttpResponse httpResponse) throws IOException {
  this.httpResponse = httpResponse;
  if(httpResponse.getContent() != null) {
    this.body = IOUtils.toString(httpResponse.getContent());
  }else {
    this.body = null;
  }
}

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

private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
    String errorCode = null;

    // Parse the error stream returned from the service.
    if(errorStream != null) {
      String errorResponse = IOUtils.toString(errorStream);

      try {
        JsonNode node = Jackson.jsonNodeOf(errorResponse);
        JsonNode code = node.get("code");
        JsonNode message = node.get("message");
        if (code != null && message != null) {
          errorCode = code.asText();
          responseMessage = message.asText();
        }
      } catch (Exception exception) {
        LOG.debug("Unable to parse error stream");
      }
    }

    AmazonServiceException ase = new AmazonServiceException(responseMessage);
    ase.setStatusCode(statusCode);
    ase.setErrorCode(errorCode);
    throw ase;
  }
}

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

@Override
public String getObjectAsString(String bucketName, String key)
    throws AmazonServiceException, SdkClientException {
  rejectNull(bucketName, "Bucket name must be provided");
  rejectNull(key, "Object key must be provided");
  S3Object object = getObject(bucketName, key);
  try {
    return IOUtils.toString(object.getObjectContent());
  } catch (IOException e) {
    throw new SdkClientException("Error streaming content from S3 during download");
  } finally {
    IOUtils.closeQuietly(object, log);
  }
}

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

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

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

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

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

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

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

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

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

@Override
  public String unmarshall(InputStream in) throws Exception {
    assertEquals("content", IOUtils.toString(in));
    handleCalled.add(true);
    return null;
  }
});

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

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

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

@Test
public void testZeroByteStream() throws Exception {
  String s = IOUtils.toString(new InputStream() {
    @Override
    public int read() throws IOException {
      return -1;
    }
  });
  assertEquals("", s);
}

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

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

相关文章