2 * todesbaum-lib - Copyright (C) 2006 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 de.todesbaum.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.net.ServerSocket;
27 import java.net.Socket;
28 import java.sql.Connection;
29 import java.sql.ResultSet;
30 import java.sql.SQLException;
31 import java.sql.Statement;
34 * Helper class that can close all kinds of resources without throwing exception
35 * so that clean-up code can be written with less code. All methods check that
36 * the given resource is not <code>null</code> before invoking the close()
37 * method of the respective type.
39 * @author <a href="mailto:bombe@freenetproject.org">David ‘Bombe&squo;
46 * Closes the given result set.
49 * The result set to close
50 * @see ResultSet#close()
52 public static void close(ResultSet resultSet) {
53 if (resultSet != null) {
56 } catch (SQLException ioe1) {
62 * Closes the given statement.
65 * The statement to close
66 * @see Statement#close()
68 public static void close(Statement statement) {
69 if (statement != null) {
72 } catch (SQLException ioe1) {
78 * Closes the given connection.
81 * The connection to close
82 * @see Connection#close()
84 public static void close(Connection connection) {
85 if (connection != null) {
88 } catch (SQLException ioe1) {
94 * Closes the given server socket.
97 * The server socket to close
98 * @see ServerSocket#close()
100 public static void close(ServerSocket serverSocket) {
101 if (serverSocket != null) {
103 serverSocket.close();
104 } catch (IOException ioe1) {
110 * Closes the given socket.
113 * The socket to close
114 * @see Socket#close()
116 public static void close(Socket socket) {
117 if (socket != null) {
120 } catch (IOException ioe1) {
126 * Closes the given input stream.
129 * The input stream to close
130 * @see InputStream#close()
132 public static void close(InputStream inputStream) {
133 if (inputStream != null) {
136 } catch (IOException ioe1) {
142 * Closes the given output stream.
144 * @param outputStream
145 * The output stream to close
146 * @see OutputStream#close()
148 public static void close(OutputStream outputStream) {
149 if (outputStream != null) {
151 outputStream.close();
152 } catch (IOException ioe1) {
158 * Closes the given reader.
161 * The reader to close
162 * @see Reader#close()
164 public static void close(Reader reader) {
165 if (reader != null) {
168 } catch (IOException ioe1) {
174 * Closes the given writer.
178 * @see Writer#close()
180 public static void close(Writer writer) {
181 if (writer != null) {
184 } catch (IOException ioe1) {