summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/util/Util.java
blob: 28f522b88f9d3c2f2a6bce4ce7beb7d91532afa3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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) {
			}
		}
	}

}