mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-29 15:32:06 +01:00
Add CloseableUtil.maybeClose(Closeable)
This commit is contained in:
parent
02e2eba556
commit
04238bd36a
1 changed files with 8 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright 2018 Florian Schmaus
|
* Copyright 2018-2019 Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 class CloseableUtil {
|
||||||
|
|
||||||
|
public static void maybeClose(Closeable closable) {
|
||||||
|
maybeClose(closable, null);
|
||||||
|
}
|
||||||
|
|
||||||
public static void maybeClose(Closeable closable, Logger logger) {
|
public static void maybeClose(Closeable closable, Logger logger) {
|
||||||
if (closable == null) {
|
if (closable == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -31,7 +35,9 @@ public class CloseableUtil {
|
||||||
try {
|
try {
|
||||||
closable.close();
|
closable.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
if (logger != null) {
|
||||||
logger.log(Level.WARNING, "Could not close " + closable, e);
|
logger.log(Level.WARNING, "Could not close " + closable, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue