package util; import java.io.Closeable; public class Util { /** * Try to close everything passed to this method. Never throw an exception * if it fails, just silently continue. * * @param item One or more objects that are Closeable */ public static void safeClose(Closeable... item) { if (item == null) return; for (Closeable c : item) { if (c == null) continue; try { c.close(); } catch (Exception e) { } } } /** * Try to close everything passed to this method. Never throw an exception * if it fails, just silently continue. * * @param item One or more objects that are AutoCloseable */ public static void safeClose(AutoCloseable... item) { if (item == null) return; for (AutoCloseable c : item) { if (c == null) continue; try { c.close(); } catch (Exception e) { } } } }