software.amazon.awssdk.utils.IoUtils.toUtf8String()方法的使用及代码示例

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

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

IoUtils.toUtf8String介绍

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

代码示例

代码示例来源:origin: software.amazon.awssdk/protocol-tests-core

  1. @Override
  2. public Void transform(Object response, AbortableInputStream inputStream) throws Exception {
  3. this.captured = IoUtils.toUtf8String(inputStream);
  4. return null;
  5. }

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

  1. @Override
  2. public Void transform(Object response, AbortableInputStream inputStream) throws Exception {
  3. this.captured = IoUtils.toUtf8String(inputStream);
  4. return null;
  5. }

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

  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(Class<?> clazz, String location) {
  11. try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
  12. return IoUtils.toUtf8String(resourceStream);
  13. } catch (IOException e) {
  14. throw new RuntimeException(e);
  15. }
  16. }

代码示例来源:origin: software.amazon.awssdk/service-test-utils

  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(Class<?> clazz, String location) {
  11. try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
  12. return IoUtils.toUtf8String(resourceStream);
  13. } catch (IOException e) {
  14. throw new RuntimeException(e);
  15. }
  16. }

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

  1. private String loadDefaultFileHeader() throws IOException {
  2. try (InputStream inputStream = getClass()
  3. .getResourceAsStream("/software/amazon/awssdk/codegen/DefaultFileHeader.txt")) {
  4. return IoUtils.toUtf8String(inputStream)
  5. .replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
  6. }
  7. }

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

  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(Class<?> clazz, String location) {
  11. try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
  12. String resourceAsString = IoUtils.toUtf8String(resourceStream);
  13. resourceStream.close();
  14. return resourceAsString;
  15. } catch (IOException e) {
  16. throw new RuntimeException(e);
  17. }
  18. }

代码示例来源:origin: software.amazon.awssdk/service-test-utils

  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(Class<?> clazz, String location) {
  11. try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
  12. String resourceAsString = IoUtils.toUtf8String(resourceStream);
  13. resourceStream.close();
  14. return resourceAsString;
  15. } catch (IOException e) {
  16. throw new RuntimeException(e);
  17. }
  18. }

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

  1. private String loadDefaultFileHeader() throws IOException {
  2. try (InputStream inputStream = getClass()
  3. .getResourceAsStream("/software/amazon/awssdk/codegen/lite/DefaultFileHeader.txt")) {
  4. return IoUtils.toUtf8String(inputStream)
  5. .replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
  6. }
  7. }

代码示例来源:origin: software.amazon.awssdk/codegen

  1. private String loadDefaultFileHeader() throws IOException {
  2. try (InputStream inputStream = getClass()
  3. .getResourceAsStream("/software/amazon/awssdk/codegen/DefaultFileHeader.txt")) {
  4. return IoUtils.toUtf8String(inputStream)
  5. .replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
  6. }
  7. }

代码示例来源:origin: software.amazon.awssdk/codegen-lite

  1. private String loadDefaultFileHeader() throws IOException {
  2. try (InputStream inputStream = getClass()
  3. .getResourceAsStream("/software/amazon/awssdk/codegen/lite/DefaultFileHeader.txt")) {
  4. return IoUtils.toUtf8String(inputStream)
  5. .replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
  6. }
  7. }

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

  1. private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
  2. // Parse the error stream returned from the service.
  3. if (errorStream != null) {
  4. String errorResponse = IoUtils.toUtf8String(errorStream);
  5. try {
  6. JsonNode node = JacksonUtils.jsonNodeOf(errorResponse);
  7. JsonNode code = node.get("code");
  8. JsonNode message = node.get("message");
  9. if (code != null && message != null) {
  10. responseMessage = message.asText();
  11. }
  12. } catch (RuntimeException exception) {
  13. log.debug("Unable to parse error stream", exception);
  14. }
  15. }
  16. SdkServiceException exception = SdkServiceException.builder()
  17. .message(responseMessage)
  18. .statusCode(statusCode)
  19. .build();
  20. throw exception;
  21. }
  22. }

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

  1. @Override
  2. public Optional<InputStream> modifyHttpResponseContent(Context.ModifyHttpResponse context,
  3. ExecutionAttributes executionAttributes) {
  4. if (context.request() instanceof GetBucketPolicyRequest) {
  5. String policy = context.responseBody() == null ? null : invokeSafely(
  6. () -> IoUtils.toUtf8String(context.responseBody().get()));
  7. // Wrap in CDATA to deal with any escaping issues
  8. String xml = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  9. + "<Policy><![CDATA[%s]]></Policy>", policy);
  10. return Optional.of(AbortableInputStream.create(new StringInputStream(xml)));
  11. }
  12. return context.responseBody();
  13. }
  14. }

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

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

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

  1. private void validateResponse(HttpExecuteResponse response, int returnCode, SdkHttpMethod method) throws IOException {
  2. RequestMethod requestMethod = RequestMethod.fromString(method.name());
  3. RequestPatternBuilder patternBuilder = RequestPatternBuilder.newRequestPattern(requestMethod, urlMatching("/"))
  4. .withHeader("Host", containing("localhost"))
  5. .withHeader("User-Agent", equalTo("hello-world!"));
  6. if (method == SdkHttpMethod.HEAD) {
  7. patternBuilder.withRequestBody(equalTo(""));
  8. } else {
  9. patternBuilder.withRequestBody(equalTo("Body"));
  10. }
  11. verify(1, patternBuilder);
  12. if (method == SdkHttpMethod.HEAD) {
  13. assertThat(response.responseBody()).isEmpty();
  14. } else {
  15. assertThat(IoUtils.toUtf8String(response.responseBody().orElse(null))).isEqualTo("hello");
  16. }
  17. assertThat(response.httpResponse().firstMatchingHeader("Some-Header")).contains("With Value");
  18. assertThat(response.httpResponse().statusCode()).isEqualTo(returnCode);
  19. mockServer.resetMappings();
  20. }

代码示例来源:origin: otto-de/edison-microservice

  1. @Test
  2. public void getObjectShouldReturnStreamWithData() throws Exception {
  3. // given
  4. testee.putObject(PutObjectRequest.builder()
  5. .bucket("someBucket")
  6. .key("someKey")
  7. .build(),
  8. RequestBody.fromString("testdata"));
  9. //when
  10. ResponseInputStream<GetObjectResponse> inputStream = testee.getObject(GetObjectRequest.builder()
  11. .bucket("someBucket")
  12. .key("someKey")
  13. .build());
  14. //then
  15. String data = IoUtils.toUtf8String(inputStream);
  16. assertThat(data, is("testdata"));
  17. }

相关文章