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.IOException;
22 import java.io.InputStream;
23 import java.io.OutputStream;
24 import java.io.Reader;
25 import java.io.Writer;
26 import java.util.jar.JarFile;
27 import java.util.zip.ZipFile;
30 * Closes various resources. The resources are checked for being
31 * <code>null</code> before being closed, and every possible execption is
32 * swallowed. That makes this class perfect for use in the finally blocks of
33 * try-catch-finally blocks.
35 * @author David ‘Roden’ <bombe@freenetproject.org>
41 * Closes the given output stream.
44 * The output stream to close
46 public static void close(OutputStream outputStream) {
47 if (outputStream != null) {
50 } catch (IOException ioe1) {
56 * Closes the given input stream.
59 * The input stream to close
61 public static void close(InputStream inputStream) {
62 if (inputStream != null) {
65 } catch (IOException ioe1) {
71 * Closes the given writer.
76 public static void close(Writer writer) {
80 } catch (IOException ioe1) {
86 * Closes the given reader.
91 public static void close(Reader reader) {
95 } catch (IOException ioe1) {
101 * Closes the given jar file.
104 * The jar file to close
106 public static void close(JarFile jarFile) {
107 if (jarFile != null) {
110 } catch (IOException e) {
116 * Closes the given zip file.
119 * The zip file to close
121 public static void close(ZipFile zipFile) {
122 if (zipFile != null) {
125 } catch (IOException e) {