本文整理了Java中software.amazon.awssdk.utils.IoUtils.toByteArray()
方法的一些代码示例,展示了IoUtils.toByteArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtils.toByteArray()
方法的具体详情如下:
包路径:software.amazon.awssdk.utils.IoUtils
类名称:IoUtils
方法名:toByteArray
[英]Reads and returns the rest of the given input stream as a byte array. Caller is responsible for closing the given input stream.
[中]以字节数组的形式读取并返回给定输入流的其余部分。调用者负责关闭给定的输入流。
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Reads and returns the rest of the given input stream as a string.
* Caller is responsible for closing the given input stream.
*/
public static String toUtf8String(InputStream is) throws IOException {
return new String(toByteArray(is), StandardCharsets.UTF_8);
}
代码示例来源:origin: software.amazon.awssdk/utils
/**
* Reads and returns the rest of the given input stream as a string.
* Caller is responsible for closing the given input stream.
*/
public static String toUtf8String(InputStream is) throws IOException {
return new String(toByteArray(is), StandardCharsets.UTF_8);
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Static factory method to create a JsonContent object from the contents of the HttpResponse
* provided
*/
public static JsonContent createJsonContent(SdkHttpFullResponse httpResponse,
JsonFactory jsonFactory) {
byte[] rawJsonContent = httpResponse.content().map(c -> {
try {
return IoUtils.toByteArray(c);
} catch (IOException e) {
LOG.debug("Unable to read HTTP response content", e);
}
return null;
}).orElse(null);
return new JsonContent(rawJsonContent, jsonFactory);
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
/**
* Create {@link SdkBytes} from an input stream. This will read all of the remaining contents of the stream, but will not
* close it.
*/
public static SdkBytes fromInputStream(InputStream inputStream) {
Validate.paramNotNull(inputStream, "inputStream");
return new SdkBytes(invokeSafely(() -> IoUtils.toByteArray(inputStream)));
}
代码示例来源:origin: software.amazon.awssdk/aws-json-protocol
/**
* Static factory method to create a JsonContent object from the contents of the HttpResponse
* provided
*/
public static JsonContent createJsonContent(SdkHttpFullResponse httpResponse,
JsonFactory jsonFactory) {
byte[] rawJsonContent = httpResponse.content().map(c -> {
try {
return IoUtils.toByteArray(c);
} catch (IOException e) {
LOG.debug("Unable to read HTTP response content", e);
}
return null;
}).orElse(null);
return new JsonContent(rawJsonContent, jsonFactory);
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
public SimpleHttpContentPublisher(SdkHttpFullRequest request) {
this.content = request.contentStreamProvider().map(p -> invokeSafely(() -> IoUtils.toByteArray(p.newStream())))
.orElseGet(() -> new byte[0]);
this.length = content.length;
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Encodes the request into a flow message and then returns bytebuffer from the message.
*
* @param request The request to encode
* @return A bytebuffer representing the given request
*/
public static ByteBuffer encodeEventStreamRequestToByteBuffer(SdkHttpFullRequest request) {
Map<String, HeaderValue> headers = request.headers()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> HeaderValue.fromString(
firstIfPresent(e.getValue()))));
byte[] payload = null;
if (request.contentStreamProvider().isPresent()) {
try {
payload = IoUtils.toByteArray(request.contentStreamProvider().get().newStream());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return new Message(headers, payload).toByteBuffer();
}
代码示例来源:origin: aws/aws-sdk-java-v2
byte[] content = nextResponse.responseBody().map(p -> invokeSafely(() -> IoUtils.toByteArray(p)))
.orElseGet(() -> new byte[0]);
代码示例来源:origin: software.amazon.awssdk/sdk-core
/**
* Creates a response transformer that loads all response content into memory, exposed as {@link ResponseBytes}. This allows
* for conversion into a {@link String}, {@link ByteBuffer}, etc.
*
* @param <ResponseT> Type of unmarshalled response POJO.
* @return The streaming response transformer that can be used on the client streaming method.
*/
static <ResponseT> ResponseTransformer<ResponseT, ResponseBytes<ResponseT>> toBytes() {
return (response, inputStream) -> {
try {
InterruptMonitor.checkInterrupted();
return ResponseBytes.fromByteArray(response, IoUtils.toByteArray(inputStream));
} catch (IOException e) {
throw RetryableException.builder().message("Failed to read response.").cause(e).build();
}
};
}
代码示例来源:origin: otto-de/edison-microservice
@Override
public PutObjectResponse putObject(final PutObjectRequest putObjectRequest,
final RequestBody requestBody) throws S3Exception {
try {
bucketsWithContents.get(putObjectRequest.bucket()).put(putObjectRequest.key(),
bucketItemBuilder()
.withName(putObjectRequest.key())
.withData(toByteArray(requestBody.contentStreamProvider().newStream()))
.withLastModifiedNow()
.build());
return PutObjectResponse.builder().build();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!