本文整理了Java中software.amazon.awssdk.utils.IoUtils
类的一些代码示例,展示了IoUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtils
类的具体详情如下:
包路径:software.amazon.awssdk.utils.IoUtils
类名称:IoUtils
[英]Utilities for IO operations.
[中]
代码示例来源:origin: software.amazon.awssdk/utils
/**
* Closes the given Closeable quietly.
* @param maybeCloseable the given closeable
* @param log logger used to log any failure should the close fail
*/
public static void closeIfCloseable(Object maybeCloseable, Logger log) {
if (maybeCloseable instanceof AutoCloseable) {
IoUtils.closeQuietly((AutoCloseable) maybeCloseable, log);
}
}
代码示例来源: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 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
@Override
public void close() {
IoUtils.closeIfCloseable(parentCredentialsProvider, null);
IoUtils.closeQuietly(credentialsProvider, null);
IoUtils.closeQuietly(stsClient, null);
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
return IoUtils.toUtf8String(inputStream);
} else if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) {
IoUtils.closeQuietly(inputStream, log);
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public void close() {
// The delegate credentials provider may be closeable (eg. if it's an STS credentials provider). In this case, we should
// clean it up when this credentials provider is closed.
IoUtils.closeIfCloseable(credentialsProvider, null);
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
/**
* Creates a response transformer that writes all response content to the given {@link OutputStream}. Note that
* the {@link OutputStream} is not closed or flushed after writing.
*
* @param outputStream Output stream to write data to.
* @param <ResponseT> Type of unmarshalled response POJO.
* @return ResponseTransformer instance.
*/
static <ResponseT> ResponseTransformer<ResponseT, ResponseT> toOutputStream(OutputStream outputStream) {
return (resp, in) -> {
InterruptMonitor.checkInterrupted();
IoUtils.copy(in, outputStream);
return resp;
};
}
代码示例来源:origin: software.amazon.awssdk/sts
@Override
public void close() {
IoUtils.closeIfCloseable(parentCredentialsProvider, null);
IoUtils.closeQuietly(credentialsProvider, null);
IoUtils.closeQuietly(stsClient, null);
}
}
代码示例来源:origin: software.amazon.awssdk/auth
@Override
public void close() {
// The delegate credentials provider may be closeable (eg. if it's an STS credentials provider). In this case, we should
// clean it up when this credentials provider is closed.
IoUtils.closeIfCloseable(credentialsProvider, null);
}
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public Optional<RequestBody> modifyHttpContent(Context.ModifyHttpRequest context,
ExecutionAttributes executionAttributes) {
if (!BLACKLIST_METHODS.contains(context.request().getClass()) && context.requestBody().isPresent()
&& !context.httpRequest().firstMatchingHeader(CONTENT_MD5).isPresent()) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IoUtils.copy(context.requestBody().get().contentStreamProvider().newStream(), baos);
executionAttributes.putAttribute(CONTENT_MD5_ATTRIBUTE, Md5Utils.md5AsBase64(baos.toByteArray()));
return context.requestBody();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return context.requestBody();
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Closes the given Closeable quietly.
* @param maybeCloseable the given closeable
* @param log logger used to log any failure should the close fail
*/
public static void closeIfCloseable(Object maybeCloseable, Logger log) {
if (maybeCloseable instanceof AutoCloseable) {
IoUtils.closeQuietly((AutoCloseable) maybeCloseable, log);
}
}
代码示例来源: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: 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
@Override
public void close() {
credentialsProviders.forEach(c -> IoUtils.closeIfCloseable(c, null));
}
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public HttpExecuteResponse call() throws IOException {
connection.connect();
request.contentStreamProvider().ifPresent(provider ->
invokeSafely(() -> IoUtils.copy(provider.newStream(), connection.getOutputStream())));
int responseCode = connection.getResponseCode();
boolean isErrorResponse = HttpStatusFamily.of(responseCode).isOneOf(CLIENT_ERROR, SERVER_ERROR);
InputStream content = !isErrorResponse ? connection.getInputStream() : connection.getErrorStream();
AbortableInputStream responseBody = content != null ?
AbortableInputStream.create(content) : null;
return HttpExecuteResponse.builder()
.response(SdkHttpResponse.builder()
.statusCode(responseCode)
.statusText(connection.getResponseMessage())
// TODO: Don't ignore abort?
.headers(extractHeaders(connection))
.build())
.responseBody(responseBody)
.build();
}
代码示例来源:origin: aws/aws-sdk-java-v2
public static void closeQuietly(Closeable closeable) {
IoUtils.closeQuietly(closeable, 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/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/auth
@Override
public void close() {
credentialsProviders.forEach(c -> IoUtils.closeIfCloseable(c, null));
}
代码示例来源:origin: software.amazon.awssdk/codegen-lite
public static void closeQuietly(Closeable closeable) {
IoUtils.closeQuietly(closeable, null);
}
}
内容来源于网络,如有侵权,请联系作者删除!