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>
39 * Closes the given closeable.
42 * The closeable to close
44 public static void close(Closeable closeable) {
45 if (closeable != null) {
48 } catch (IOException ioe1) {
55 * Closes the given socket.
60 public static void close(Socket socket) {
64 } catch (IOException ioe1) {
71 * Closes the given jar file.
74 * The jar file to close
76 public static void close(JarFile jarFile) {
77 if (jarFile != null) {
80 } catch (IOException e) {
87 * Closes the given zip file.
90 * The zip file to close
92 public static void close(ZipFile zipFile) {
93 if (zipFile != null) {
96 } catch (IOException e) {