本文整理了Java中software.amazon.awssdk.utils.IoUtils.closeQuietly()
方法的一些代码示例,展示了IoUtils.closeQuietly()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IoUtils.closeQuietly()
方法的具体详情如下:
包路径:software.amazon.awssdk.utils.IoUtils
类名称:IoUtils
方法名:closeQuietly
[英]Closes the given Closeable quietly.
[中]安静地关闭给定的可关闭对象。
代码示例来源: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/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
public static void closeQuietly(Closeable closeable) {
IoUtils.closeQuietly(closeable, null);
}
}
代码示例来源:origin: software.amazon.awssdk/codegen-lite
public static void closeQuietly(Closeable closeable) {
IoUtils.closeQuietly(closeable, null);
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
public static void closeQuietly(Closeable closeable) {
IoUtils.closeQuietly(closeable, null);
}
代码示例来源:origin: software.amazon.awssdk/codegen
public static void closeQuietly(Closeable closeable) {
IoUtils.closeQuietly(closeable, null);
}
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public void close() {
IoUtils.closeIfCloseable(parentCredentialsProvider, null);
IoUtils.closeQuietly(credentialsProvider, null);
IoUtils.closeQuietly(stsClient, null);
}
}
代码示例来源: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/sdk-core
@Override
public void release() {
// Don't call IOUtils.release(in, null) or else could lead to infinite loop
IoUtils.closeQuietly(this, null);
if (in instanceof Releasable) {
// This allows any underlying stream that has the close operation
// disabled to be truly released
Releasable r = (Releasable) in;
r.release();
}
}
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
@Override
public final void release() {
// Don't call IOUtils.release(in, null) or else could lead to infinite loop
IoUtils.closeQuietly(this, null);
if (in instanceof Releasable) {
// This allows any underlying stream that has the close operation
// disabled to be truly released
Releasable r = (Releasable) in;
r.release();
}
}
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
/**
* Close the input stream if required.
*/
private void closeInputStreamIfNeeded(SdkHttpFullResponse httpResponse,
boolean didRequestFail) {
// Always close on failed requests. Close on successful requests unless it needs connection left open
if (didRequestFail || !successResponseHandler.needsConnectionLeftOpen()) {
Optional.ofNullable(httpResponse)
.flatMap(SdkHttpFullResponse::content) // If no content, no need to close
.ifPresent(s -> IoUtils.closeQuietly(s, log));
}
}
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
private Mimetype() {
Optional.ofNullable(CLASS_LOADER).map(loader -> loader.getResourceAsStream(MIME_TYPE_PATH)).ifPresent(
stream -> {
try {
loadAndReplaceMimetypes(stream);
} catch (IOException e) {
LOG.debug("Failed to load mime types from file in the classpath: mime.types", e);
} finally {
IoUtils.closeQuietly(stream, null);
}
}
);
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Reads to the end of the inputStream returning a byte array of the contents
*
* @param inputStream
* InputStream to drain
* @return Remaining data in stream as a byte array
*/
public static byte[] drainInputStream(InputStream inputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
long bytesRead = 0;
while ((bytesRead = inputStream.read(buffer)) > -1) {
byteArrayOutputStream.write(buffer, 0, (int) bytesRead);
}
return byteArrayOutputStream.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IoUtils.closeQuietly(byteArrayOutputStream, null);
}
}
}
代码示例来源:origin: software.amazon.awssdk/test-utils
/**
* Reads to the end of the inputStream returning a byte array of the contents
*
* @param inputStream
* InputStream to drain
* @return Remaining data in stream as a byte array
*/
public static byte[] drainInputStream(InputStream inputStream) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
long bytesRead = 0;
while ((bytesRead = inputStream.read(buffer)) > -1) {
byteArrayOutputStream.write(buffer, 0, (int) bytesRead);
}
return byteArrayOutputStream.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
IoUtils.closeQuietly(byteArrayOutputStream, null);
}
}
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
/**
* Releases the given {@link Closeable} especially if it was an instance of
* {@link Releasable}.
* <p>
* For example, the creation of a <code>ResettableInputStream</code> would entail
* physically opening a file. If the opened file is meant to be closed only
* (in a finally block) by the very same code block that created it, then it
* is necessary that the release method must not be called while the
* execution is made in other stack frames.
*
* In such case, as other stack frames may inadvertently or indirectly call
* the close method of the stream, the creator of the stream would need to
* explicitly disable the accidental closing via
* <code>ResettableInputStream#disableClose()</code>, so that the release method
* becomes the only way to truly close the opened file.
*/
static void release(Closeable is, Logger log) {
closeQuietly(is, log);
if (is instanceof Releasable) {
Releasable r = (Releasable) is;
r.release();
}
}
}
代码示例来源:origin: software.amazon.awssdk/test-utils
/**
* Returns true if, and only if, the contents read from the specified input streams are exactly
* equal. Both input streams will be closed at the end of this method.
*
* @param expected
* The input stream containing the expected contents.
* @param actual
* The stream that will be read, compared to the expected file contents, and finally
* closed.
* @return True if the two input streams contain the same data.
* @throws IOException
* If any problems are encountered comparing the file and stream.
*/
public static boolean doesStreamEqualStream(InputStream expected, InputStream actual) throws IOException {
try {
byte[] expectedDigest = InputStreamUtils.calculateMD5Digest(expected);
byte[] actualDigest = InputStreamUtils.calculateMD5Digest(actual);
return Arrays.equals(expectedDigest, actualDigest);
} catch (NoSuchAlgorithmException nse) {
throw new RuntimeException(nse.getMessage(), nse);
} finally {
IoUtils.closeQuietly(expected, null);
IoUtils.closeQuietly(actual, null);
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Returns true if, and only if, the contents read from the specified input streams are exactly
* equal. Both input streams will be closed at the end of this method.
*
* @param expected
* The input stream containing the expected contents.
* @param actual
* The stream that will be read, compared to the expected file contents, and finally
* closed.
* @return True if the two input streams contain the same data.
* @throws IOException
* If any problems are encountered comparing the file and stream.
*/
public static boolean doesStreamEqualStream(InputStream expected, InputStream actual) throws IOException {
try {
byte[] expectedDigest = InputStreamUtils.calculateMD5Digest(expected);
byte[] actualDigest = InputStreamUtils.calculateMD5Digest(actual);
return Arrays.equals(expectedDigest, actualDigest);
} catch (NoSuchAlgorithmException nse) {
throw new RuntimeException(nse.getMessage(), nse);
} finally {
IoUtils.closeQuietly(expected, null);
IoUtils.closeQuietly(actual, null);
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
@Override
public ProfileFile build() {
InputStream stream = content != null ? content :
FunctionalUtils.invokeSafely(() -> Files.newInputStream(contentLocation));
Validate.paramNotNull(type, "type");
Validate.paramNotNull(stream, "content");
try {
return new ProfileFile(ProfileFileReader.parseFile(stream, type));
} finally {
IoUtils.closeQuietly(stream, null);
}
}
}
代码示例来源:origin: software.amazon.awssdk/profiles
@Override
public ProfileFile build() {
InputStream stream = content != null ? content :
FunctionalUtils.invokeSafely(() -> Files.newInputStream(contentLocation));
Validate.paramNotNull(type, "type");
Validate.paramNotNull(stream, "content");
try {
return new ProfileFile(ProfileFileReader.parseFile(stream, type));
} finally {
IoUtils.closeQuietly(stream, null);
}
}
}
代码示例来源:origin: software.amazon.awssdk/sdk-core
/**
* WARNING: Subclass that overrides this method must NOT call
* super.release() or else it would lead to infinite loop.
* <p>
* {@inheritDoc}
*/
@Override
public void release() {
// Don't call IOUtils.release(in, null) or else could lead to infinite loop
IoUtils.closeQuietly(this, null);
InputStream in = getWrappedInputStream();
if (in instanceof Releasable) {
// This allows any underlying stream that has the close operation
// disabled to be truly released
Releasable r = (Releasable) in;
r.release();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!