1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-25 15:52:06 +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"); * 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) {
logger.log(Level.WARNING, "Could not close " + closable, e); if (logger != null) {
logger.log(Level.WARNING, "Could not close " + closable, e);
}
} }
} }
} }