1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-25 21:42:07 +01:00

Add CloseableUtil.maybeClose(Closeable)

This commit is contained in:
Florian Schmaus 2019-05-18 13:25:31 +02:00
parent 02e2eba556
commit 04238bd36a

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2018 Florian Schmaus
* Copyright 2018-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -23,6 +23,10 @@ import java.util.logging.Logger;
public class CloseableUtil {
public static void maybeClose(Closeable closable) {
maybeClose(closable, null);
}
public static void maybeClose(Closeable closable, Logger logger) {
if (closable == null) {
return;
@ -31,7 +35,9 @@ public class CloseableUtil {
try {
closable.close();
} catch (IOException e) {
logger.log(Level.WARNING, "Could not close " + closable, e);
if (logger != null) {
logger.log(Level.WARNING, "Could not close " + closable, e);
}
}
}
}