2 * freenet - Closer.java Copyright © 2007 David Roden
4 * This program is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License as published by the Free Software
6 * Foundation; either version 2 of the License, or (at your option) any later
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16 * Place - Suite 330, Boston, MA 02111-1307, USA.
19 package net.pterodactylus.util.io;
21 import java.io.Closeable;
22 import java.io.IOException;
23 import java.net.Socket;
24 import java.util.jar.JarFile;
25 import java.util.zip.ZipFile;
28 * Closes various resources. The resources are checked for being
29 * <code>null</code> before being closed, and every possible execption is
30 * swallowed. That makes this class perfect for use in the finally blocks of
31 * try-catch-finally blocks.
33 * @author David ‘Roden’ <bombe@freenetproject.org>
38 * Closes the given closeable.
41 * The closeable to close
43 public static void close(Closeable closeable) {
44 if (closeable != null) {
47 } catch (IOException ioe1) {
54 * Closes the given socket.
59 public static void close(Socket socket) {
63 } catch (IOException ioe1) {
70 * Closes the given jar file.
73 * The jar file to close
75 public static void close(JarFile jarFile) {
76 if (jarFile != null) {
79 } catch (IOException e) {
86 * Closes the given zip file.
89 * The zip file to close
91 public static void close(ZipFile zipFile) {
92 if (zipFile != null) {
95 } catch (IOException e) {