Clean up netconf-parent root pom
[netconf.git] / netconf / netconf-util / src / main / java / org / opendaylight / netconf / util / CloseableUtil.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netconf.util;
10
11 public class CloseableUtil {
12
13     @SuppressWarnings("checkstyle:IllegalCatch")
14     public static void closeAll(Iterable<? extends AutoCloseable> autoCloseables) throws Exception {
15         Exception lastException = null;
16         for (AutoCloseable autoCloseable : autoCloseables) {
17             try {
18                 autoCloseable.close();
19             } catch (Exception e) {
20                 if (lastException == null) {
21                     lastException = e;
22                 } else {
23                     lastException.addSuppressed(e);
24                 }
25             }
26         }
27         if (lastException != null) {
28             throw lastException;
29         }
30
31     }
32 }