本文整理了Java中software.amazon.awssdk.utils.IoUtils.toUtf8String()
方法的一些代码示例,展示了IoUtils.toUtf8String()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtils.toUtf8String()
方法的具体详情如下:
包路径:software.amazon.awssdk.utils.IoUtils
类名称: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
@Override
public Void transform(Object response, AbortableInputStream inputStream) throws Exception {
this.captured = IoUtils.toUtf8String(inputStream);
return null;
}
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public Void transform(Object response, AbortableInputStream inputStream) throws Exception {
this.captured = IoUtils.toUtf8String(inputStream);
return null;
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* 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(Class<?> clazz, String location) {
try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
return IoUtils.toUtf8String(resourceStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: software.amazon.awssdk/service-test-utils
/**
* 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(Class<?> clazz, String location) {
try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
return IoUtils.toUtf8String(resourceStream);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
private String loadDefaultFileHeader() throws IOException {
try (InputStream inputStream = getClass()
.getResourceAsStream("/software/amazon/awssdk/codegen/DefaultFileHeader.txt")) {
return IoUtils.toUtf8String(inputStream)
.replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* 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(Class<?> clazz, String location) {
try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
String resourceAsString = IoUtils.toUtf8String(resourceStream);
resourceStream.close();
return resourceAsString;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: software.amazon.awssdk/service-test-utils
/**
* 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(Class<?> clazz, String location) {
try (InputStream resourceStream = clazz.getResourceAsStream(location)) {
String resourceAsString = IoUtils.toUtf8String(resourceStream);
resourceStream.close();
return resourceAsString;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
private String loadDefaultFileHeader() throws IOException {
try (InputStream inputStream = getClass()
.getResourceAsStream("/software/amazon/awssdk/codegen/lite/DefaultFileHeader.txt")) {
return IoUtils.toUtf8String(inputStream)
.replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
}
}
代码示例来源:origin: software.amazon.awssdk/codegen
private String loadDefaultFileHeader() throws IOException {
try (InputStream inputStream = getClass()
.getResourceAsStream("/software/amazon/awssdk/codegen/DefaultFileHeader.txt")) {
return IoUtils.toUtf8String(inputStream)
.replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
}
}
代码示例来源:origin: software.amazon.awssdk/codegen-lite
private String loadDefaultFileHeader() throws IOException {
try (InputStream inputStream = getClass()
.getResourceAsStream("/software/amazon/awssdk/codegen/lite/DefaultFileHeader.txt")) {
return IoUtils.toUtf8String(inputStream)
.replaceFirst("%COPYRIGHT_DATE_RANGE%", getCopyrightDateRange());
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
private void handleErrorResponse(InputStream errorStream, int statusCode, String responseMessage) throws IOException {
// Parse the error stream returned from the service.
if (errorStream != null) {
String errorResponse = IoUtils.toUtf8String(errorStream);
try {
JsonNode node = JacksonUtils.jsonNodeOf(errorResponse);
JsonNode code = node.get("code");
JsonNode message = node.get("message");
if (code != null && message != null) {
responseMessage = message.asText();
}
} catch (RuntimeException exception) {
log.debug("Unable to parse error stream", exception);
}
}
SdkServiceException exception = SdkServiceException.builder()
.message(responseMessage)
.statusCode(statusCode)
.build();
throw exception;
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public Optional<InputStream> modifyHttpResponseContent(Context.ModifyHttpResponse context,
ExecutionAttributes executionAttributes) {
if (context.request() instanceof GetBucketPolicyRequest) {
String policy = context.responseBody() == null ? null : invokeSafely(
() -> IoUtils.toUtf8String(context.responseBody().get()));
// Wrap in CDATA to deal with any escaping issues
String xml = String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<Policy><![CDATA[%s]]></Policy>", policy);
return Optional.of(AbortableInputStream.create(new StringInputStream(xml)));
}
return context.responseBody();
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
return IoUtils.toUtf8String(inputStream);
} else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
代码示例来源:origin: aws/aws-sdk-java-v2
private void validateResponse(HttpExecuteResponse response, int returnCode, SdkHttpMethod method) throws IOException {
RequestMethod requestMethod = RequestMethod.fromString(method.name());
RequestPatternBuilder patternBuilder = RequestPatternBuilder.newRequestPattern(requestMethod, urlMatching("/"))
.withHeader("Host", containing("localhost"))
.withHeader("User-Agent", equalTo("hello-world!"));
if (method == SdkHttpMethod.HEAD) {
patternBuilder.withRequestBody(equalTo(""));
} else {
patternBuilder.withRequestBody(equalTo("Body"));
}
verify(1, patternBuilder);
if (method == SdkHttpMethod.HEAD) {
assertThat(response.responseBody()).isEmpty();
} else {
assertThat(IoUtils.toUtf8String(response.responseBody().orElse(null))).isEqualTo("hello");
}
assertThat(response.httpResponse().firstMatchingHeader("Some-Header")).contains("With Value");
assertThat(response.httpResponse().statusCode()).isEqualTo(returnCode);
mockServer.resetMappings();
}
代码示例来源:origin: otto-de/edison-microservice
@Test
public void getObjectShouldReturnStreamWithData() throws Exception {
// given
testee.putObject(PutObjectRequest.builder()
.bucket("someBucket")
.key("someKey")
.build(),
RequestBody.fromString("testdata"));
//when
ResponseInputStream<GetObjectResponse> inputStream = testee.getObject(GetObjectRequest.builder()
.bucket("someBucket")
.key("someKey")
.build());
//then
String data = IoUtils.toUtf8String(inputStream);
assertThat(data, is("testdata"));
}
内容来源于网络,如有侵权,请联系作者删除!